Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Added code to stop gl thread #8871

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
@@ -1,15 +1,50 @@
package org.robolectric.shadows;

import android.opengl.GLSurfaceView;
import android.util.Log;
import java.lang.reflect.Field;
import java.lang.reflect.Method;
import org.robolectric.annotation.Implementation;
import org.robolectric.annotation.Implements;

/** Fake implementation of GLSurfaceView */
@Implements(GLSurfaceView.class)
public class ShadowGLSurfaceView extends ShadowSurfaceView {

private static final String TAG = "ShadowGLSurfaceView";

@Implementation
protected void onPause() {}

@Implementation
protected void onResume() {}

@Implementation
protected void onDetachedFromWindow() {
stopGLThread();
}

@Implementation
protected void finalize() throws Throwable {
try {
stopGLThread();
} finally {
super.finalize();
}
}

private void stopGLThread() {
try {
Field glThreadField = GLSurfaceView.class.getDeclaredField("mGLThread");
utzcoz marked this conversation as resolved.
Show resolved Hide resolved
glThreadField.setAccessible(true);
Thread glThread = (Thread) glThreadField.get(realView);
if (glThread != null) {
Method requestExitAndWait = glThread.getClass().getMethod("requestExitAndWait");
requestExitAndWait.invoke(glThread);
}
} catch (Exception e) {
Log.e(TAG, "Exception occurred while stopping GLThread: " + e.getMessage());
e.printStackTrace();
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You can add e to Log.e, and remove e.printStackTrace, like:

Log.e(TAG, "....", e);

}
}
}