Anthony Pecorella

In a testing program that I'm writing I have to be able to play QuickTime movies. I'm writing the program in VSEE, C#. I have written a small test program to make sure QuickTime would behave okay, and while for the most part it works, I am fairly regularly getting an error when I'm switching movies: "Attempted to read or write protected memory. This is often an indication that other memory is corrupt."

In case it matters, the movie files are relatively small (3 - 5 MB). I'm really not sure what's happening, and I haven't even found a reliable way to replicate the issue (happens on various movies in the series - sometimes immediately, sometimes delayed...). It's a very simply program so I included pretty much all of the code below. I provided the exception details, but generally I find those to be fairly dense and unhelpful (or perhaps I'm just not good at interpreting them). Please let me know if anyone has any suggestions. Thanks!

The form simply has a movie object on it and a single button. Pressing the button switches to the next movie in the list. Upon some of these switches I get the error.

Main program file:

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Windows.Forms;
 4 
 5 namespace TestQuicktime
 6 {
 7   static class Program
 8   {
 9     [STAThread]
 10     static void Main()
 11     {
 12       Application.EnableVisualStyles();
 13       Application.SetCompatibleTextRenderingDefault(false);
 14       Application.Run(new Form1());
 15     }
 16   }
 17 }
Form:
 1 using System;
 2 using System.Collections.Generic;
 3 using System.ComponentModel;
 4 using System.Data;
 5 using System.Drawing;
 6 using System.Text;
 7 using System.Windows.Forms;
 8 
 9 namespace TestQuicktime
 10 {
 11   public partial class Form1 : Form
 12   {
 13     private List<string> movies = new List<string>();
 14     private int currMov = 0;
 15     
 16     public Form1()
 17     {
 18       InitializeComponent();
 19     }
 20 
 21     private void Form1_Load(object sender, EventArgs e)
 22     {
 23       movies.Add("c:\movie1.mov");
 24       movies.Add("c:\movie2.mov");
 25       movies.Add("c:\movie3.mov");
 26       QTMovie.FileName = "c:\movie3.mov";
 27       QTMovie.AutoPlay = "true";
 28     }
 29 
 30     private void NextMovie_Click(object sender, EventArgs e)
 31     {
 32       QTMovie.FileName = movies[currMov];  
 33       QTMovie.Movie.Play(1);
 34       currMov = (currMov + 1) % 3; 
 35     }
 36   }
 37 }
Exception Details:
System.AccessViolationException was unhandled
Message="Attempted to read or write protected memory. This is often an indication that other memory is corrupt."
Source="System.Windows.Forms"
StackTrace:
at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam)
at System.Windows.Forms.NativeWindow.DefWndProc(Message& m)
at System.Windows.Forms.Control.DefWndProc(Message& m)
at System.Windows.Forms.Control.WndProc(Message& m)
at System.Windows.Forms.AxHost.WndProc(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)
at System.Windows.Forms.NativeWindow.DebuggableCallback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)
at System.Windows.Forms.UnsafeNativeMethods.DispatchMessageA(MSG& msg)
at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(Int32 dwComponentID, Int32 reason, Int32 pvLoopData)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
at System.Windows.Forms.Application.Run(Form mainForm)
at TestQuicktime.Program.Main() in C:\Documents and Settings\Pecorella\My Documents\Visual Studio 2005\Projects\TestQuicktime\TestQuicktime\Program.cs:line 17
at System.AppDomain.nExecuteAssembly(Assembly assembly, String[] args)
at System.AppDomain.ExecuteAssembly(String assemblyFile, Evidence assemblySecurity, String[] args)
at Microsoft.VisualStudio.HostingProcess.HostProc.RunUsersAssembly()
at System.Threading.ThreadHelper.ThreadStart_Context(Object state)
at System.Threading.ExecutionContext.Run(ExecutionContext executionContext, ContextCallback callback, Object state)
at System.Threading.ThreadHelper.ThreadStart()


Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

Anthony Pecorella

Ok, so apparently no ideas... Does anyone know of another forum I could try to post this on I've been scouring around for Quicktime developer or Quicktime .NET forums and have found very little of help. Thanks for the suggestions!



Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

Anthony Pecorella

Really, no one knows any forums with Quicktime developers This is insane...I'd think Apple would have better support than this. I've gotten to a point where the control will sometimes flat out ignore my commands. For example:

Before this line, Movie.URL is "movie1.mov" and NewMovie is "movie2.mov".

Movie.URL = NewMovie;

Now, after running (and using watches to verify), the URL remains unchanged, sometimes! No error or anything, just ignores the line. I'm about to tear my hair out... Alternatively, does anyone have any recommendations for other ways to play movies with C# (preferably QuickTime but I'll convert if necessary) Thanks!




Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

Anthony Pecorella

Ok, I think Visual Studio just got on my crap list. I finally got tired of it and on a whim decided to go ahead and publish it, just to see what would happen. Low and behold, it works!! So, now it appears I've spent days working on removing a bug that the debugger introduced. To quote of my friend's reaction when I told him this, "Debuggers should never introduce bugs. That kinda defeats the purpose." I couldn't say it better...has anyone else had these issues Is this a memory management problem Why did I just lose a week of development to a debugger




Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

Keith

Anthony,

I am working in a different language (VB6 and VB 2005), but I get the same exact error message that you get. I have found it to be very random when the issue happens. Have you run in to it again





Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

j3rky

Anthony, have you tried stopping the current movie before loading a new one

