Reputation: 1640
I try to get max texture size on device where app is running:
protected int getMaxTextureSize() {
IntBuffer buf = BufferUtils.newIntBuffer(16);
Gdx.gl.glGetIntegerv(GL20.GL_MAX_TEXTURE_SIZE, buf); //here is null pointer exception
return buf.get();
}
and app crashes when I use it:
Exception in thread "main" java.lang.NullPointerException
at com.example.ResourceManager.getMaxTextureSize(ResourceManager.java:32)
at com.example.ResourceManager.<init>(ResourceManager.java:23)
at com.example.Game.<init>(Game.java:17)
at com.example.desktop.DesktopLauncher.main(DesktopLauncher.java:15)
(on Android same exception appears)
Why? Every forum or docs say it is correct.
Upvotes: 2
Views: 208
Reputation: 45332
The stack trace shows that the NullPointerException does not happen inside Gdx.gl.glGetIntegerv
, strongly indicating that Gdx.gl.glGetIntegerv
itself might be a NULL pointer.
Since glGetIntegerv
is a core function which must be present in all versions of GL and GLES, the most plausible explanation is that you call this function before the GL binding is properly initialized.
For this function to return meaningful values, you will always need a valid GL context in any case, so you must move it to some point after the GL context is created.
Upvotes: 1