2014-06-30 171 views
0

代碼:FloatBuffer拋出異常?我怎樣才能解決這個問題?

FloatBuffer buf = BufferTools.reserveData(4); 
float[] fl = new float[]{0.1f, 0.1f, 0.1f, 1.0f}; 
buf.put(fl); 

其中buf.put(fl)是線2039的錯誤都在談論:

Exception in thread "main" java.lang.IllegalArgumentException: Number of remaining buffer elements is 0, must be at least 4. Because at most 4 elements can be returned, a buffer with at least 4 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:258) 
    at org.lwjgl.opengl.GL11.glLight(GL11.java:2039) 
    at Joehot200.TerrainDemo.setUpLighting(TerrainDemo.java:1543) 
    at Joehot200.TerrainDemo.enterGameLoop(TerrainDemo.java:1984) 
    at Joehot200.TerrainDemo.startGame(TerrainDemo.java:2109) 
    at Joehot200.Main.main(Main.java:56) 

我在做什麼錯?我只想擁有一個帶有4個元素的FloatBuffer,這樣我就可以設置OpenGL環境照明。

+0

什麼是TerrainDemo:2109年,1984年和1543年? – Brian

+0

因此,您向我們展示的代碼來自'org.lwjgl.opengl.GL11',而不是您自己的代碼? –

+0

BufferTools不是'org.lwggl' API。它從何而來? –

回答

1

LWJGL拋出這個錯誤,它的緩衝區對於請求的操作來說太小。見here

我的猜測是BufferTools.reserveData(4)保留4個字節,而不是4 * sizeof(float)== 16字節。

相關問題