robpson's picture

Possible bug in GraphicsContext.CreateDummyContext()

Project:The Open Toolkit library
Version:0.9.9-2b
Component:Code
Category:bug report
Priority:normal
Assigned:the Fiddler
Status:closed
Description

My winodws desktop throws an null reference exception when using GraphicsContext.CreateDummyContext(), and there _is_ an active context (i even doubly checked it with wglGetCurrentContext, which returned a non-null value). I saw this was a bug in an earlier opentk version, but i use latest 'stable', 0.9.8-1

I badly needs this function to hook opentk to an external context, is there any workarounds for now?

/robpson


Comments

Comment viewing options

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

#1

Assigned to:Anonymous» the Fiddler

A small test case that reproduces the bug would really help here.

robpson's picture

#2

Im working on a cross-platform C# wrapper to the user interface library IUP. Its not easy to post a small code snippet copied from this project, but what im basically do is:

//---Begin code----------------------------
//create window with GL control on
window=new Dialog(new GLCanvas(300,300), ...a lot of non-important things here, buttons and other stuff...)

//the gl context is not created before the window is Show() in iup so:
IntPtr p;
p=wglGetCurrentContex(); // <= this returns NULL which is correct since no GL context exists yet

window.Show(); <= the window with the GLCanvas is now mapped to the underlying system and a GL context is created

p=wglGetCurrentContex(); <= now this returns a non-null value (65535 on my system (: )

GraphicsContext.CreateDummyContext(); //<=crashes with null pointer reference exception
//------------------------------------------

Note that IUP is single threaded, so cross thread problems with context do not apply here.
If this was of any help, good. If not please let me know, I bet I can create a small C-Project which creates a context and recreate the bug in a small scale program (o:

//Rob.P.

the Fiddler's picture

#3

The problem is that I can't fix an issue that I can't reproduce and I am too time-limited right now to cook up a test case myself (exam period). With a small test case I could fix this issue tomorrow.

robpson's picture

#4

Sorry for the delay. So much to do and so little time....

I included a zip file that includes a minimal c project and a c# test. All the c dll does is exporting a function that creates a gl context in c++ in a standard way:

extern "C" __declspec(dllexport) HGLRC CreateGLContext(HWND hwnd) {
PIXELFORMATDESCRIPTOR pfd;
int iFormat;
HGLRC hrc;
HDC hdc;

// get the device context (DC)
hdc = GetDC( hwnd );

// set the pixel format for the DC
ZeroMemory( &pfd, sizeof( pfd ) );
pfd.nSize = sizeof( pfd );
pfd.nVersion = 1;
pfd.dwFlags = PFD_DRAW_TO_WINDOW | PFD_SUPPORT_OPENGL |
PFD_DOUBLEBUFFER;
pfd.iPixelType = PFD_TYPE_RGBA;
pfd.cColorBits = 24;
pfd.cDepthBits = 16;
pfd.iLayerType = PFD_MAIN_PLANE;
iFormat = ChoosePixelFormat( hdc, &pfd );
SetPixelFormat( hdc, iFormat, &pfd );

// create and enable the render context (RC)
hrc = wglCreateContext( hdc );
wglMakeCurrent( hdc,hrc );

return hrc;
}
///////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

***In the subfolder DummyContextTest is a c# project that does this when a button is pressed:

//import our c function that creates a context
[DllImport("GLContext.dll")]
static extern IntPtr CreateGLContext(IntPtr hwnd);

//import a check function from opengl library
[DllImport("opengl32.dll")]
static extern IntPtr wglGetCurrentContext();

private void button1_Click(object sender, EventArgs e)
{
IntPtr nullhrc = wglGetCurrentContext(); //<= returns IntPtr.zero ofcourse
IntPtr hrc = CreateGLContext(this.Handle); //returns the HGLRC, 65536 on my computer
IntPtr hrc_check = wglGetCurrentContext(); //returns same as previos line, confirming there is an active context

GraphicsContext.CreateDummyContext(); //this line crashes with an null exception
GL.LoadAll(); //and this never happens because of that
Glu.LoadAll();
}

I included the c dll so that you dont have to compile it, but I included the vc++ project files so you can do it if you want. I also included the c# exe file and the solution for it. Hope this helps to clear this out...

Note that I did not include OpenTK.dll to save some space but I bet yoiu have it |o:

/Rob.P.

AttachmentSize
GLContext.zip94.73 KB
the Fiddler's picture

#5

Thanks, this will help track down the bug!

objarni's picture

#6

What is CreateDummyContexts function..? The name implies a "dummy" or "fake" context -- like something used during boot time before the "real" context is there. But judging from the above discussion, it seems it is used to "hook into" contexts created by other libraries than OpenTK, is that the case? Maybe it should be called "CreateExternalContext" or "CreateHookedContext" or something instead to be more clear?

the Fiddler's picture

#7

Status:open» confirmed
the Fiddler's picture

#8

Status:confirmed» in progress
the Fiddler's picture

#9

Version:0.9.8-1» 0.9.x-dev
Status:in progress» fixed

Issue fixed in 0.9.8 branch and trunk (SVN rev. 2099).

the Fiddler's picture

#10

Version:0.9.x-dev» 0.9.9-2b
Status:fixed» closed

Closing issues fixed in 0.9.9-2.