Unverified Commit c5716983 authored by Dan Field's avatar Dan Field Committed by GitHub

Avoid concurrent modification of persistent frame callbacks (#131677)

Fixes https://github.com/flutter/flutter/issues/131415

We should do an audit of all such cases though, filed https://github.com/flutter/flutter/issues/131678
parent b9c3f1f7
......@@ -1227,7 +1227,7 @@ mixin SchedulerBinding on BindingBase {
try {
// PERSISTENT FRAME CALLBACKS
_schedulerPhase = SchedulerPhase.persistentCallbacks;
for (final FrameCallback callback in _persistentCallbacks) {
for (final FrameCallback callback in List<FrameCallback>.of(_persistentCallbacks)) {
_invokeFrameCallback(callback, _currentFrameTimeStamp!);
}
......
......@@ -28,4 +28,21 @@ void main() {
);
timeDilation = 1.0;
});
test('Adding a persistent frame callback during a persistent frame callback', () {
bool calledBack = false;
SchedulerBinding.instance.addPersistentFrameCallback((Duration timeStamp) {
if (!calledBack) {
SchedulerBinding.instance.addPersistentFrameCallback((Duration timeStamp) {
calledBack = true;
});
}
});
SchedulerBinding.instance.handleBeginFrame(null);
SchedulerBinding.instance.handleDrawFrame();
expect(calledBack, false);
SchedulerBinding.instance.handleBeginFrame(null);
SchedulerBinding.instance.handleDrawFrame();
expect(calledBack, true);
});
}
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment