Hello Guest

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

  • 3 Replies
  • 8007 Views
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();
         }
      }
   }
« Last Edit: February 15, 2014, 16:15:07 by tduindam »

Re: [BUG] MacosXDisplay calls glViewport when context isn't owned
« Reply #1 on: February 15, 2014, 16:54:13 »
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();
         }
      }
   }
« Last Edit: February 15, 2014, 17:01:33 by tduindam »

*

Offline Cornix

  • *****
  • 488
Re: [BUG] MacosXDisplay calls glViewport when context isn't owned
« Reply #2 on: February 15, 2014, 17:35:35 »
Well, does it work now with this change? Maybe it would be better if you told us about the outcome.

Re: [BUG] MacosXDisplay calls glViewport when context isn't owned
« Reply #3 on: February 16, 2014, 09:36:46 »
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.
« Last Edit: February 16, 2014, 15:39:37 by tduindam »