debugger: if controller has been disposed, leave showScriptLocation early (#9884)
diff --git a/packages/devtools_app/lib/src/screens/debugger/codeview_controller.dart b/packages/devtools_app/lib/src/screens/debugger/codeview_controller.dart
index 5336255..befe39d 100644
--- a/packages/devtools_app/lib/src/screens/debugger/codeview_controller.dart
+++ b/packages/devtools_app/lib/src/screens/debugger/codeview_controller.dart
@@ -218,6 +218,9 @@
);
if (succeeded) {
+ // The controller may have been disposed while awaiting the asynchronous
+ // location display setup.
+ if (disposed) return;
// Update the scripts history (and make sure we don't react to the
// subsequent event).
scriptsHistory.current.removeListener(_scriptHistoryListener);
@@ -234,6 +237,8 @@
final isolateRef =
serviceConnection.serviceManager.isolateManager.selectedIsolate.value!;
final processedReport = await _getSourceReport(isolateRef, current.script);
+ // The controller may have been disposed while awaiting the source report.
+ if (disposed) return;
parsedScript.value = ParsedScript(
script: current.script,
@@ -264,6 +269,8 @@
if (scriptRef.id != parsedScript.value?.script.id) {
// Try to parse the script if it isn't the currently parsed script:
final script = await _parseScript(scriptRef);
+ // The controller may have been disposed while awaiting the script parsing.
+ if (disposed) return false;
if (script == null) {
// Return early and indicate failure if parsing fails.
reportError(