0

When I try to call any GL15 function in lwjgl I get A NullPointerException. The problem is caused by a variable called caps inside GL15.class. Caps is loaded in the following way: ContextCapabilities caps = GLContext.getCapabilities();. After this however caps is null. What I want to know is if this is a problem with the way I initialized lwjgl, or a problem with lwjgl itself. I initialize lwjgl with the following code:

Display.setDisplayMode(new DisplayMode(800, 600));
Display.create();
jbills
  • 694
  • 1
  • 7
  • 22

1 Answers1

1

Looking at the code, it appears that the capabilities object is stored in a non-inherited ThreadLocal. That means that the capabilities object initialized / set in one thread will not be available to a different thread. I suspect that that is the root cause of your problems.


Incidentally, the GLContext class claims to be thread-safe, but I don't think it is. If you look at the source code the getCapabilities() method (in the linked page above), it accesses a private static called fast_path_cache without any synchronization, and then refers to fields of the object. If some other thread has recently changed ... or is in the process of changing ... the variable or the object that it refers to, then this thread may see stale and inconsistent values.

It is not sufficient to just synchronize the code that performs the updates. (And it is not sufficient to just say the code is thread-safe in the javadoc ...)

If someone who uses this library wants to report this to the maintainers, please feel free to do so. But PLEASE double-check my reading of the code FIRST!!

Stephen C
  • 698,415
  • 94
  • 811
  • 1,216