MEX file access violation

Any help would be very gratefully received!

I am running a script using PTB (on Windows) which loops through and displays sequences of videos, but every so often Matlab will encounter an internal error and need to close. There is no particular point at which this occurs, it seems random. I can restart my computer, run the script 10 times and it'll crash on the 11th time. Or it'll crash first time. It also doesn't crash at the same point during my script - I loop through 12 blocks and it can crash at any time.

When running in no java mode using the Windows command prompt (-nojvm) this crashing does not seem to occur, but it rotates my vidoes 90 degrees and I can't work out how to fix this. Also I can't run one script I need as the no java mode doesn't support the GetKey.m function, which I need.


When crashing, it gives me this message:

 ---------------------------------------------------------------------------------------------------------------------------

Abnormal termination:

Access violation

 

Register State (from fault):

  EAX = 00000002  EBX = 32767579

  ECX = 23a27630  EDX = 32767579

  ESP = 00c262c0  EBP = 00000000

  ESI = 00c26344  EDI = 00c262f4

 

  EIP = 332c9e4c  EFL = 00010287

 

   CS = 00000023   DS = 0000002b   SS = 0000002b

   ES = 0000002b   FS = 00000053   GS = 0000002b

 

Stack Trace (from fault):

 

 

This error was detected while a MEX-file was running. If the MEX-file

is not an official MathWorks function, please examine its source code

for errors. Please consult the External Interfaces Guide for information

on debugging MEX-files.

---------------------------------------------------------------------------------------------------------------------------
The only MEX files I am using are Screen and WaitSecs.mexw32, and the MatLab file reqmgt.mexw32. I have disabled WaitSecs, and still get the crashing, so I am assuming the problem is Screen.

I am having to use 32bit Matlab, with Psychtoolbox-3.0.11, as that's all I can get to work with gstreamer-1.4.

Any ideas?