Shaders & OpenGL random crashes

I have an application with my .Net OpenGL component that basically Shows a form with my openGL control, then creates, shows and closes at intervals of 1 second another form with my opengl control.

I have these problems on a pc with ATI Radeon HD 5450, Catalyst 12.4:

  1. If I run my application from outside Visual Studio, sooner or later (but not after a fixed number of opened forms) I will get an “Attempted to read or write protected memory” exception in various part of my code where I do various things (for example a glCallList(), or glDeleteTexture()…).

  2. If I run it from Visual Studio, when the second form is closed and the third one is created and shown (the first one remains always visible) the code hangs in the initialization of my OpenGL control where I compile a shader and in particular at the call where I get its GL_COMPILE_STATUS value:

glGetShaderiv(shaderObj, GL_COMPILE_STATUS, ref shaderStatus);

Note that the shader compilation was fine for the first 2 forms…

If I remove the creation and compilation of the shaders the crashes and the hang disappear.

Also, If I don’t keep the first Form visible, but just open and close a Form, the crashes disappear too.

To make things worse, these problems don’t happen on another machine with another ATI card (FirePro V3750) and an older Catalyst version.

Do you have any idea of what I could be doing wrong or how could I debug this problem?

I tried using gDebugger but had not success with it (it doesn’t seem to intercept my OpenGL calls…).

Any idea is welcome…

Have you run it under a normal (i.e. not an OpenGL) debugger? Some have the capability to stop program flow at the point where exceptions are thrown, so you could stop execution when the first problem occurs.
As a random guess, are forms perhaps each using their own thread? Are you making sure to make the OpenGL context active in at most one thread at a time?


how can I make sure that the OpenGL context is active in at most one thread at a time?
Each form has its own thread and its own graphics context.
Maybe I’m not properly calling the wglMakeCurrent?