Skip to content

Commit

Permalink
ANDROID: Fix a race condition
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
klusark committed Jan 28, 2014
1 parent 0756893 commit 2d903d9
Showing 1 changed file with 5 additions and 3 deletions.
8 changes: 5 additions & 3 deletions backends/platform/android/org/scummvm/scummvm/ScummVM.java
Expand Up @@ -86,13 +86,15 @@ final public void surfaceChanged(SurfaceHolder holder, int format,
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
Expand Down

0 comments on commit 2d903d9

Please sign in to comment.