hey guys
I’m having some problems with random crashes, and hope someone here can help me out
My gameloop is not handled by an animator, autoswapbuffer mode is 0, and each tick (after processing game logic), drawable.display() is called which calls display(), which calls the draw callbacks (and loads textures etc). after stuff is rendered, the game loop sleeps until end of tick (1/60 second) and swaps the buffer.
the loading routine for the texture is this:
private void makeTexture(GL gl) {
// binds this texture, id is generated earlier
bind(gl);
int srcPixelFormat;
if (bi.getColorModel().hasAlpha())
srcPixelFormat = GL.GL_RGBA;
else
srcPixelFormat = GL.GL_RGB;
// convert that image into a byte buffer of texture data
ByteBuffer textureBuffer = convertImageData(bi, texWidth, texHeight);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_S, GL.GL_CLAMP);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_WRAP_T, GL.GL_CLAMP);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MIN_FILTER, GL.GL_LINEAR);
gl.glTexParameteri(GL.GL_TEXTURE_2D, GL.GL_TEXTURE_MAG_FILTER, GL.GL_LINEAR);
// produce a texture from the byte buffer
gl.glTexImage2D(GL.GL_TEXTURE_2D, 0, GL.GL_RGB, texWidth, texHeight, 0, srcPixelFormat, GL.GL_UNSIGNED_BYTE, textureBuffer);
}
private static ByteBuffer convertImageData(BufferedImage bi, int texWidth, int texHeight) {
ByteBuffer imageBuffer = null;
WritableRaster raster;
BufferedImage texImage;
// we need an ogl-compatible raster
if (bi.getColorModel().hasAlpha()) {
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, texWidth, texHeight, 4, null);
texImage = new BufferedImage(glAlphaColorModel, raster, false, null);
} else {
raster = Raster.createInterleavedRaster(DataBuffer.TYPE_BYTE, texWidth, texHeight, 3, null);
texImage = new BufferedImage(glColorModel, raster, false, null);
}
// copy the source image into the produced image
Graphics2D g = (Graphics2D) texImage.getGraphics();
g.setColor(new Color(0f, 0f, 0f, 0f));
g.fillRect(0, 0, texWidth, texHeight);
g.drawImage(bi, 0, 0, null);
// build a byte buffer from the temporary image that be used by OpenGL to produce a texture.
byte[] data = ((DataBufferByte) texImage.getRaster().getDataBuffer()).getData();
imageBuffer = ByteBuffer.allocateDirect(data.length);
imageBuffer.order(ByteOrder.nativeOrder());
imageBuffer.put(data, 0, data.length);
return imageBuffer;
}
texwidth and texheight are the closest potence of 2 of the image’s width/height, glColorModel/glAlphacolorModel are obviously the color models needed for the conversion, as you can see a good part of the code is taken from the known tutorials
the crashes occur at the glTexImage2D call, error is this:
ideas, anyone? :-\