Problem with Space Invaders project

Started by Chuckleluck, June 08, 2013, 19:23:33

Previous topic - Next topic

Chuckleluck

Hello,
I'm trying to get my first LWJGL game project working.  All the code is copied from the Space Invaders example project on the wiki (http://www.lwjgl.org/wiki/index.php?title=Space_Invaders_Example_Game).  However, I tried running it, and I get this error:

Exception in thread "main" java.lang.IllegalArgumentException: Number of remaining buffer elements is 256, must be at least 512. Because at most 512 elements can be returned, a buffer with at least 512 elements is required, regardless of actual returned element count
	at org.lwjgl.BufferChecks.throwBufferSizeException(BufferChecks.java:162)
	at org.lwjgl.BufferChecks.checkBufferSize(BufferChecks.java:189)
	at org.lwjgl.BufferChecks.checkBuffer(BufferChecks.java:230)
	at org.lwjgl.opengl.GL11.glTexImage2D(GL11.java:2845)
	at me.chuckle.flwjglp.TextureLoader.getTexture(TextureLoader.java:92)
	at me.chuckle.flwjglp.TextureLoader.getTexture(TextureLoader.java:60)
	at me.chuckle.flwjglp.Sprite.<init>(Sprite.java:15)
	at me.chuckle.flwjglp.Game.getSprite(Game.java:355)
	at me.chuckle.flwjglp.ShotEntity.<init>(ShotEntity.java:13)
	at me.chuckle.flwjglp.Game.initialize(Game.java:129)
	at me.chuckle.flwjglp.Game.<init>(Game.java:65)
	at me.chuckle.flwjglp.Game.main(Game.java:346)
AL lib: (EE) alc_cleanup: 1 device not closed


This seems very cryptic.  I've tried googling it, to no avail.  This is my TextureLoader class: http://pastebin.com/1r2LdwQB.  I apologize if this is a very simple mistake, like I said, this is my first LWJGL project.  I'd appreciate it if someone could point out my problem.  Thanks in advance :)

quew8

This is IMO a bad  error description but LWJGL uses as a one size fits all when doing buffer checks. It makes sense if your doing a glGetXXX operation where the buffer must be large enough to accommodate the data but it also gets used when doing some kind of write operation and LWJGL works out that the buffer you supplied cannot fit all of the data in it. In the case of glTexImage, the size (actually it is the limit but a lot of the time that is the same but lots don't know what the limit is) of the buffer must be at least the width times the height * the number of components to each pixel.

The issue you are having is with your get2Fold() method. The conditional you use is <= when it should be <. When the image size is already a pot then this results in the pot above it. convertImageData() however doesn't use this method but does it correctly. Hence the buffer returned from convertImageData() is the correct size but you are passing the wrong arguments for width and height to glTexImage.

Chuckleluck

Ah, I see.  Such a small mistake made such a huge problem ::) Anyway, thanks for the quick reply.