首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

安卓错误之java.lang.IllegalArgumentException: Must use a native order direct Buffer

2012-07-15 
安卓异常之java.lang.IllegalArgumentException: Must use a native order direct BufferHello thereNon-d

安卓异常之java.lang.IllegalArgumentException: Must use a native order direct Buffer

Hello there

Non-direct buffers exist within the java heap space, and thus may be
shuffled around by the garbage collector to reduce fragmentation.
OpenGL may try and use data from the buffers that you pass in at any
time - if the buffer has been moved since you passed its address to
OpenGL then you'll be reading data from an invalid location.
Direct buffers are allocated outside of the java heap, and thus do not
move around.
For opengl use, always allocate buffers like so

FloatBuffer fb =
ByteBuffer.allocateDirect( size ).order( ByteBuffer.nativeOrder() ).asFloatBuffer();

Also be aware of the performance issue in
http://code.google.com/p/android/issues/detail?id=11078

Ryan

On Jan 6, 5:13?am, kong <zfr...@gmail.com> wrote:

e.g.
?sphereVertex =
? ? ? ? ? ? ByteBuffer.allocateDirect( 400000 ).order(
ByteOrder.nativeOrder() ).asFloatBuffer();

This was after I found a workable syntax elsewhere with the statements
broken out like this (sphereVertex was previously defined as a FloatBuffer):

? ? ? ? ByteBuffer vbb = ByteBuffer.allocateDirect(400000);
? ? ? ? vbb.order(ByteOrder.nativeOrder());
? ? ? ? sphereVertex = vbb.asFloatBuffer();

When that worked I took a closer look at the condensed syntax and made the
one change to ByteOrder and that worked too.

热点排行