Closed stetre closed 4 years ago
This is because MoonGL tracks the creation/deletion of GL objects, for proper deletion at exit.
The problem is that MoonGL identifies objects by the GL 'name' assigned to them by the OpenGL driver, which is reused across contexts.
Add to this that contexts themselves are not managed (created/deleted/made current) via the OpenGL API, but via OS API or libraries such as GLFW, GLUT, etc, so there is no simple way to associate an object with the context it belongs to.
Possible solution:
gl.make_context_current(contextid)
function to be called whenever a context is made current (e.g. if MoonGLFW is used, whenever glfw.make_context_current()
is called ), to inform MoonGL about the id of the current context. Calling this function should be required only when dealing with multiple GL contexts.The above solution is useless, though, without a mean to switch context.
The only reason for the object tracking system is to automatically delete objects at exit, in case the application didn't delete them for some reason (e.g. if an error occurred).
Since the glDeleteXxx()
functions are contextual (e.g., glDeleteProgram(1)
deletes the program object with name=1
in the current GL context), in order to delete objects from multiple GL contexts we need to be able to switch context during the cleanup.
AFAIK, the OpenGL API does not provide such capability, so either we ask the application to provide it (e.g. via a callback that calls glfw.make_context_current()
or equivalent functions), or we just give up tracking objects when multiple GL contexts are in use, leaving to the application the responsibility for deleting objects.
The current fix is to disable object tracking and their automatic deletion as soon as a duplicate object name is detected, from which we infere that multiple GL contexts are being used (in this case, it is up to the application to delete objects in their correct context).
See https://github.com/stetre/moonnuklear/issues/6#issuecomment-585070571