Trillian's picture

Occasional AccessViolationExceptions when creating the GraphicsContext

Project:The Open Toolkit library
Version:1.1-2014-01-02
Component:Code
Category:bug report
Priority:critical
Assigned:Unassigned
Status:closed
Description

I have a game using a GLControl. Once in a while, but quite infrequently (maybe one run on 50) I get an AccessViolationException as the GLControl attempts to initialize its context.

I have captured the stack trace of the exception on two occasions and they had the following top methods in common. As the topmost method involves pointers, might I suggest to double-check that any pointer arithmetic is correct?

Thanks.

   at OpenTK.Platform.Windows.Wgl.Delegates.CreateContextAttribsARB.Invoke(IntPtr hDC, IntPtr hShareContext, Int32* attribList)
   at OpenTK.Platform.Windows.Wgl.Arb.CreateContextAttribs(IntPtr hDC, IntPtr hShareContext, Int32[] attribList) in C:\Users\Stefanos\Desktop\opentk-all\opentk-0.9.8-3\Source\OpenTK\Platform\Windows\Bindings\Wgl.cs:line 551
   at OpenTK.Platform.Windows.WinGLContext..ctor(GraphicsMode format, IWindowInfo window, IGraphicsContext sharedContext, Int32 major, Int32 minor, GraphicsContextFlags flags) in C:\Users\Stefanos\Desktop\opentk-all\opentk-0.9.8-3\Source\OpenTK\Platform\Windows\WinGLContext.cs:line 104
   at OpenTK.Platform.Windows.WinFactory.CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, Boolean directRendering, Int32 major, Int32 minor, GraphicsContextFlags flags) in C:\Users\Stefanos\Desktop\opentk-all\opentk-0.9.8-3\Source\OpenTK\Platform\Windows\WinFactory.cs:line 31
   at OpenTK.Platform.Factory.CreateGLContext(GraphicsMode mode, IWindowInfo window, IGraphicsContext shareContext, Boolean directRendering, Int32 major, Int32 minor, GraphicsContextFlags flags) in C:\Users\Stefanos\Desktop\opentk-all\opentk-0.9.8-3\Source\OpenTK\Platform\Factory.cs:line 38
   at OpenTK.Graphics.GraphicsContext..ctor(GraphicsMode mode, IWindowInfo window, Int32 major, Int32 minor, GraphicsContextFlags flags) in C:\Users\Stefanos\Desktop\opentk-all\opentk-0.9.8-3\Source\OpenTK\Graphics\GraphicsContext.cs:line 119
   at OpenTK.Platform.Windows.WinGLControl.CreateContext(Int32 major, Int32 minor, GraphicsContextFlags flags) in C:\Users\Stefanos\Desktop\opentk-all\opentk-0.9.8-3\Source\OpenTK\Platform\Windows\WinGLControl.cs:line 53
   at OpenTK.GLControl.OnHandleCreated(EventArgs e) in C:\Users\Stefanos\Desktop\opentk-all\opentk-0.9.8-3\Source\OpenTK\GLControl.cs:line 110
   at System.Windows.Forms.Control.WmCreate(Message& m)
   at System.Windows.Forms.Control.WndProc(Message& m)
   at System.Windows.Forms.ScrollableControl.WndProc(Message& m)
   at System.Windows.Forms.ContainerControl.WndProc(Message& m)
   at System.Windows.Forms.UserControl.WndProc(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.OnMessage(Message& m)
   at System.Windows.Forms.Control.ControlNativeWindow.WndProc(Message& m)

Comments

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
the Fiddler's picture

#11

Ok, that helps quite a bit.

Two questions to help me reproduce the issue:

  • Are you using Tao.SimpleOpenGlControl?
  • Is the issue still present if you compile for x86 instead of AnyCPU?

The issue sounds suspiciously like stack corruption (some function may be using int parameters instead of IntPtr) but it remains to be seen whether this is caused by Tao or OpenTK.

Finally, have you tried to use OpenTK.Compatibility.dll instead of Tao.OpenGl.dll? The former contains a cross-platform re-implementation of Tao.Platform.Windows.SimpleOpenGlControl (built atop of OpenTK.GLControl), plus the whole Tao.OpenGl namespace. It would be useful to see if the issue is still present with OpenTK.Compatibility (if it is, it's likely that the bug is in OpenTK; otherwise it probably lies in Tao).

cjanssen's picture

#12

I'm actually using my own custom GL control but modeled it after the SimpleOpenGLControl. Also, I was actually already compiling it explicitly for x86 (though I tried AnyCPU just in case), still no luck.

Unfortunately, the hefty portion of my conversion from Tao to OpenTK has already taken place so I can't really test the OpenTK.Compatibility version of Tao in a truly scientific sense (to many changes elsewhere to make a reliable conclusion). If I have time I'll try and go back to a revision before I started the conversion and see if replacing the Tao dependencies with OpenTK.Compatibility version of Tao makes a difference.

the Fiddler's picture

#13

Status:in progress (review)» closed

I cannot reproduce this issue anymore, please reopen if you are still affected.

Duckers's picture

#14

Priority:normal» critical
Status:closed» open

I am still getting this error consistently with the latest version in certain contexts.

Note that we are combining OpenTK with WPF and using WindowsFormsHost for interop.

If anyone is debuggin this, feel free to contact me on Skype (duckers85) for a remote debugging session.

Only happens on ATI drivers, and it totally crashes the GPU driver. When the driver recovers, visual studio reports access violation in

> OpenTK.dll!OpenTK.Platform.Windows.Wgl.Arb.CreateContextAttribs(System.IntPtr hDC, System.IntPtr hShareContext, int[] attribList) Line 551 + 0x1e bytes C#
OpenTK.dll!OpenTK.Platform.Windows.WinGLContext.WinGLContext(OpenTK.Graphics.GraphicsMode format, OpenTK.Platform.Windows.WinWindowInfo window, OpenTK.Graphics.IGraphicsContext sharedContext, int major, int minor, OpenTK.Graphics.GraphicsContextFlags flags) Line 104 + 0xca bytes C#
OpenTK.dll!OpenTK.Platform.Windows.WinFactory.CreateGLContext(OpenTK.Graphics.GraphicsMode mode, OpenTK.Platform.IWindowInfo window, OpenTK.Graphics.IGraphicsContext shareContext, bool directRendering, int major, int minor, OpenTK.Graphics.GraphicsContextFlags flags) Line 56 + 0x4d bytes C#
OpenTK.dll!OpenTK.Graphics.GraphicsContext.GraphicsContext(OpenTK.Graphics.GraphicsMode mode, OpenTK.Platform.IWindowInfo window, int major, int minor, OpenTK.Graphics.GraphicsContextFlags flags) Line 134 + 0x2c bytes C#
OpenTK.dll!OpenTK.Platform.Windows.WinGraphicsMode.GetModesARB(OpenTK.INativeWindow native) Line 181 + 0x10a bytes C#
[External Code]
OpenTK.dll!OpenTK.Platform.Windows.WinGraphicsMode.WinGraphicsMode() Line 55 + 0x24 bytes C#
OpenTK.dll!OpenTK.Platform.Windows.WinFactory.CreateGraphicsMode() Line 74 + 0x15 bytes C#
OpenTK.dll!OpenTK.Graphics.GraphicsMode.GraphicsMode() Line 36 + 0x11 bytes C#
[External Code]
OpenTK.GLControl.dll!OpenTK.GLControl.GLControl() Line 72 + 0xb bytes C#

the Fiddler's picture

#15

Version:0.9.8-3» 1.1-2014-01-02
Status:open» closed

This issue should be fixed in OpenTK 1.1 beta4

Please file a bug report at https://github.com/opentk/opentk/issues if you can still reproduce this.