From 2d903d966875bb2bc665cd33d3514fb6b2dcf7f5 Mon Sep 17 00:00:00 2001 From: Joel Teichroeb Date: Mon, 27 Jan 2014 18:29:00 -0800 Subject: ANDROID: Fix a race condition setSurface is done in a different thread than the one that starts the scummvm main. The main thread would then wait until the setSurface thread notifies. The setSurface thread would notify before it actually calls setSurface, meaning if the thread is preemted before calling setSurface, initSurface will assert, causing the app to crash. --- backends/platform/android/org/scummvm/scummvm/ScummVM.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) (limited to 'backends') diff --git a/backends/platform/android/org/scummvm/scummvm/ScummVM.java b/backends/platform/android/org/scummvm/scummvm/ScummVM.java index 3a25b54eeb..5047502e61 100644 --- a/backends/platform/android/org/scummvm/scummvm/ScummVM.java +++ b/backends/platform/android/org/scummvm/scummvm/ScummVM.java @@ -86,13 +86,15 @@ public abstract class ScummVM implements SurfaceHolder.Callback, Runnable { Log.d(LOG_TAG, String.format("surfaceChanged: %dx%d (%d)", width, height, format)); + // store values for the native code + // make sure to do it before notifying the lock + // as it leads to a race condition otherwise + setSurface(width, height); + synchronized(_sem_surface) { _surface_holder = holder; _sem_surface.notifyAll(); } - - // store values for the native code - setSurface(width, height); } // SurfaceHolder callback -- cgit v1.2.3