安卓异常之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:


      

 

Jimmy Jam  
查看个人资料   翻译成中文(简体)
 更多选项 7月27日, 上午4时19分

 

I ended up using the syntax specified by RyanMcNally, using
"ByteOrder.nativeOrder()" instead of ByteBuffer.nativeOrder()

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.

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值