Slice()ing a Buffer doesn't preserve byte ordering

I stumpled upon the problem while porting lwjgl to Buffers instead of pointers. The bug is described here

http://developer.java.sun.com/developer/bugParade/bugs/4715166.html

(the emphasis is on duplicate() but slice is mentioned too)

At first I simply used the workaround mentioned (set the order after each slicing), but the really annoying part comes when you want to slice your Int-Float-Whatever-else-than-ByteBuffers; byte order can’t be changed on those! It forces me to stash the original ByteBuffers and slice those instead, ordering and then converting to the right type. And this is annoying when you just wanted to index into an existing buffer the way you could do address + offset in the pointer-lwjgl days.

  • elias

Yeah, I came across this major fecking annoyance as well. And let me tell you how long it takes to discover why nothing is rendering. GRRRRRRRRRRR. It’s no big deal to remember to call order(ByteOrder.nativeOrder()) on all your sliced/duped buffers of course - until you forget once and it all goes pear shaped.

What price security eh?

Cas :expressionless:

Forgetting is one thing, but how about those Int or FloatBuffers that can’t change byte ordering? What is one to do about those?

  • elias

Well, don’t forget that you only do this slicing business once, at resource initialisation, so fiddly it might be but at least it’s not common. And it’s probably easily wrappable in a class to handle the details for you. It shouldn’t be this way of course but it’s only a minor grumble.

Cas :slight_smile: