Closemovie error

Hi, all. I am trying to make movie files from graphs (500-2000 frames), using "Newmovie", "Addmovieframe", "Closemovie".
Sometimes my code works, but sometimes the error appears like "CloseMovie error: “the file is already in use.", "While executing CloseMovie, the following error occurred: the file is already in use.".When I found this error, the file named "tempMoviePreFlat", in addition to the file I write the name in the code, is always created in the same directory. The error message is too little for me to fix the wrong point in my code. Also, what I can not really understand is that there does not seem to be the reproducibility; the code works well sometimes, but does not work the other time.
I attach one of my codes. I would really appreciate your help.
Hi,

you don't seem to have added your code.
Please add it inline a la <igor>igor code</igor>.