gpt4 book ai didi

java - FloatBuffer 抛出异常?我怎样才能解决这个问题?

转载 作者:行者123 更新时间:2023-12-01 12:48:06 24 4
gpt4 key购买 nike

代码:

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 环境照明。

最佳答案

如果缓冲区对于请求的操作来说太小,LWJGL 会抛出此错误。请参阅here

我的猜测是 BufferTools.reserveData(4) 保留 4 个字节,而不是 4*sizeof(float) == 16 个字节。

关于java - FloatBuffer 抛出异常?我怎样才能解决这个问题?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24489637/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com