소스 검색

Fixed FloatBuffer support as well as other
buffers that are views of other buffers and
follow the same conventions.


git-svn-id: https://jmonkeyengine.googlecode.com/svn/trunk@9127 75d07b2b-3a1a-0410-a2c5-0572b91ccdca

PSp..om 14 년 전
부모
커밋
4edf262021
2개의 변경된 파일19개의 추가작업 그리고 3개의 파일을 삭제
  1. 15 3
      engine/src/core/com/jme3/util/BufferUtils.java
  2. 4 0
      engine/src/test/jme3test/app/TestReleaseDirectMemory.java

+ 15 - 3
engine/src/core/com/jme3/util/BufferUtils.java

@@ -1165,9 +1165,21 @@ public final class BufferUtils {
             Method cleanerMethod = toBeDestroyed.getClass().getMethod("cleaner");
             Method cleanerMethod = toBeDestroyed.getClass().getMethod("cleaner");
             cleanerMethod.setAccessible(true);
             cleanerMethod.setAccessible(true);
             Object cleaner = cleanerMethod.invoke(toBeDestroyed);
             Object cleaner = cleanerMethod.invoke(toBeDestroyed);
-            Method cleanMethod = cleaner.getClass().getMethod("clean");
-            cleanMethod.setAccessible(true);
-            cleanMethod.invoke(cleaner);
+            if (cleaner != null) {
+                Method cleanMethod = cleaner.getClass().getMethod("clean");
+                cleanMethod.setAccessible(true);
+                cleanMethod.invoke(cleaner);
+            } else {
+                // Try the alternate approach of getting the viewed buffer
+                Method viewedBufferMethod = toBeDestroyed.getClass().getMethod("viewedBuffer");
+                viewedBufferMethod.setAccessible(true);
+                Object viewedBuffer = viewedBufferMethod.invoke(toBeDestroyed);
+                if (viewedBuffer != null) {
+                    destroyDirectBuffer( (Buffer)viewedBuffer );
+                } else {
+                    Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "Buffer cannot be destroyed: {0}", toBeDestroyed);
+                }
+            }
         } catch (IllegalAccessException ex) {
         } catch (IllegalAccessException ex) {
             Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "{0}", ex);
             Logger.getLogger(BufferUtils.class.getName()).log(Level.SEVERE, "{0}", ex);
         } catch (IllegalArgumentException ex) {
         } catch (IllegalArgumentException ex) {

+ 4 - 0
engine/src/test/jme3test/app/TestReleaseDirectMemory.java

@@ -39,6 +39,7 @@ import com.jme3.scene.Geometry;
 import com.jme3.scene.shape.Box;
 import com.jme3.scene.shape.Box;
 import com.jme3.util.BufferUtils;
 import com.jme3.util.BufferUtils;
 import java.nio.ByteBuffer;
 import java.nio.ByteBuffer;
+import java.nio.FloatBuffer;
 
 
 public class TestReleaseDirectMemory extends SimpleApplication {
 public class TestReleaseDirectMemory extends SimpleApplication {
 
 
@@ -61,6 +62,9 @@ public class TestReleaseDirectMemory extends SimpleApplication {
     public void simpleUpdate(float tpf) {
     public void simpleUpdate(float tpf) {
         ByteBuffer buf = BufferUtils.createByteBuffer(500000);
         ByteBuffer buf = BufferUtils.createByteBuffer(500000);
         BufferUtils.destroyDirectBuffer(buf);
         BufferUtils.destroyDirectBuffer(buf);
+        
+        FloatBuffer buf2 = BufferUtils.createFloatBuffer(500000);
+        BufferUtils.destroyDirectBuffer(buf2);
     }
     }
     
     
 }
 }