File tree 2 files changed +24
-5
lines changed
io/flutter/embedding/engine/renderer
test/io/flutter/embedding/engine/renderer
2 files changed +24
-5
lines changed Original file line number Diff line number Diff line change @@ -131,11 +131,11 @@ final class SurfaceTextureRegistryEntry implements TextureRegistry.SurfaceTextur
131
131
new SurfaceTexture .OnFrameAvailableListener () {
132
132
@ Override
133
133
public void onFrameAvailable (@ NonNull SurfaceTexture texture ) {
134
- if (released ) {
135
- // Even though we make sure to unregister the callback before releasing, as of Android
136
- // O
137
- // SurfaceTexture has a data race when accessing the callback, so the callback may
138
- // still be called by a stale reference after released==true and mNativeView==null.
134
+ if (released || ! flutterJNI . isAttached () ) {
135
+ // Even though we make sure to unregister the callback before releasing, as of
136
+ // Android O, SurfaceTexture has a data race when accessing the callback, so the
137
+ // callback may still be called by a stale reference after released==true and
138
+ // mNativeView==null.
139
139
return ;
140
140
}
141
141
markTextureFrameAvailable (id );
Original file line number Diff line number Diff line change @@ -97,4 +97,23 @@ public void itStopsRenderingToSurfaceWhenRequested() {
97
97
// Verify behavior under test.
98
98
verify (fakeFlutterJNI , times (1 )).onSurfaceDestroyed ();
99
99
}
100
+
101
+ @ Test
102
+ public void itStopsSurfaceTextureCallbackWhenDetached () {
103
+ // Setup the test.
104
+ FlutterRenderer flutterRenderer = new FlutterRenderer (fakeFlutterJNI );
105
+
106
+ fakeFlutterJNI .detachFromNativeAndReleaseResources ();
107
+
108
+ FlutterRenderer .SurfaceTextureRegistryEntry entry =
109
+ (FlutterRenderer .SurfaceTextureRegistryEntry ) flutterRenderer .createSurfaceTexture ();
110
+
111
+ flutterRenderer .startRenderingToSurface (fakeSurface );
112
+
113
+ // Execute the behavior under test.
114
+ flutterRenderer .stopRenderingToSurface ();
115
+
116
+ // Verify behavior under test.
117
+ verify (fakeFlutterJNI , times (0 )).markTextureFrameAvailable (eq (entry .id ()));
118
+ }
100
119
}
You can’t perform that action at this time.
0 commit comments