
Access violation creating GameWindow
Posted Tuesday, 6 April, 2010 - 02:54 by blodbath inSo I got a nice OpenTK project going, terrain with shadowing and reflections and soforth and it worked great. However I upgraded my graphics card drivers and now it appears that it doesn't work any more. Here's my relevant code (note that I don't even get past calling the base constructor):
public static void Main(string[] args) { DisplayResolution resolution = DisplayDevice.Default.AvailableResolutions[120]; using (AppWindow window = new AppWindow(resolution, false)) { window.Run(30.0); } } public class AppWindow : GameWindow { public bool FullScreen { get; private set; } private GLRenderer renderer = null; private Geometry geo = null; public AppWindow(DisplayResolution resolution, bool fullScreen) : base( resolution.Width, resolution.Height, new GraphicsMode(), "SBC", (fullScreen ? GameWindowFlags.Fullscreen : GameWindowFlags.Default), DisplayDevice.Default, 3, 0, GraphicsContextFlags.Debug) // fails right here {
The constructor for the GameWindow is throwing an access violation down in ChoosePixelFormat called from line 128 of WinGraphicsMode.cs:
int pixel = Functions.ChoosePixelFormat(deviceContext, ref pixelFormat);
deviceContext = 0xffffffffbf0106e2 System.IntPtr
pixelFormat {OpenTK.Platform.Windows.PixelFormatDescriptor} OpenTK.Platform.Windows.PixelFormatDescriptor
AccumAlphaBits 0x00 byte
AccumBits 0x00 byte
AccumBlueBits 0x00 byte
AccumGreenBits 0x00 byte
AccumRedBits 0x00 byte
AlphaBits 0x00 byte
AlphaShift 0x00 byte
AuxBuffers 0x00 byte
BlueBits 0x00 byte
BlueShift 0x00 byte
ColorBits 0x00 byte
DamageMask 0x00000000 int
DepthBits 0x00 byte
Flags DOUBLEBUFFER | DRAW_TO_WINDOW | SUPPORT_OPENGL | DEPTH_DONTCARE OpenTK.Platform.Windows.PixelFormatDescriptorFlags
GreenBits 0x00 byte
GreenShift 0x00 byte
LayerMask 0x00000000 int
LayerType 0x00 byte
PixelType RGBA OpenTK.Platform.Windows.PixelType
RedBits 0x00 byte
RedShift 0x00 byte
Reserved 0x00 byte
Size 0x0028 short
StencilBits 0x00 byte
Version 0x0001 short
VisibleMask 0x00000000 int
Call stack:
> OpenTK.dll!OpenTK.Platform.Windows.WinGraphicsMode.SelectGraphicsModePFD(OpenTK.Graphics.ColorFormat color = {0 (0000)}, int depth = 0x00000000, int stencil = 0x00000000, int samples = 0x00000000, OpenTK.Graphics.ColorFormat accum = {0 (0000)}, int buffers = 0x00000002, bool stereo = false) Line 128 C#
OpenTK.dll!OpenTK.Platform.Windows.WinGraphicsMode.SelectGraphicsMode(OpenTK.Graphics.ColorFormat color = {0 (0000)}, int depth = 0x00000000, int stencil = 0x00000000, int samples = 0x00000000, OpenTK.Graphics.ColorFormat accum = {0 (0000)}, int buffers = 0x00000002, bool stereo = false) Line 78 + 0x6e bytes C#
OpenTK.dll!OpenTK.Graphics.GraphicsMode.Index.get() Line 186 + 0x162 bytes C#
OpenTK.dll!OpenTK.Graphics.GraphicsMode.ToString() Line 329 + 0x4a bytes C#
[External Code]
OpenTK.dll!OpenTK.Graphics.GraphicsContext.GraphicsContext(OpenTK.Graphics.GraphicsMode mode = {OpenTK.Graphics.GraphicsMode}, OpenTK.Platform.IWindowInfo window = {Windows.WindowInfo: Handle 1378484, Parent (Windows.WindowInfo: Handle 524978, Parent (null))}, int major = 0x00000001, int minor = 0x00000000, OpenTK.Graphics.GraphicsContextFlags flags = Default) Line 94 + 0x48 bytes C#
OpenTK.dll!OpenTK.Platform.Windows.WinGraphicsMode.SelectGraphicsModeARB(OpenTK.Graphics.ColorFormat color = {32 (8888)}, int depth = 0x00000010, int stencil = 0x00000000, int samples = 0x00000000, OpenTK.Graphics.ColorFormat accum = {0 (0000)}, int buffers = 0x00000002, bool stereo = false) Line 158 + 0x13a bytes C#
OpenTK.dll!OpenTK.Platform.Windows.WinGraphicsMode.SelectGraphicsMode(OpenTK.Graphics.ColorFormat color = {32 (8888)}, int depth = 0x00000010, int stencil = 0x00000000, int samples = 0x00000000, OpenTK.Graphics.ColorFormat accum = {0 (0000)}, int buffers = 0x00000002, bool stereo = false) Line 70 + 0x6e bytes C#
OpenTK.dll!OpenTK.Graphics.GraphicsMode.Index.get() Line 186 + 0x162 bytes C#
OpenTK.dll!OpenTK.Graphics.GraphicsMode.ToString() Line 329 + 0x4a bytes C#
[External Code]
OpenTK.dll!OpenTK.Graphics.GraphicsContext.GraphicsContext(OpenTK.Graphics.GraphicsMode mode = {OpenTK.Graphics.GraphicsMode}, OpenTK.Platform.IWindowInfo window = {Windows.WindowInfo: Handle 2820158, Parent (Windows.WindowInfo: Handle 3801558, Parent (null))}, int major = 0x00000003, int minor = 0x00000000, OpenTK.Graphics.GraphicsContextFlags flags = Debug) Line 94 + 0x48 bytes C#
OpenTK.dll!OpenTK.GameWindow.GameWindow(int width = 0x000005a0, int height = 0x00000384, OpenTK.Graphics.GraphicsMode mode = {OpenTK.Graphics.GraphicsMode}, string title = "SBC", OpenTK.GameWindowFlags options = Default, OpenTK.DisplayDevice device = {Primary: {X=0,Y=0,Width=1920,Height=1200} (147 modes available)}, int major = 0x00000003, int minor = 0x00000000, OpenTK.Graphics.GraphicsContextFlags flags = Debug, OpenTK.Graphics.IGraphicsContext sharedContext = null) Line 206 + 0xa0 bytes C#
OpenTK.dll!OpenTK.GameWindow.GameWindow(int width = 0x000005a0, int height = 0x00000384, OpenTK.Graphics.GraphicsMode mode = {OpenTK.Graphics.GraphicsMode}, string title = "SBC", OpenTK.GameWindowFlags options = Default, OpenTK.DisplayDevice device = {Primary: {X=0,Y=0,Width=1920,Height=1200} (147 modes available)}, int major = 0x00000003, int minor = 0x00000000, OpenTK.Graphics.GraphicsContextFlags flags = Debug) Line 178 + 0x6d bytes C#
SBC.exe!SBC.AppWindow.AppWindow(OpenTK.DisplayResolution resolution = {{X=0,Y=0,Width=1440,Height=900}x32@60Hz}, bool fullScreen = false) Line 16 + 0xea bytes C#
SBC.exe!SBC.Program.Main(string[] args = {string[0x00000000]}) Line 14 + 0x23 bytes C#
For reference I'm running Windows 7 x64 with an ATI 5770 with the newest (10.3) drivers installed. Oddly enough the example binaries still run just fine so I'm not sure whats going on with it. Mindfully this code was running just fine before I updated my drivers so it may have something to do with that...


Comments
Re: Access violation creating GameWindow
Oh, also I'm using the latest version of OpenTK, 1.0 RC1.
Re: Access violation creating GameWindow
I also hit this issue from time to time. The difference being that in my case it is quite random and 9 runs out of 10 are successful. I'm not sure that this is drivers related because I'm running nVidia.
Win7 64bit, 196.21, OpenTK 1.0 RC1.
Re: Access violation creating GameWindow
Some more information, still haven't solved it (although I haven't had much time to check into things). The debug output log is highly suspect--I can't seem to even step into the calls that generate all this creating/destroying spam. I'm wondering if there's some event logic going on I'm not seeing (I'm not creating multiple threads and VS only shows the main thread).
Re: Access violation creating GameWindow
for ATI drivers, install
ATI Open Stream SDK for support of OpenCL due that it is no more shipped with new drivers, as written here and here
There are reference to NVIDIA software as well.
Re: Access violation creating GameWindow
I've got the same issue. It goes away when changing the platform in Visual Studio from "Any CPU" to "x86". Installing the ATI Open Stream SDK did not help.
Windows 7 Professional (x64)
ATI Radeon HD 5870 (Catalyst 10.3)
OpenTK 1.0 RC1
Re: Access violation creating GameWindow
I'm looking into this.
Re: Access violation creating GameWindow
Oh, I see. I forgot that I was a Windows hacker ;) Yeah, now i understand, what's wrong,
While loading JIT compiler (this is unavoidable by design of .NET framework untill assembly image is not linked as native x64\x86 image), it compiles assemby on the fly as x64 images on 64bit system (Windows7) and tries to load x86 process context into x64 process context which leads to memory corruptions because 64 bit pointers are twice as big as 32 bit pointers, so some memory adressing exceptions occurs on a calee becuse of 64 bit caller's pointers.
Steps to complie QuickStart.sln (Windows7, Visual Studio)
1. Remove links in project to OpenTK.dll, using Solution Explorer for the project itself and project's Project References
2 .Add OpenTK project to solution. Add references to that project in any project you will use.
3. Add x86 solution configuration.
Using Confiiguration Manager, add new soultion configuration (x86) from existing configuration (AnyCPU).
Rebuild soultion and everything will be done automatically, you will able to debug your projects.
Cheers!
Re: Access violation creating GameWindow
Speakin about error in the topic, I discovered that nothing is wrong with OpenTK.Platform.Windows.Functions.ChoosePixelFormat(IntPtr dc, PixelFormatDescriptor& pfd)
function.
It is the first call of externally mapped dll function, so i expected managed AccessViolationException, and i got it well.
The reason i metioned previosly is that x64 versions on native dll's for system /dll's and OpenAL/GL/CL dll's are still missing by the assembly you are running, you need to rebuild them as well first for you hardware and software configuration.
Re: Access violation creating GameWindow
OpenTK is x64-aware, which it is (or should be) safe to run as AnyCPU. System dlls (like opengl32.dll, gdi32.dll etc) come in both x86 and x64 flavors and the correct one is resolved by the OS.
I'm trying to reproduce the issue in order to understand what is going wrong. So far everything seems to be running fine on both my Nvidia and Ati systems.
Re: Access violation creating GameWindow
I have no issues with my Nvidia system here at work, it runs like a charm. When I brought the project home it worked great for a couple days. I upgraded my drivers and it started doing this. I should have more time tonight to dive into this and see if I can get any more information out of it.