Download a simple code example here: http://blog.gerke-preussner.de/index.php /archives/2-Embedding-QuickTime-Media-into-.NET-Applications-using-Visual-C.html





Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

jgraham

I have been experiencing the same problem. I would have *never* thought to try this outside of Visual Studio. Thanks for that tip. It does appear to work better outside the debugger however, I did manage to get the same error but it took much longer:

************** Exception Text **************
System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt. at System.Windows.Forms.UnsafeNativeMethods.CallWindowProc(IntPtr wndProc, IntPtr hWnd, Int32 msg, IntPtr wParam, IntPtr lParam) at System.Windows.Forms.NativeWindow.DefWndProc(Message& m) at System.Windows.Forms.Control.DefWndProc(Message& m) at System.Windows.Forms.Control.WndProc(Message& m) at System.Windows.Forms.AxHost.WndProc(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m) at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m) at System.Windows.Forms.NativeWindow.Callback(IntPtr hWnd, Int32 msg, IntPtr wparam, IntPtr lparam)

The way I get the error is by loading several movies. I load, play then seek to a new location and close the movie. Then I load another movie. In the debugger, I get the AccessViolation after loading between 3-5 movies. Outside the debugger it was more like 15-20 movies. I would suggest that we all try this experiment to make sure the you're not seeing the error simply because you have not tried loading and unloading enough movies.I'd like to keep this discussion alive since it appears to be the only place I've found that's talking about this particular QuickTime problem.






Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

Anthony Pecorella

That's interesting (though I suppose expected) that the same error was given in VB. I have tried running it multiple times and will almost always get the error, though not always in the same spot (and yes jgraham, I think that's the exact same error I eventually got in the published version of the software).

The thing that really got me (and that somewhat answers j3rky's suggestion) is that I actually downloaded the movie player sample directly from Apple's dev site and tried to run that. Sure enough (with a little effort) after opening and playing 10 - 15 movies I get the same "protected memory" error.

This happens both in debug and in full publication attempts at running the software (though yes, it may have taken longer in published mode - the fix for me was actually of the other bug where it wasn't switching movies properly for me...but still very strange). At this point it seems that something is fundamentally wrong with the software, which is rather surprising to me since Quicktime is one of Apple's premier products - I'd think they'd have it well supported and debugged. Any ideas

Edit: I did try the link above, and it worked fine, but it only loads one movie - there is no switching between movies.

As for stopping the movie, I think I can say that no, I didn't. I followed the exact same procedure used in the sample code from Apple, which just switches the filename/url of the movie. When I tried running QTControl.Movie.Stop() I think I got a null error at some point - I don't recall exactly.




Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

jgraham

i don't think my previous post made in to this thread but i, too, was experiencing a similar problem. it even happens using the sample code from apple (C# Quicktime player). i got the access violation error after loading and unloading several quicktime movies. running it outside the debugger improved the number of times i could run this test but it eventually happened anyway (after about 15-20 movie switches).

however, i ran the above code an could not reproduce the problem. so i created a thread where it continually loads a movie from a given directory where i keep about 10 movies. i let this run "forever" and after loading about 120 videos, i finally stopped the thread because no error occurred. so something about the code in the above posting works whereas the code from Apple, e.g.

http://developer.apple.com/samplecode/QuickTime/idxQuickTimeforWindows-date.html
see " MoviePlayer - C# (HTML) (DMG) (ZIP)"

eventually fails.






Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

jgraham

i don't think my previous post made in to this thread but i, too, was experiencing a similar problem. it even happens using the sample code from apple (C# Quicktime player). i got the access violation error after loading and unloading several quicktime movies. running it outside the debugger improved the number of times i could run this test but it eventually happened anyway (after about 15-20 movie switches).

however, i ran the above code an could not reproduce the problem. so i created a thread where it continually loads a movie from a given directory where i keep about 10 movies. i let this run "forever" and after loading about 120 videos, i finally stopped the thread because no error occurred. so something about the code in the above posting works whereas the code from Apple, e.g.

http://developer.apple.com/samplecode/QuickTime/idxQuickTimeforWindows-date.html
see " MoviePlayer - C# (HTML) (DMG) (ZIP)"

eventually fails.




Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

Anthony Pecorella

jgraham: I'm not sure what happened with your post - I think one of mine kinda disappeared too...this forum is doing some weird stuff (it's like the one that's searchable is slightly out of date or something). Anyway, that's intriguing that the example above didn't have problems when you ran that loop. I'll have to look at it in more detail. Thanks.




Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

jgraham

anthony,

i'd be happy to send you a zip of the project so you can run it on your system. i simply took the above mentioned code, added a thread and a couple of methods, a couple of buttons and that's it.






Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

Anthony Pecorella

I'd appreciate seeing your version - and man, this thread is having some serious problems. It's getting all out of order and is doing some really weird stuff...

Can you post the modifications here It should be mostly the same, right I'd prefer to keep spam crawlers from getting ahold of my email address on these forums.

I'm trying to figure out what exactly the difference is between this code sample and Apple's. I tried adding the "movie.stop()" function and that didn't seem to help...




Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

JRQ

If you are using the Listeners, remove it fisrt before assigning the new movie then re-add it.



Re: Windows Forms General Quicktime COM control giving "AccessViolationException"

Anthony Pecorella

Actually, don't worry about posting the code example - I ran my own (based on the code I posted in the first post, only imported into the downloaded sample) and it did indeed work just fine. Now I just gotta figure out why...

As for listeners...there weren't any in the program in the first post in the thread (right ), and that one had problems, so I'm don't think that that's the issue.