Eclipse 内で Android プロジェクト用の頂点クラスを作成していますが、コンストラクター内でランタイム バグが発生しています。これがコンストラクタです...
public Vertices(GLGraphics glGraphics, int maxVertices, int maxIndices, boolean hasColor, boolean hasTexCoords)
{
this.glGraphics = glGraphics;
this.hasColor = hasColor;
this.hasTexCoords = hasTexCoords;
this.vertexSize = (2 + (hasColor?4:0) + (hasTexCoords?2:0)) * 4;
ByteBuffer buffer = ByteBuffer.allocateDirect(maxVertices * vertexSize);
buffer.order(ByteOrder.nativeOrder());
vertices = buffer.asFloatBuffer();
if(maxIndices > 0)
{
buffer = ByteBuffer.allocateDirect(maxIndices * Short.SIZE / 8);
buffer.order(ByteOrder.nativeOrder());
indices = buffer.asShortBuffer();
}
else
{
indices = null;
}
}
この声明では:
this.vertexSize = (2 + (hasColor?4:0) + (hasTexCoords?2:0)) * 4;
頂点のサイズをバイト単位で計算しています。問題は、三項演算が評価されるたびに vertexSize が 0 のままになり、プログラムがそのステートメントでコンストラクターから抜け出すことです。三項演算子は、条件が true か false かに応じて値を評価していません。ここで何が起こっているのですか?