Exception in opengl32.dll when moving from VS2005 to VS2010. RRS feed

  • Question

  • I've recently been tasked with taking a tools application which uses OpenGL via C# from Visual Studio 2005 to VS2010. In the process I've retargetted the application from .Net 2.0 to .Net 4.0. For the most part, everything has gone relatively smoothly, however a couple pieces of the code are now malfunctioning.

    One piece is using glGetString calls to retrieve the renderer, version, and vendor information from the current context. Executing this code now results in an exception thrown from within the OpenGL call itself. Despite this, most of the OpenGL functionality works correctly if you ignore the exception.

    The code relating to OpenGL has not changed during this migration, and the application compiled in VS2005 does not show this behavior. I can't help but think if I can figure out what has changed (the code has not) between VS2005 and VS2010 (or between .Net 2.0 and .Net 4.0) then I will be able to track down the other issues as well.

    So... Any ideas as to how I might track down the problem that has occurred?
    • Moved by Leo Liu - MSFT Wednesday, May 25, 2011 9:18 AM Moved for better support. (From:Visual C# General)
    Tuesday, May 24, 2011 1:16 AM

All replies

  • I am moving your thread into the Common Language Runtime Forum for specialized support. Thanks.
    Leo Liu [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, May 25, 2011 9:17 AM



    Based on your description, the problem causes by differences between .NET Framework 2.0 and .NET Framework 4.0. I am not familiar with class library about OpenGL, but I believe that there is some changes in the class library so that the issue happens. You'd better find the differences and change the method to follow .NET Framework 4.0 class library.

    What's New in the .NET Framework 4


    I hope this can help you.


    Paul Zhou [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, May 26, 2011 9:32 AM
  • ToolsGuy,


    Based on your infromation, you use PInvoke to call OpenGL functions. Please post the detailed infromation about the thrown exception, so that we can know the more information about this issue. The detailed information includes: exception message, stacktrace, inner exception(if it isn't null).

    It is best that you can post one small and whole code example, so that we can reproduce your scenario. If we can reproduce it, we can give better discussion with you. If you can, please specify how to get the OpenGL(you download and install it in your PC or it is built-in DLL in windows). Thanks!

    Best regards,

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Friday, May 27, 2011 1:35 AM
  • What the application does is create static delegates and assign them marshalled values.

    The first call that is giving us trouble is declared and assigned like this (this is not the actual code, just an example of the process):


    public static class Kernel
    public extern static IntPtr GetProcAddress(IntPtr hModule, string lpProcName);
    extern static IntPtr LoadLibrary(string fileName);

    delegate string glGetStringDelegate(int name); glGetStringDelegate glGetString; bool BindGLString() { IntPtr dll = Kernel.LoadLibrary("c:\\Windows\\System32\\opengl32.dll");
    IntPtr fn = IntPtr.Zero; Kernel.GetProcAddress(dll, "glGetString"); if ( fn == IntPtr.Zero ) return false; Type t = typeof(glGetStringDelegate); glGetString = Marshal.GetDelegateForFunctionPointer(fn, t) as glGetStringDelegate; return true; }


    All the gl calls are acquired through this method or through wglGetProcAddress (for extensions, presumably - I am not terribly familiar with OpenGL). After creating and setting the context, the glGetString delegate is called with the value GL_RENDERER (although GL_VENDOR and GL_VERSION also throw exceptions).

    I was not the one who set up the machine, however I don't believe we download and install OpenGL on our PCs so I assume it is the built-in DLL.

    When the exception is thrown, the following is written to the output window:

    "Critical error detected c0000374
    Windows has triggered a breakpoint in ******.exe.

    This may be due to a corruption of the heap, which indicates a bug in ******.exe or any of the DLLs it has loaded.

    This may also be due to the user pressing F12 while ******.exe has focus.

    The output window may have more diagnostic information."

    The call stack looks like this:

    "     ntdll.dll!775be625()    
         [Frames below may be incorrect and/or missing, no symbols loaded for ntdll.dll]   
         [External Code]   
    >    *********.dll!Shared.Interop.GlBind.TryDLL(string filename = "C:\\Windows\\system32\\OpenGL32.dll") Line 285 + 0x22 bytes    C#"

    I can verify that the call is at least entering opengl32.dll as when I step into the glGetString function, the stack location reads "opengl32.dll!69e93ced()".

    I will attempt to put together a working example application if needed, though it may take a little while as I have never created an OpenGL application from scratch, much less through C#...


    Friday, May 27, 2011 5:22 PM
  • I can't say for sure what the problem is, but the first thing that jumps out at me is the enum. GLenum is (I believe) a uint, not just an int. In your delegate definition, I believe name should be a uint

    Friday, May 27, 2011 8:09 PM
  • Alas, switching the enum and the delegate definition to use uint does not appear to have an effect...
    Friday, May 27, 2011 10:11 PM