我正在尝试使用多个活动,每个活动都有一个GLSurfaceView。每个GLSurfaceView都使用一个调用C ++渲染器的渲染器。
当我开始第一个活动时以及当我移动到第二个活动时,系统按预期工作。但是,如果我然后尝试返回第一个活动,我会从第二个活动的GL线程中获取来自libc的SEGFAULT。即使虚拟渲染器不执行任何操作,问题也会出现。我觉得我错过了一些重要的事情......
渲染
public class GL2JNIRenderer implements GLSurfaceView.Renderer {
public void onDrawFrame(GL10 gl) {
return;
}
public void onSurfaceChanged(GL10 gl, int width, int height) {
return;
}
public void onSurfaceCreated(GL10 gl, EGLConfig config) {
return;
}
}
GLSurfaceView
public class BasicJNIGLView extends GLSurfaceView {
public BasicJNIGLView(Context context) {
super(context);
setEGLContextClientVersion(2);
}
public BasicJNIGLView(Context context, AttributeSet attribs) {
super(context, attribs);
setEGLContextClientVersion(2);
}
@Override
public void onPause(){
super.onPause();
}
@Override
public void onResume(){
super.onResume();
}
private Context context_;
}
我可以通过使用单个活动(从中删除各种无关的细节)来重现这一点,从而启动自身的副本:
活动
public class MainActivity extends Activity {
...
private BasicJNIGLView glSurface_;
private GL2JNIRenderer myRenderer_;
@Override
protected void onStart() {
super.onStart();
}
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
// Load the layout from the XML file.
setContentView(R.layout.activity_main);
// Hide the layout until the map is initialized (if we show it right away
// the loading/initialization of the map does not look pretty). The
// layout will be made visible again in the InitializeLocationTracker
// function.
findViewById(android.R.id.content).setVisibility(View.GONE);
// Set the custom renderer.
glSurface_ = (BasicJNIGLView) findViewById(R.id.basicJNIGLView1);
myRenderer_ = new GL2JNIRenderer();
glSurface_.setRenderer(myRenderer_);
}
@Override public void onResume() {
super.onResume();
glSurface_.onResume();
findViewById(android.R.id.content).setVisibility(View.VISIBLE);
}
@Override
public void onStop() {
super.onStop();
}
@Override
public void onDestroy() {
super.onDestroy();
}
@Override
public void onPause() {
glSurface_.onPause();
super.onPause();
}
public void onButton(View view) {
Intent intent = new Intent(this, MainActivity.class);
startActivity(intent);
}
}
跟随LogCat的Backtrace。线程20885是第二个活动的openGL线程。
01-29 18:00:47.841: A/libc(20857): Fatal signal 11 (SIGSEGV) at 0x00000000 (code=1), thread 20885 (Thread-222)
01-29 18:00:47.931: I/DEBUG(17463): *** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
01-29 18:00:47.931: I/DEBUG(17463): Build fingerprint: 'generic/google_sdk/generic:4.4/KRT16L/892118:eng/test-keys'
01-29 18:00:47.931: I/DEBUG(17463): Revision: '0'
01-29 18:00:47.951: I/DEBUG(17463): pid: 20857, tid: 20885, name: Thread-222 >>> com.gamma.trafficrouting <<<
01-29 18:00:47.951: I/DEBUG(17463): signal 11 (SIGSEGV), code 1 (SEGV_MAPERR), fault addr 00000000
01-29 18:00:48.241: I/DEBUG(17463): r0 b77c6d38 r1 00000000 r2 00000000 r3 00000000
01-29 18:00:48.241: I/DEBUG(17463): r4 00000000 r5 b6f6d190 r6 00000000 r7 00000000
01-29 18:00:48.251: I/DEBUG(17463): r8 b77c93c0 r9 00000000 sl 00000000 fp 00000000
01-29 18:00:48.251: I/DEBUG(17463): ip 00000000 sp a9eb4d10 lr aef68737 pc 00000000 cpsr a0000010
01-29 18:00:48.251: I/DEBUG(17463): d0 0000008543052000 d1 3ff0000043052000
01-29 18:00:48.251: I/DEBUG(17463): d2 4301000000000000 d3 4301000000000000
01-29 18:00:48.251: I/DEBUG(17463): d4 4481e000448b2000 d5 0000012b3f800000
01-29 18:00:48.251: I/DEBUG(17463): d6 42d8000043958000 d7 3f8000003f800000
01-29 18:00:48.251: I/DEBUG(17463): d8 0000000000000000 d9 0000000000000000
01-29 18:00:48.251: I/DEBUG(17463): d10 0000000000000000 d11 0000000000000000
01-29 18:00:48.251: I/DEBUG(17463): d12 0000000000000000 d13 0000000000000000
01-29 18:00:48.251: I/DEBUG(17463): d14 0000000000000000 d15 0000000000000000
01-29 18:00:48.251: I/DEBUG(17463): scr 60000010
01-29 18:00:48.261: I/DEBUG(17463): backtrace:
01-29 18:00:48.261: I/DEBUG(17463): #00 pc 00000000 <unknown>
01-29 18:00:48.261: I/DEBUG(17463): #01 pc 00007735 /system/lib/egl/libEGL_emulation.so
01-29 18:00:48.261: I/DEBUG(17463): #02 pc 0000f059 /system/lib/libEGL.so (eglReleaseThread+44)
01-29 18:00:48.261: I/DEBUG(17463): #03 pc 0000d538 /system/lib/libc.so
01-29 18:00:48.261: I/DEBUG(17463): #04 pc 0000ec78 /system/lib/libc.so (pthread_exit+80)
01-29 18:00:48.261: I/DEBUG(17463): #05 pc 0000d1f8 /system/lib/libc.so (pthread_create+240)
01-29 18:00:48.271: I/DEBUG(17463): stack:
01-29 18:00:48.271: I/DEBUG(17463): a9eb4cd0 00000000
01-29 18:00:48.271: I/DEBUG(17463): a9eb4cd4 a9eb4d44 [stack:20885]
01-29 18:00:48.271: I/DEBUG(17463): a9eb4cd8 00000000
01-29 18:00:48.271: I/DEBUG(17463): a9eb4cdc b5b0a323 /system/lib/libdvm.so (dvmCallMethodV(Thread*, Method const*, Object*, bool, JValue*, std::__va_list)+346)
01-29 18:00:48.271: I/DEBUG(17463): a9eb4ce0 b6ee0df0 /system/lib/libbinder.so
01-29 18:00:48.271: I/DEBUG(17463): a9eb4ce4 b779cc88 [heap]
01-29 18:00:48.271: I/DEBUG(17463): a9eb4ce8 00000000
01-29 18:00:48.271: I/DEBUG(17463): a9eb4cec ae79afc3 /system/lib/libOpenglSystemCommon.so (HostConnection::get()+6)
01-29 18:00:48.271: I/DEBUG(17463): a9eb4cf0 b77c93c0 [heap]
01-29 18:00:48.271: I/DEBUG(17463): a9eb4cf4 00000000
01-29 18:00:48.271: I/DEBUG(17463): a9eb4cf8 00000000
01-29 18:00:48.271: I/DEBUG(17463): a9eb4cfc 00000000
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d00 00000000
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d04 00000000
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d08 b6f6d190
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d0c aef68715 /system/lib/egl/libEGL_emulation.so
01-29 18:00:48.271: I/DEBUG(17463): #00 a9eb4d10 b6f6b510 /system/lib/libc.so
01-29 18:00:48.271: I/DEBUG(17463): ........ ........
01-29 18:00:48.271: I/DEBUG(17463): #01 a9eb4d10 b6f6b510 /system/lib/libc.so
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d14 b6f3111f /system/lib/libc.so (dlfree+50)
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d18 b6f69000 /system/lib/libc.so
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d1c b779cc88 [heap]
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d20 b779cc88 [heap]
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d24 00000000
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d28 b6ed33b1 /system/lib/libbinder.so (android::IPCThreadState::threadDestructor(void*))
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d2c b6f2dafd /system/lib/libc.so (free+12)
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d30 b779cc50 [heap]
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d34 b6f6b320 /system/lib/libc.so
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d38 b6ed33b1 /system/lib/libbinder.so (android::IPCThreadState::threadDestructor(void*))
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d3c b6d13de8 /system/lib/libEGL.so
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d40 b6f6b328 /system/lib/libc.so
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d44 b6cd702d /system/lib/libEGL.so (eglReleaseThread)
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d48 b77c8928 [heap]
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d4c b6f6b510 /system/lib/libc.so
01-29 18:00:48.271: I/DEBUG(17463): ........ ........
01-29 18:00:48.271: I/DEBUG(17463): #02 a9eb4d60 00000019
01-29 18:00:48.271: I/DEBUG(17463): a9eb4d64 b6f2d53c /system/lib/libc.so