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
This commit is contained in:
parent
b9c3f1f74c
commit
c57169835a
@ -1227,7 +1227,7 @@ mixin SchedulerBinding on BindingBase {
|
|||||||
try {
|
try {
|
||||||
// PERSISTENT FRAME CALLBACKS
|
// PERSISTENT FRAME CALLBACKS
|
||||||
_schedulerPhase = SchedulerPhase.persistentCallbacks;
|
_schedulerPhase = SchedulerPhase.persistentCallbacks;
|
||||||
for (final FrameCallback callback in _persistentCallbacks) {
|
for (final FrameCallback callback in List<FrameCallback>.of(_persistentCallbacks)) {
|
||||||
_invokeFrameCallback(callback, _currentFrameTimeStamp!);
|
_invokeFrameCallback(callback, _currentFrameTimeStamp!);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,4 +28,21 @@ void main() {
|
|||||||
);
|
);
|
||||||
timeDilation = 1.0;
|
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);
|
||||||
|
});
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user