2

I'm running into a very strange OpenGL bug, where calling glCreateShader works several times, and then at a later point I try to call it and it fails, returning 0. Calling glGetError immediately afterwards also returns 0, indicating no error. Searching around, I see questions about glCreateShader never working, which is not the case here, and a few people mentioning that it can return 0 if called between glBegin and glEnd, which I'm not using. Looking around, I don't see any obvious things in the call stack that should indicate I'm doing something strange with OpenGL.

glGetString(GL_VERSION) returns "4.3.0 - Build 10.18.10.3977", in case that helps.

Anyone have any idea what's going on here?

Community
  • 1
  • 1
Mason Wheeler
  • 82,511
  • 50
  • 270
  • 477

1 Answers1

6

This reeks of no OpenGL context being bound to the calling thread. You didn't specify which OS you're on, but you can use wglGetCurrentContext on Windows, glXGetCurrentContext on X11 (most likely Linux) to query which context is currently bound (or not at all).

If either function returns NULL then there's no OpenGL context arond and you'll get the behaviour you described.

datenwolf
  • 159,371
  • 13
  • 185
  • 298
  • That was the problem, all right. The code in question was supposed to only run on the main threat, but it got invoked in a worker threat due to a bug, and the call stack was deep enough that I didn't immediately notice. Thanks! – Mason Wheeler Jul 14 '15 at 22:20