[BUG] MacosXDisplay calls glViewport when context isn't owned

Started by tduindam, February 15, 2014, 15:36:13

Previous topic - Next topic

tduindam

Regardless of whether the context is currently owned the update function in MacosXDisplay calls glViewport.

In the scenario where rendering is done in one thread and polling the input in another this causes a crash. I was trying to recreate the setup that Spasi suggests in this thread: http://lwjgl.org/forum/index.php?topic=5196.0

Below is the code that I believe is wrong, I think there should be a check if the context is owned before calling glViewport.

Also, it is a bit strange that should_update is forced true.


public void update() {
      boolean should_update = true;

      DrawableGL drawable = (DrawableGL)Display.getDrawable();
      if (should_update) {
         drawable.context.update();
         /* This is necessary to make sure the context won't "forget" about the view size */
         if (skipViewportValue) skipViewportValue = false;
         else glGetInteger(GL_VIEWPORT, current_viewport);
         glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3));
      }

      if (native_mode && updateNativeCursor) {
         updateNativeCursor = false;
         try {
            setNativeCursor(currentNativeCursor);
         } catch (LWJGLException e) {
            e.printStackTrace();
         }
      }
   }

tduindam

I've downloaded the LWJGL source and made a small change to MacOSXDisplay.java. I check if the context is current before attempting to call openGL commands. Not quite sure if my fix is everything it should be.

Some feedback? Thanks :-)

public void update() {
      boolean should_update = true;
      
      DrawableGL drawable = (DrawableGL)Display.getDrawable();
      if (should_update) {
         drawable.context.update();
         try{
            if( drawable.context.isCurrent())
            {
               /* This is necessary to make sure the context won't "forget" about the view size */
               if (skipViewportValue) skipViewportValue = false;
               else glGetInteger(GL_VIEWPORT, current_viewport);
               glViewport(current_viewport.get(0), current_viewport.get(1), current_viewport.get(2), current_viewport.get(3));
            }
         } catch (Exception e){}
      }
      
      if (native_mode && updateNativeCursor) {
         updateNativeCursor = false;
         try {
            setNativeCursor(currentNativeCursor);
         } catch (LWJGLException e) {
            e.printStackTrace();
         }
      }
   }

Cornix

Well, does it work now with this change? Maybe it would be better if you told us about the outcome.

tduindam

I have been doing some more testing.

The fix above solves my problem.

However, on MacOS I hardly get any mouse events. I'm not sure if this is caused by the fix I made, or there is some other problem. I can't test that either, since I can't run the game on MacOS without my fix.