I've got a problem with DevIL and I've some posts with the same problem but couldn't find the solution. The problem is that when I compile my code I get with IL.create() in the code:
Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glGenTextures(GL11.java:1169)
at game.TextureLoader.load(TextureLoader.java:28)
at game.Scene.<init>(Scene.java:7)
at game.Main.<init>(Main.java:15)
at game.Main.main(Main.java:81)
Java Result: 1
and without it in the code:
#
# An unexpected error has been detected by Java Runtime Environment:
#
# EXCEPTION_ACCESS_VIOLATION (0xc0000005) at pc=0x00000000, pid=2812, tid=1108
#
# Java VM: Java HotSpot(TM) Client VM (1.6.0-rc-b61 mixed mode, sharing)
# Problematic frame:
# C 0x00000000
#
# An error report file with more information is saved as hs_err_pid2812.log
#
# If you would like to submit a bug report, please visit:
# http://java.sun.com/webapps/bugreport/crash.jsp
#
Java Result: 1
It's the same when using jse 5.0 and jse 6.0
Any solution to this?
Thanks in advance!
The crash is a known problem as dynamic stub loading isn't supported on the DevIL side of things yet, and if I remember correctly, FMOD does the same too... But Mazon is on it, so it should be fixed soon :)
As for the stack trace, would you mind posting some code? That would help alot..
DP
Strange cause it worked earlier...
For the code this is supposed to load the texture in to the memory and return the handle (I took it from NeHe's tutorial - still learning to use LWJGL :) )
public static int load(String path)
{
IntBuffer image = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
IL.ilGenImages(image);
IL.ilBindImage(image.get(0));
IL.ilLoadImage(path);
IL.ilConvertImage(IL.IL_RGBA, IL.IL_BYTE);
ByteBuffer scratch = ByteBuffer.allocateDirect(IL.ilGetInteger(IL.IL_IMAGE_WIDTH) * IL.ilGetInteger(IL.IL_IMAGE_HEIGHT) * 3);
IL.ilCopyPixels(0, 0, 0, IL.ilGetInteger(IL.IL_IMAGE_WIDTH), IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 1, IL.IL_RGB, IL.IL_BYTE, scratch);
IntBuffer buf = ByteBuffer.allocateDirect(4).order(ByteOrder.nativeOrder()).asIntBuffer();
GL11.glGenTextures(buf);
GL11.glBindTexture(GL11.GL_TEXTURE_2D, buf.get(0));
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MIN_FILTER, GL11.GL_LINEAR);
GL11.glTexParameteri(GL11.GL_TEXTURE_2D, GL11.GL_TEXTURE_MAG_FILTER, GL11.GL_LINEAR);
GL11.glTexImage2D(GL11.GL_TEXTURE_2D, 0, GL11.GL_RGB, IL.ilGetInteger(IL.IL_IMAGE_WIDTH),
IL.ilGetInteger(IL.IL_IMAGE_HEIGHT), 0, GL11.GL_RGB, GL11.GL_UNSIGNED_BYTE, scratch);
return buf.get(0);
}
Forgot to add this before at the beginning:
try
{
IL.create();
}catch(LWJGLException e){}
static {
try {
IL.create();
ILU.create();
ILUT.create();
ILUT.ilutRenderer( ILUT.ILUT_OPENGL );
checkAnisotropicFilter();
} catch ( LWJGLException e ) {
System.err.println( "Failed to load OpenIL" );
System.exit( 1 );
}
}
private static Texture loadTextureBase( URL url, boolean mipmap, boolean flip )
throws IOException {
IntBuffer ib = BufferUtils.createIntBuffer( 1 );
IL.ilGenImages( ib );
int image = ib.get( 0 );
IL.ilBindImage( image );
if ( !IL.ilLoadFromURL( url ) )
throw new IOException( "IL error " + IL.ilGetError() + " loading texture" );
if ( flip )
ILU.iluFlipImage();
int glImage = 0;
if ( mipmap )
glImage = ILUT.ilutGLBindMipmaps();
else
glImage = ILUT.ilutGLBindTexImage();
if ( anisotropicFilter > 0 )
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, anisotropicFilter);
if ( glImage == 0 )
Util.checkGLError();
IL.ilDeleteImages( ib );
// reset texture, got me in a proper headache earlier
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
return new Texture( glImage );
}
That works...try that...
DP
Not working. Still the same NullPointerException.
have you created an display beforehand ?
yes
well, the only way you can get a NPE in that piece of code:
long function_pointer = GLContext.getCapabilities().GL11_glGenTextures_pointer;
is by not having a valid context, which I am unsure about how you can possibly have.
Do you have some multithreaded code ?
Does LWJGL demos work fine for you ?
The demos work fine and well my application is not multithreaded.
I checked the devil's BasicTest and I get:
init:
deps-jar:
Compiling 1 source file to F:\java app\Game\build\classes
compile:
run:
error = no error
ilGenImages
ilBindImage
error = no error
error = no error
ilGetData
error = no error
limit = 900
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 0
0 0 0
0 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 -1
-1 -1 -1
-1 -1 -1
-1 -1 -1
-1 -1 -1
-1 -1 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 0
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 -1
-1 -1 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
-1 -1 -1
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0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 0
0 -1 0
0 0 -1
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 -1
0 0 0
-1 0 0
0 -1 0
0 0 -1
0 0 0
-1 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
0 0 0
current image = 2 IL.ilGetInteger(IL.IL_ACTIVE_IMAGE) = 0
Version: 167
error = no error
info.id = 3
info.width = 15
info.height = 15
info.depth = 1
info.bpp = 4
info.sizeOfData = 900
info.format = 6408
info.type = 5121
info.origin = 1537
info.palType = 1024
info.palSize = 0
info.numNext = 0
info.numMips = 0
info.numLayers = 0
error = no error
ILUT Vendor: Abysmal Software
BUILD SUCCESSFUL (total time: 1 second)
so it's working
Here's my code for loading the texture:
public static int load(String path)
{
try
{
IL.create();
ILU.create();
ILUT.create();
ILUT.ilutRenderer( ILUT.ILUT_OPENGL );
}
catch(LWJGLException e)
{}
IntBuffer ib = BufferUtils.createIntBuffer( 1 );
IL.ilGenImages( ib );
int image = ib.get( 0 );
IL.ilBindImage( image );
IL.ilLoadImage(path);
int glImage = 0;
glImage = ILUT.ilutGLBindTexImage();
GL11.glTexParameterf(GL11.GL_TEXTURE_2D, EXTTextureFilterAnisotropic.GL_TEXTURE_MAX_ANISOTROPY_EXT, 16);
if ( glImage == 0 )
Util.checkGLError();
IL.ilDeleteImages( ib );
GL11.glBindTexture(GL11.GL_TEXTURE_2D, 0);
return glImage;
}
And I get:
Exception in thread "main" java.lang.NullPointerException
at org.lwjgl.opengl.GL11.glTexParameterf(GL11.java:2264)
at game.TextureLoader.load(TextureLoader.java:34)
at game.Scene.<init>(Scene.java:7)
at game.Main.<init>(Main.java:15)
at game.Main.main(Main.java:81)
Java Result: 1
Strange cause the BasicTest works..