I had the same issue and I prefer MasterQ32's solution:

while(total_frames < 1) wait(1);