Hello Guest

3.0.0a/b java.nio.HeapDoubleBuffer cannot be cast to sun.nio.ch.DirectBuffer

  • 3 Replies
  • 8033 Views
Stack trace:

Code: [Select]
[error] Exception in thread "main" java.lang.ExceptionInInitializerError
[error]         at net.fluffy8x.thsch.base.Diagnostics.main(Diagnostics.scala)
[error] Caused by: java.lang.ClassCastException: java.nio.HeapDoubleBuffer cannot be cast to sun.nio.ch.DirectBuffer
[error]         at org.lwjgl.system.MemoryAccessSun$MemoryAccessorUnsafe.getAddress(MemoryAccessSun.java:82)
[error]         at org.lwjgl.system.MemoryUtil.memAddress0(MemoryUtil.java:115)
[error]         at org.lwjgl.system.MemoryUtil.memAddress(MemoryUtil.java:195)
[error]         at org.lwjgl.system.MemoryUtil.memAddress(MemoryUtil.java:192)
[error]         at org.lwjgl.opengl.GL15.glBufferData(GL15.java:368)
[error]         at net.fluffy8x.thsch.entity.Primitive._register(Primitive.scala:103)
[error]         at net.fluffy8x.thsch.entity.Entity$class.register(Entity.scala:22)
[error]         at net.fluffy8x.thsch.entity.Primitive.register(Primitive.scala:15)
[error]         at net.fluffy8x.thsch.base.Diagnostics$.myinit(Diagnostics.scala:41)
[error]         at net.fluffy8x.thsch.lwjgl.LWJGLApplication$class.loop(LWJGLApplication.scala:68)
[error]         at net.fluffy8x.thsch.lwjgl.LWJGLApplication$class.$init$(LWJGLApplication.scala:80)
[error]         at net.fluffy8x.thsch.base.Diagnostics$.<init>(Diagnostics.scala:8)
[error]         at net.fluffy8x.thsch.base.Diagnostics$.<clinit>(Diagnostics.scala)
[error]         ... 1 more

The offending line of code:

Code: [Select]
GL15.glBufferData(GL15.GL_ARRAY_BUFFER, vdata, usage.u)
Java version: 1.8.0_51

edit: happens with 3.0.0a build 59 too

edit: happens with various OpenGL calls

Code: [Select]
[error] Exception in thread "main" java.lang.ExceptionInInitializerError
[error]         at net.fluffy8x.thsch.base.Diagnostics.main(Diagnostics.scala)
[error] Caused by: java.lang.ClassCastException: java.nio.HeapIntBuffer cannot be cast to sun.nio.ch.DirectBuffer
[error]         at org.lwjgl.system.MemoryAccessSun$MemoryAccessorUnsafe.getAddress(MemoryAccessSun.java:82)
[error]         at org.lwjgl.system.MemoryUtil.memAddress0(MemoryUtil.java:115)
[error]         at org.lwjgl.system.MemoryUtil.memAddress(MemoryUtil.java:177)
[error]         at org.lwjgl.system.MemoryUtil.memAddress(MemoryUtil.java:174)
[error]         at org.lwjgl.system.MemoryUtil.memAddressSafe(MemoryUtil.java:224)
[error]         at org.lwjgl.opengl.GL11.glTexImage2D(GL11.java:10283)
[error]         at net.fluffy8x.thsch.resource.SCHTexture.glSet(SCHTexture.scala:27)
[error]         at net.fluffy8x.thsch.entity.Primitive._render(Primitive.scala:137)
[error]         at net.fluffy8x.thsch.entity.Renderable$class.render(Renderable.scala:18)
[error]         at net.fluffy8x.thsch.entity.Primitive.render(Primitive.scala:15)
[error]         at net.fluffy8x.thsch.entity.EntityManager$$anonfun$renderAll$2$$anonfun$apply$1.apply(EntityManager.scala:34)
[error]         at net.fluffy8x.thsch.entity.EntityManager$$anonfun$renderAll$2$$anonfun$apply$1.apply(EntityManager.scala:33)
[error]         at scala.collection.mutable.HashSet.foreach(HashSet.scala:78)
[error]         at net.fluffy8x.thsch.entity.EntityManager$$anonfun$renderAll$2.apply(EntityManager.scala:33)
[error]         at net.fluffy8x.thsch.entity.EntityManager$$anonfun$renderAll$2.apply(EntityManager.scala:32)
[error]         at scala.collection.TraversableLike$WithFilter$$anonfun$foreach$1.apply(TraversableLike.scala:778)
[error]         at scala.collection.immutable.RedBlackTree$._foreach(RedBlackTree.scala:101)
[error]         at scala.collection.immutable.RedBlackTree$.foreach(RedBlackTree.scala:97)
[error]         at scala.collection.immutable.TreeMap.foreach(TreeMap.scala:203)
[error]         at scala.collection.TraversableLike$WithFilter.foreach(TraversableLike.scala:777)
[error]         at net.fluffy8x.thsch.entity.EntityManager.renderAll(EntityManager.scala:32)
[error]         at net.fluffy8x.thsch.base.Diagnostics$.work(Diagnostics.scala:45)
[error]         at net.fluffy8x.thsch.lwjgl.LWJGLApplication$class.loop(LWJGLApplication.scala:72)
[error]         at net.fluffy8x.thsch.lwjgl.LWJGLApplication$class.$init$(LWJGLApplication.scala:80)
[error]         at net.fluffy8x.thsch.base.Diagnostics$.<init>(Diagnostics.scala:8)
[error]         at net.fluffy8x.thsch.base.Diagnostics$.<clinit>(Diagnostics.scala)
[error]         ... 1 more

Edit: apparently 3.0.0b build 19 doesn't have this bug.
« Last Edit: August 23, 2015, 15:30:00 by bb94 »

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
This is not a bug. LWJGL does not work with heap buffers, only direct (off-heap). See the BufferUtils javadoc for details.

This is not a bug. LWJGL does not work with heap buffers, only direct (off-heap). See the BufferUtils javadoc for details.

Then if it does manage to work with heap buffers, is that a bug?

*

Offline spasi

  • *****
  • 2261
    • WebHotelier
Good point. Build #19 uses a different implementation that reads the address field directly. This is a problem because the field is in java.nio.Buffer and exists for on-heap buffers too. I have reverted the code now, build #20 will reject on-heap buffers. Thanks!