From b4d3f5fc0d846c3b302e99846610e52955ec826b Mon Sep 17 00:00:00 2001 From: Michael Bien Date: Tue, 22 Feb 2011 02:03:54 +0100 Subject: - ensure slice uses the buffers original byteorder. - create new buffers only if size > capacity not if >= capacity --- src/java/com/jogamp/common/nio/CachedBufferFactory.java | 4 ++-- src/junit/com/jogamp/common/nio/CachedBufferFactoryTest.java | 2 ++ 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/src/java/com/jogamp/common/nio/CachedBufferFactory.java b/src/java/com/jogamp/common/nio/CachedBufferFactory.java index 36bac13..dbeed2d 100644 --- a/src/java/com/jogamp/common/nio/CachedBufferFactory.java +++ b/src/java/com/jogamp/common/nio/CachedBufferFactory.java @@ -168,7 +168,7 @@ public class CachedBufferFactory { public ByteBuffer newDirectByteBuffer(int size) { // if large enough... just create it - if (size >= currentBuffer.capacity()) { + if (size > currentBuffer.capacity()) { checkIfFixed(); return Buffers.newDirectByteBuffer(size); } @@ -180,7 +180,7 @@ public class CachedBufferFactory { } currentBuffer.limit(currentBuffer.position() + size); - ByteBuffer result = currentBuffer.slice(); + ByteBuffer result = currentBuffer.slice().order(currentBuffer.order()); currentBuffer.position(currentBuffer.limit()); currentBuffer.limit(currentBuffer.capacity()); return result; diff --git a/src/junit/com/jogamp/common/nio/CachedBufferFactoryTest.java b/src/junit/com/jogamp/common/nio/CachedBufferFactoryTest.java index 0b10fe8..a00f4c9 100644 --- a/src/junit/com/jogamp/common/nio/CachedBufferFactoryTest.java +++ b/src/junit/com/jogamp/common/nio/CachedBufferFactoryTest.java @@ -28,6 +28,7 @@ package com.jogamp.common.nio; import java.nio.ByteBuffer; +import java.nio.ByteOrder; import java.nio.IntBuffer; import java.util.ArrayList; import java.util.List; @@ -88,6 +89,7 @@ public class CachedBufferFactoryTest { // create for (int i = 0; i < sizes.length; i++) { buffers[i] = factory.newDirectIntBuffer(sizes[i]); + assertEquals(ByteOrder.nativeOrder(), buffers[i].order()); fill(buffers[i], values[i]); } -- cgit v1.2.3