I’m having a problem with moving to a two threaded solution. First I initialize and load the scenegraph and then create the simulation thread in OnCreate() passing it a pointer to the scenegraph however when i step through into the thread, glGetError() returns 0x00502 (GL_INVALID_OPERATION) infering that the context is invalid; the same error code is generated regardless of where i query it within the simulation thread.
I’m using GXBase and the glex pointer provides the opengl window context.

in Controller::OnCreate():

GLenum AAA = glGetError(); //0
_SceneGraph = new SceneGraphModel(&_Glex);
HANDLE h_ThreadSceneGraph = (HANDLE)_beginthreadex(NULL, 67108864, _SceneGraph->SGMLoop, _SceneGraph, 0, &_ThreadIDSceneGraph);
GLenum BBB = glGetError(); //0

in the SceneGraphModel:

unsigned __stdcall SceneGraphModel::SGMLoop(void* p_SGM)
SceneGraphModel* M = (SceneGraphModel*)p_SGM;
GLenum AAA = glGetError(); //1282


Does anyone have any idea why the context would suddenly invalidate itself outside of the main thread?

thanks in advance.

The current context is a thread-specific thing. If you have a context that is current in one thread, it cannot be made current in another thread. Generally, people get around this by creating a second context that shares objects with the first.

You can make the contex current in the second thread but it willno longer be current in the other thread. You would have switch back and forth and you lose speed. Using another context for the seconx thread is another way but still, it isn’t really that great

I am experiencing the same error with the error code 1282. This error occurs when I try to debug the program. My program involves rendering a 2d image/ simulation. This error occurs right in the beginning of running the code. The error points back to render axes function. I read up a few articles and it said that it might have something to do with the buffer size as there might be a stack overflow problem but I do not believe this is the case since at that point in my program it is only trying to render the grids.
Before the following 2 programs a few transformations lines have been executed and simple initialization has been done.
Hardware/Software details:
OpenGl version : 1.1
The problem occurs on both NVIDIA and ATI.
ATI version: HD5670
Vidia Card: geforce gtx460
programming language: c and c++

Here are the two programs:

void CMglCamera2D::SetupBuffer()

::glClearColor(MGL_COLOR_WHITE, 0.0);



void CMglView::RenderGrid()
if( !_config.bRenderGrid || m_bPreviewMode )


// disable z-buffer for grid

if( m_dlGrid.IsEmpty() )



void MglCheckError()
if (!s_nGLDepth)

while( GLenum error=::glGetError() )

     TRACE( "** OpenGL error: %s **

", gluErrorString (error) );


This topic was automatically closed 183 days after the last reply. New replies are no longer allowed.