Hello Guest

[CLOSED] glfwPollEvents() crashes on Mac OX 10.9.5 with EXC_BAD_ACCESS

  • 10 Replies
  • 20867 Views
I've been able to write a basic program that runs fine in Window 64. I've been trying to get it to work on Mac OX. I've ran into several problem that I've been able to fix but not this one. I am using lwjgl 3.0a. When the program runs, it renders everything fine until it reaches glfwPollEvents(). Then the Java VM crashes. It works fine when I comment out glfwPollEvents(), of course then you can't do anything with it (including close the window). Any ideas? Here's my loop:
Code: [Select]
...
 public void start()
   {

      Throwable t = null;
      try
      {
         _programs = new Programs();
         _board = new Board(_programs, 500, 500);

         initFramework();

         initOpenGL();

         while (glfwWindowShouldClose(window) == GL_FALSE)
         {

            Vec3 cameraPosition = ResolveCamPosition();
            Mat4 worldToCameraMatrix = Glm.lookAt(cameraPosition, _board.getHero().getPosition(), _updir);

            _board.processKeyPress(window, cameraPosition);
            if (!_mouseDisabled)
            {
               Mat4 persMatrix = Glm.perspective(45, _board.getWidth() / _board.getHeight(), fzNear, fzFar);
               _board.processMousePress(window, worldToCameraMatrix, persMatrix, cameraPosition);
            }

            _board.cycle(glfwGetTime());

            glClearColor(0f, 0f, 0f, 0f);
            glClearDepth(1);
            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            _board.render(worldToCameraMatrix);


            glfwSwapBuffers(window);

         
            glfwPollEvents();//-->must comment out for Mac Os to work!
         }

         glfwDestroyWindow(window);
      }
      catch (Throwable th)
      {
...

And it dies by killing the whole JVM (ie, no Error is thrown) with this:

Code: [Select]
Process:         java [68300]
Path:            /Library/Internet Plug-Ins/JavaAppletPlugin.plugin/Contents/Home/bin/java
Identifier:      java
Version:         1.0 (1.0)
Code Type:       X86-64 (Native)
Parent Process:  java [68299]
Responsible:     Jar Launcher [68296]
User ID:         501

Date/Time:       2015-04-30 17:32:53.171 -0500
OS Version:      Mac OS X 10.9.5 (13F1077)
Report Version:  11
Anonymous UUID:  AB3B5505-A56A-28A5-35B3-A4BBE27168C1


Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGABRT)
Exception Codes: EXC_I386_GPFLT

Application Specific Information:
abort() called

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libsystem_kernel.dylib        0x00007fff88c34866 __pthread_kill + 10
1   libsystem_pthread.dylib        0x00007fff88cd035c pthread_kill + 92
2   libsystem_c.dylib              0x00007fff8f369b1a abort + 125
3   libjvm.dylib                  0x000000010da6e22f os::abort(bool) + 25
4   libjvm.dylib                  0x000000010db8ec8c VMError::report_and_die() + 2250
5   libjvm.dylib                  0x000000010da6fe5a JVM_handle_bsd_signal + 1131
6   libjvm.dylib                  0x000000010da6c137 signalHandler(int, __siginfo*, void*) + 47
7   libsystem_platform.dylib      0x00007fff8a35d5aa _sigtramp + 26
8   libobjc.A.dylib                0x00007fff8912a091 objc_msgSend + 17
9   liblwjgl.dylib                0x00000001214ddcc8 -[GLFWWindowDelegate windowDidBecomeKey:] + 360
10  com.apple.CoreFoundation      0x00007fff8a8c6e0c __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 12
11  com.apple.CoreFoundation      0x00007fff8a7ba82d _CFXNotificationPost + 2893
12  com.apple.Foundation          0x00007fff90c30dda -[NSNotificationCenter postNotificationName:object:userInfo:] + 68
13  com.apple.AppKit              0x00007fff9165fd6a -[NSWindow becomeKeyWindow] + 1463
14  com.apple.AppKit              0x00007fff9165f236 -[NSWindow _changeKeyAndMainLimitedOK:] + 803
15  com.apple.AppKit              0x00007fff91657706 -[NSWindow _makeKeyRegardlessOfVisibility] + 100
16  com.apple.AppKit              0x00007fff91657670 -[NSWindow makeKeyAndOrderFront:] + 29
17  ???                            0x000000010e5b3954 0 + 4535826772
18  ???                            0x000000010e5a5c4d 0 + 4535770189
19  ???                            0x000000010e5a5c4d 0 + 4535770189
20  ???                            0x000000010e5a5c4d 0 + 4535770189
21  ???                            0x000000010e5a5c4d 0 + 4535770189
22  ???                            0x000000010e59e7a7 0 + 4535740327
23  libjvm.dylib                  0x000000010d8e032a JavaCalls::call_helper(JavaValue*, methodHandle*, JavaCallArguments*, Thread*) + 1710
24  libjvm.dylib                  0x000000010d916a36 jni_invoke_static(JNIEnv_*, JavaValue*, _jobject*, JNICallType, _jmethodID*, JNI_ArgumentPusher*, Thread*) + 447
25  libjvm.dylib                  0x000000010d90f7b0 jni_CallStaticVoidMethod + 349
26  java                          0x000000010cbb49ae JavaMain + 2481
27  java                          0x000000010cbb660c -[JavaLaunchHelper launchJava:] + 42
28  com.apple.Foundation          0x00007fff90c9175e __NSThreadPerformPerform + 229
29  com.apple.CoreFoundation      0x00007fff8a8295b1 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION__ + 17
30  com.apple.CoreFoundation      0x00007fff8a81ac62 __CFRunLoopDoSources0 + 242
31  com.apple.CoreFoundation      0x00007fff8a81a3ef __CFRunLoopRun + 831
32  com.apple.CoreFoundation      0x00007fff8a819e75 CFRunLoopRunSpecific + 309
33  java                          0x000000010cbb7490 CreateExecutionEnvironment + 871
34  java                          0x000000010cbb321c JLI_Launch + 1952
35  java                          0x000000010cbb94ed main + 101
36  java                          0x000000010cbb2a74 start + 52

Thread 1:
...
« Last Edit: May 01, 2015, 18:18:59 by linkbew »

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Could you try the Events demo from the LWJGL repository? Does it crash too?
« Last Edit: July 01, 2015, 08:22:50 by spasi »

Could you try the Events demo from the LWJGL repository? Does it crash too?
Tried it and it works fine. I even replaced the main loop with the following so it would closer match what I am doing.
Quote
while ( glfwWindowShouldClose(window) == 0 ) {

         if (glfwGetKey(window, GLFW_KEY_W) == GLFW_PRESS)
         {
           
         }
         if (glfwGetMouseButton(window, GLFW_MOUSE_BUTTON_LEFT) == GLFW_PRESS)
         {
           
         }

         glfwPollEvents();

         glClear(GL_COLOR_BUFFER_BIT);
         glfwSwapBuffers(window);
      }

I'm not sure why this works and mine doesn't...

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Do you keep strong references to the callback closures in your code?

Do you keep strong references to the callback closures in your code?

I do not....but I don't see that in the sample code anywhere...unless it's this:

Quote
System.setProperty(
         "org.lwjgl.system.libffi.ClosureRegistry",
         "org.lwjgl.demo.util.ClosureGC"
      );
?

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Indeed, that was an experiment that allows you to not store references to the callbacks. Normally you should, read this post for details.

Well that didn't work.

I tried a few things. First I added your System Property to my code, and that didn't fix it. So I then saved all my Callbacks in a List and called release() on all of them at the end of the program. That also didn't fix it. Then I removed the System Property from the Events class to see if it would crash, and it did not.

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Then it's probably something else.

You can try simplifying your code. Remove as much as you can, but make sure you can still reproduce the issue. If you can get it down to something that you can share, I'll try to debug the issue on my machine.

I have gotten rid of a lot of code and it still keeps crashing. Here's what I'm down to:

Code: [Select]
package com.ow2.display;

import static org.lwjgl.glfw.Callbacks.errorCallbackPrint;
import static org.lwjgl.glfw.GLFW.*;
import static org.lwjgl.opengl.GL11.*;
import static org.lwjgl.system.MemoryUtil.NULL;

import java.nio.ByteBuffer;
import java.util.ArrayList;

import org.lwjgl.glfw.GLFWErrorCallback;
import org.lwjgl.glfw.GLFWvidmode;
import org.lwjgl.opengl.GLContext;
import org.lwjgl.system.libffi.Closure;

public class OWDisplay2
{
   public static void main(String[] args)
   {
      new OWDisplay2().start();
   }

   private long window;

   ArrayList<Closure> _callbackClosures = new ArrayList<>();

   public void start()
   {

      System.setProperty("org.lwjgl.system.libffi.ClosureRegistry", "org.lwjgl.demo.util.ClosureGC");

      Throwable t = null;
      try
      {

         initFramework();

         while (glfwWindowShouldClose(window) == GL_FALSE)
         {

            glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);

            glfwPollEvents();
            glfwSwapBuffers(window);

         }

         glfwDestroyWindow(window);
      }
      catch (Throwable th)
      {
         t = th;
         th.printStackTrace(System.err);
         try
         {

            glfwDestroyWindow(window);
         }
         catch (Exception e)
         {
         }
      }
      finally
      {
         glfwTerminate();

         for (Closure closure : _callbackClosures)
         {
            closure.release();
         }
      }

   }

   private void initFramework()
   {

      GLFWErrorCallback errorCallback = errorCallbackPrint(System.err);
      _callbackClosures.add(errorCallback);
      glfwSetErrorCallback(errorCallback);

      if (glfwInit() != GL_TRUE)
         throw new IllegalStateException("Unable to initialize GLFW");

      glfwDefaultWindowHints();
      glfwWindowHint(GLFW_VISIBLE, GL_FALSE);

      window = glfwCreateWindow(500, 500, "Other World 2", NULL, NULL);

      if (window == NULL)
         throw new RuntimeException("Failed to create the GLFW window");

      glfwMakeContextCurrent(window);
      glfwSwapInterval(1);

      GLContext.createFromCurrent();

      ByteBuffer vidmode = glfwGetVideoMode(glfwGetPrimaryMonitor());
      glfwSetWindowPos(window, (GLFWvidmode.width(vidmode) - 500) / 2,
            (GLFWvidmode.height(vidmode) - 500) / 2);

      glfwSetGamma(window, 1f);
      glfwShowWindow(window);
   }

}

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Reproduced, indeed it crashes at glfwPollEvents(), but the bug is elsewhere:

Code: [Select]
glfwSetGamma(window, 1f);You're passing the window handle to a function that expects a monitor handle. Replacing the above with:

Code: [Select]
glfwSetGamma(glfwGetPrimaryMonitor(), 1f);fixes the crash.

That was it! Thanks for your help. This was a tough one to find...