Avoid sending message on dead thread

PiperOrigin-RevId: 493040714
This commit is contained in:
kimvde 2022-12-05 18:05:28 +00:00 committed by Ian Baker
parent 656b346e6c
commit 72773a862e

View file

@ -200,6 +200,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
public void cancel() { public void cancel() {
if (released) {
return;
}
internalHandler internalHandler
.obtainMessage( .obtainMessage(
MSG_END, END_REASON_CANCELLED, /* unused */ 0, /* transformationException */ null) MSG_END, END_REASON_CANCELLED, /* unused */ 0, /* transformationException */ null)
@ -333,6 +336,9 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
releaseTransformationException = TransformationException.createForUnexpected(e); releaseTransformationException = TransformationException.createForUnexpected(e);
cancelException = e; cancelException = e;
} }
// Quit thread lazily so that all events that got triggered when releasing the AssetLoader are
// still delivered.
internalHandler.post(internalHandlerThread::quitSafely);
} }
if (!forCancellation) { if (!forCancellation) {
@ -352,7 +358,6 @@ import org.checkerframework.checker.nullness.qual.MonotonicNonNull;
} }
} }
internalHandlerThread.quitSafely();
cancellingConditionVariable.open(); cancellingConditionVariable.open();
} }