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
base: master
Are you sure you want to change the base?
Added code to stop gl thread #8871
Conversation
shadows/framework/src/main/java/org/robolectric/shadows/ShadowGLSurfaceView.java
Outdated
Show resolved
Hide resolved
@Devashishbasu Please check CI jobs and fix failures. |
If you're a new contributor, it's recommended to run related tasks like building, running tests, formatting changes, and etc. It can help reduce extra discussion for simple changes. |
i have tried Another option to terminate the thread in callOnDetachFromWindow...could you please review...build was successful in local |
@Devashishbasu Please squash your commits to one as Robolectric prefers single commit PR for many occasions. |
9c5157b
to
0f1b308
Compare
Done |
Hi @Devashishbasu , Thanks for this PR. I believe the problem is that GLSurfaceView starts a thread when This thread is contained in the GLSurfaceView.mGLThread member. There is currently nothing stopping that thread. This PR creates a new thread member in the shadow and stops that, but that isn't really doing anything to stop the existing thread. I think the first step would be to write a test that captures this issue. This would involve creating a new activity and then adding a GLSurfaceView to it, and then making the activity visible. I believe this would start the |
Got it.. thankyou |
Hi @hoisie , could you please review the test? and in which folder do i need to place the test? import android.app.Activity; import static org.robolectric.Robolectric.buildActivity; @RunWith(AndroidJUnit4.class)
} |
@Devashishbasu You can create a new test file called |
Hi @utzcoz @MGaetan89 ...how can i retrieve the GLThread associated with GLSurfaceView? |
@Devashishbasu I think you can use reflector or common reflection code to retrieve |
Hi, @utzcoz could you please review if the code added by me is correctly terminating the thread or not after the test is finished? |
shadows/framework/src/main/java/org/robolectric/shadows/ShadowGLSurfaceView.java
Outdated
Show resolved
Hide resolved
shadows/framework/src/main/java/org/robolectric/shadows/ShadowGLSurfaceView.java
Show resolved
Hide resolved
shadows/framework/src/main/java/org/robolectric/shadows/ShadowGLSurfaceView.java
Outdated
Show resolved
Hide resolved
shadows/framework/src/main/java/org/robolectric/shadows/ShadowGLSurfaceView.java
Outdated
Show resolved
Hide resolved
shadows/framework/src/main/java/org/robolectric/shadows/ShadowGLSurfaceView.java
Outdated
Show resolved
Hide resolved
shadows/framework/src/main/java/org/robolectric/shadows/ShadowGLSurfaceView.java
Outdated
Show resolved
Hide resolved
@Devashishbasu Please keep your commit history clean always. |
terminate the thread using callOnDetachFromWindow and finalize method present in GLSurafceView
bbedd78
to
11f0d4a
Compare
Hi @utzcoz, done.... is there anything else that I need to do to fix this issue? |
Hi utzcoz, should I add a test class for ShadowGLSurafceView? |
I recommend you adding necessary tests for it. You can refer other tests in |
} | ||
} catch (Exception e) { | ||
Log.e(TAG, "Exception occurred while stopping GLThread: " + e.getMessage()); | ||
e.printStackTrace(); |
There was a problem hiding this comment.
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);
fixes #7194
I added fields to hold the renderer and the GL thread.
In onPause(), I interrupt the GL thread if it's not null.
In onResume(), I start a new GL thread only if the renderer is not null.
I added a setRenderer() method to set the renderer externally.
I introduced a reset() method, annotated with @resetter, which you can use to clean up resources and terminate the GL thread if needed after each test.