Login  Register

Re: Buffers.newDirectIntBuffer(int[]) does not set limit

Posted by Xerxes Rånby on Jul 24, 2015; 3:02pm
URL: https://forum.jogamp.org/Buffers-newDirectIntBuffer-int-does-not-set-limit-tp4034959p4034963.html

jmaasing wrote
OMG I'm sorry I left out a piece of code that I use. The 'working' case is this:

final IntBuffer indexBuf = Buffers.newDirectIntBuffer(triIndexes.length);
for (int triIndex : triIndexes) {
	indexBuf.put(triIndex) ;
}
indexBuf.flip();

The flip() part is the essential thing and I think more appropriate than clear() in the Buffers class.

Sorry I do not have a build setup for gluegen where I can test the patch :-/
It would be good to understand the root cause why the crash can happen when lim do not match capacity.
The only reason i can think of that generates a crash is that the JVM garbage collector has decide to reclaim the memory that have been passed to the GPU.