- android - 多次调用 OnPrimaryClipChangedListener
- android - 无法更新 RecyclerView 中的 TextView 字段
- android.database.CursorIndexOutOfBoundsException : Index 0 requested, 光标大小为 0
- android - 使用 AppCompat 时,我们是否需要明确指定其 UI 组件(Spinner、EditText)颜色
我正在尝试学习适用于 Android 的 OpenGL ES 1.0。我的应用程序运行良好,直到今天早上我将设备升级到 Android 5.0.1 Lollipop。我最初尝试调试这个问题很快就发现我的应用程序仍然可以在运行 KitKat 的模拟器上运行,但在 Lollipop 上崩溃,无论是在我的设备上还是在模拟器上。
我的应用程序使用 OpenGL 绘制一个简单的立方体,每一面都有不同的纹理。我已经对其进行了故障排除,直到它在 glDrawElements() 行崩溃的地方。
package com.briansworld.gravitycubestep7;
import java.nio.ByteBuffer;
import java.nio.ByteOrder;
import java.nio.FloatBuffer;
import javax.microedition.khronos.opengles.GL10;
// draw a cube
// store the cube's position within the multicube
// bind the textures here
class Cube
{
private FloatBuffer mVertexBuffer;
private FloatBuffer myTexBuffer;
private ByteBuffer myIndexBuffer;
public int x, y, z; // used to keep track of which cube is which, not cube position
// constructor
public Cube(int x, int y, int z) // need to add texture ID's
{
this.x = x;
this.y = y;
this.z = z;
float vertices[] =
{
-1.0f, -1.0f, 1.0f, // front
1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f,
1.0f, -1.0f, 1.0f, // right
1.0f, -1.0f, -1.0f,
1.0f, 1.0f, 1.0f,
1.0f, 1.0f, -1.0f,
1.0f, -1.0f, -1.0f, // rear
-1.0f, -1.0f, -1.0f,
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, -1.0f, -1.0f, // left
-1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
-1.0f, -1.0f, -1.0f, // bottom
1.0f, -1.0f, -1.0f,
-1.0f, -1.0f, 1.0f,
1.0f, -1.0f, 1.0f,
-1.0f, 1.0f, -1.0f, // top
1.0f, 1.0f, -1.0f,
-1.0f, 1.0f, 1.0f,
1.0f, 1.0f, 1.0f
};
float texBuffer[] =
{
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f,
0.0f, 1.0f,
1.0f, 1.0f,
0.0f, 0.0f,
1.0f, 0.0f
};
byte indexBuffer[] =
{
0, 1, 3, 0, 3, 2,
4, 5, 7, 4, 7, 6,
8, 9, 11, 8, 11, 10,
12, 13, 15, 12, 15, 14,
16, 17, 19, 16, 19, 18,
20, 21, 23, 20, 23, 22
};
ByteBuffer byteBuf = ByteBuffer.allocateDirect(vertices.length * 4);
byteBuf.order(ByteOrder.nativeOrder());
mVertexBuffer = byteBuf.asFloatBuffer();
mVertexBuffer.put(vertices);
mVertexBuffer.position(0);
byteBuf = ByteBuffer.allocateDirect(texBuffer.length * 4);
byteBuf.order(ByteOrder.nativeOrder());
myTexBuffer = byteBuf.asFloatBuffer();
myTexBuffer.put(texBuffer);
myTexBuffer.position(0);
myIndexBuffer = ByteBuffer.allocate(indexBuffer.length);
myIndexBuffer.put(indexBuffer);
myIndexBuffer.position(0);
}
// need to add functionality to only draw viewable/outside textures
public void draw(GL10 gl, int[] texture)
{
// enable vertex and texture states
gl.glEnableClientState(GL10.GL_VERTEX_ARRAY);
gl.glEnableClientState(GL10.GL_TEXTURE_COORD_ARRAY);
// set the font face rotation
gl.glFrontFace(GL10.GL_CW);
// set the pointers to the buffers
gl.glVertexPointer(3, GL10.GL_FLOAT, 0, mVertexBuffer);
gl.glTexCoordPointer(2, GL10.GL_FLOAT, 0, myTexBuffer);
// step each face of the cube and attach a different texture to each side
for (int i = 0; i < 6; i++)
{
gl.glBindTexture(GL10.GL_TEXTURE_2D, texture[i]); // bind the textures
myIndexBuffer.position(6 * i); // step through the buffer
gl.glDrawElements(GL10.GL_TRIANGLES, 6, GL10.GL_UNSIGNED_BYTE, myIndexBuffer);
}
gl.glDisableClientState(GL10.GL_VERTEX_ARRAY);
gl.glDisableClientState(GL10.GL_COLOR_ARRAY);
}
}
目录中错误消息的前几行是:
JNI 在应用程序中检测到错误:无效元素指针 0x12ce4382,数组元素为 0x12ce437c
in call to ReleaseArrayElements
from void com.google.android.gles_jni.GLImpl.glDrawElements(int, int, int, java.nio.Buffer)
“GLThread 147”prio=5 tid=12 可运行
| group="main"sCount=0 dsCount=0 obj=0x12c72430 self=0xae286400
| sysTid=2100 Nice=0 cgrp=default sched=0/0 句柄=0xb4559f00
|状态=R schedstat=( 0 0 0 ) utm=1 stm=16 core=0 HZ=100
|堆栈=0xa6832000-0xa6834000堆栈大小=1036KB
| held mutexes=“mutator lock”(共享持有)
它通过了 for 循环的第一次迭代,OK。应用程序在第二遍时在 glDrawElements 行崩溃。为什么这在 KitKat Android 4.4 上可以正常工作,而在 Lollipop、Android 5.0 上却崩溃?我需要做哪些不同的事情才能让我的代码与 Lollipop 一起使用?
最佳答案
使用allocateDirect
分配索引缓冲区:
myIndexBuffer = ByteBuffer.allocateDirect(indexBuffer.length);
传递给 OpenGLES 的所有缓冲区都应该是直接缓冲区。我不知道为什么它会在 Kit Kat 上起作用,也许某些东西在幕后得到了优化,现在它产生了影响。
关于java - glDrawElements() 会导致 Lollipop 崩溃,但在 KitKat 上正常,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30472118/
我使用工具栏是为了在我的应用程序中进行 Material 设计。一切正常,但除了更改菜单项文本颜色时,我完全无法接受该解决方案。我还张贴了我在申请中使用的文本和代码的屏幕截图,供您引用。我尝试了几种替
看起来 FloatingActionButton 在 Android 4.0 和 Lollipop 上无法正常工作。正如您在下图中看到的那样,在 Android Lollipo 上,阴影缺失,而在 A
SDK 升级到 Android 5 后,我无法使用 Intel 硬件加速执行管理器: $ android-sdk-macosx/tools/emulator -avd AVD_for_LowMemor
SDK升级到Android 5后,无法使用Intel Hardware Accelerated Execution Manager: $ android-sdk-macosx/tools/emulat
我有不同 draw9patch png 作为背景的按钮。目前按钮由 selector 控制,看起来像这样: 对于 Android Lollipop,他们有一个用于触摸效果的
我尝试在 Pre-Lollipop 设备上运行我的应用程序。但是这段代码向我显示了 Pre-Lolliop 和 Lollipop 设备的相同错误。 如果我将“android:”添加到样式中(如样式 2
我实现了一个自定义的 SurfaceView 来绘制相机预览,并在其上完成了所有捕获和手动对焦操作。它在 Pre-Lolipop 设备上运行良好,但问题是它在 Lollipop 设备上崩溃。 发生的最
风格 @color/my_primary_color @color/my_primary_dark_color @color/accent 布局
我想在 Lollipop 设备中显示较旧的时间选择器(如 Lollipop 设备之前的时间选择器)。可以 这是可能的。 最佳答案 您可以通过将 timePickerMode 属性设置为“spinner
嗨,所以我有点困惑,想知道是否有人能指出我正确的方向。 在 Lollipop 和 pre-lollipop 上使用 Google Play 商店 您会在 Lollipop 上看到可选择的 View 具
如果我们希望使用 Material Design 的应用同时支持 Lollipop 和 Lollipop 之前的设备,以下哪种方法是正确的? 单独使用 Android 支持库:仅对整个应用程序使用支持
我正在使用 appcompat/support-v7 中引入的新工具栏小部件。我想根据用户是否向上/向下滚动页面来隐藏/显示工具栏,就像在新的 Google Playstore 应用程序或 NewsS
我的数据库中有一个 .mhtml 文件作为字节数组。我写了下面的代码,它在 Lollipop 之前的设备上运行良好。但它不适用于 Lollipop 和棉花糖。 代码:- String p
根据标题,我能够在下面的 Lollipop 中成功读取/写入数据,但在 Lollipop 中多次读取/写入失败。 这就是我读/写数据的方式: boolean isRead= getmBluetooth
我刚刚在 Android Studio 上安装了 Android 5,并在模拟器上进行了第一次运行。我发现“API Demos”应用程序非常有趣,我想找到代码。我说的是这个应用程序: 有人知道我在哪里
我正在关注 this tutorial在 Android Material Design 中使用颜色(我的 ActionBar 和 StatusBar)。我确实按照教程进行操作,但没有反射(refle
在我的应用程序中,用户可以通过它调用任何号码,我正在启动蓝牙 audioManager.setBluetoothScoOn(true); audioManager.startBluetoothSco(
我正在我的 android 应用程序中实现 Google map API v2。该应用程序在所有设备上都可以正常工作,但在 Lollipop 设备上却不行。应用程序在 Lollipop 中崩溃。我确实
我正在开发一个项目,其中有一个日期选择器。我正在尝试为其设置最大日期和最短日期。最短日期是今天之后 1 天,最大日期是今天之后 11 天。但问题是在 Lollipop 设备中,最后一个最大日期显示为可
我正在使用嵌入式无线系统,它以定义的时间间隔生成数据包。目的是检测设备/系统何时重新启动。为此,我读到 Lollipop 序列编号是最适合此目的的编号方案。 “在此编号方案中,序列号从负值开始,增加直
我是一名优秀的程序员,十分优秀!