2016年4月15日金曜日

nexus9:OpenGL GL_TRIANGLE_STRIP の不可解な動作

 Android アプリを開発中、手持ちの3機種ではそれなり安定して動いていたアプリが、出先で借りた nexus9(6.0.1 MMB29V) では動かなかった(「問題が発生したため、~を終了します。」)
 
 ご厚意で nexus9 をお借りし、自宅で調べてみると、見たことのないメッセージを出して止まっていた。
 
> 04-15 15:20:42.739 11046-11534/sample.ble.sensortag D/NvOsDebugPrintf: WARNING: Couldn't find glCurrentPaletteMatrixOES in procAddrs table
>04-15 15:20:42.739 11046-11534/sample.ble.sensortag D/NvOsDebugPrintf: WARNING: Couldn't find glLoadPaletteFromModelViewMatrixOES in procAddrs table
>04-15 15:20:42.739 11046-11534/sample.ble.sensortag D/NvOsDebugPrintf: WARNING: Couldn't find glMatrixIndexPointerOES in procAddrs table
>04-15 15:20:42.739 11046-11534/sample.ble.sensortag D/NvOsDebugPrintf: WARNING: Couldn't find glWeightPointerOES in procAddrs table
>04-15 15:20:42.804 11046-11534/sample.ble.sensortag A/libc: Fatal signal 11 (SIGSEGV), code 1, fault addr 0x0 in tid 11534 (GLThread 367)

 ネットで調べてみたが、役に立つ情報が見つからない。ブレークポイント仕込んで調べていくと、OpenGL で直線を引くための class の、直線を引くメソッドで止まっていた。
 
 直線は、三角形を二つ並べることで描いていて、コード的には
 
     (略)
            float squareCoords[] = {
                (float) (xs - (Math.cos(angle) * width / 2)), (float) (ys + (Math.sin(angle) * width / 2)), 0,     // top left

                (float) (xs + (Math.cos(angle) * width / 2)), (float) (ys - (Math.sin(angle) * width / 2)), 0,     // top right

                (float) (xe - (Math.cos(angle) * width / 2)), (float) (ye + (Math.sin(angle) * width / 2)), 0,     // bottom left

                (float) (xe + (Math.cos(angle) * width / 2)), (float) (ye - (Math.sin(angle) * width / 2)), 0     // bottom righ
           };

         short drawOrder[] = {0, 1, 2, 3}; // order to draw vertices
         (略)
         gl.glDrawElements(  // draw shape:
                GL10.GL_TRIANGLE_STRIP,
                mDrawOrder.length, GL10.GL_UNSIGNED_SHORT,
                drawListBuffer);
 
 はたと思うところあって、GL_TRIANGLE_STRIP を GL_TRIANGLES に変更し、drawOrder[] もそれに合わせて {0, 1, 2, 1, 2, 3} に変更したところ、エラーは出なくなった。GL_TRIANGLE_STRIP で、三角形を二つしか書かないのは少なすぎるのだろうか。


 円を描くところでは、glDrawElements() に GL10.GL_TRIANGLE_STRIP を指定して問題なく動いているのだが...。
 
 ともあれ、問題を一つ越えられた ><
 

0 件のコメント:

コメントを投稿