Android: Fix rotating EmulationActivity after boot fails

Time for yet another new iteration of working around the
"surface destruction during boot" problem...
This time, the strategy is to use a mutex in MainAndroid.cpp.
This commit is contained in:
JosJuice
2020-11-06 21:22:22 +01:00
parent d06830b274
commit ee52f465b1
7 changed files with 54 additions and 61 deletions

View File

@ -403,15 +403,13 @@ public final class NativeLibrary
*/
public static native void StopEmulation();
public static native boolean IsBooting();
public static native void WaitUntilDoneBooting();
/**
* Returns true if emulation is running (or is paused).
*/
public static native boolean IsRunning();
public static native boolean IsRunningAndStarted();
/**
* Enables or disables CPU block profiling
*
@ -487,7 +485,7 @@ public final class NativeLibrary
private static native String GetCurrentTitleDescriptionUnchecked();
public static boolean displayAlertMsg(final String caption, final String text,
final boolean yesNo, final boolean isWarning)
final boolean yesNo, final boolean isWarning, final boolean nonBlocking)
{
Log.error("[NativeLibrary] Alert: " + text);
final EmulationActivity emulationActivity = sEmulationActivity.get();
@ -498,10 +496,9 @@ public final class NativeLibrary
}
else
{
// AlertMessages while the core is booting will deadlock if WaitUntilDoneBooting is called.
// We also can't use AlertMessages unless we have a non-null activity reference.
// As a fallback, we use toasts instead.
if (emulationActivity == null || IsBooting())
// We can't use AlertMessages unless we have a non-null activity reference
// and are allowed to block. As a fallback, we can use toasts.
if (emulationActivity == null || nonBlocking)
{
new Handler(Looper.getMainLooper()).post(
() -> Toast.makeText(DolphinApplication.getAppContext(), text, Toast.LENGTH_LONG)

View File

@ -330,16 +330,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
mSurface = null;
Log.debug("[EmulationFragment] Surface destroyed.");
if (state != State.STOPPED && !NativeLibrary.IsShowingAlertMessage())
{
// In order to avoid dereferencing nullptr, we must not destroy the surface while booting
// the core, so wait here if necessary. An easy (but not 100% consistent) way to reach
// this method while the core is booting is by having landscape orientation lock enabled
// and starting emulation while the phone is in portrait mode, leading to the activity
// being recreated very soon after NativeLibrary.Run has been called.
NativeLibrary.WaitUntilDoneBooting();
}
NativeLibrary.SurfaceDestroyed();
}
}

View File

@ -148,7 +148,7 @@ public final class InputOverlay extends SurfaceView implements OnTouchListener
public void initTouchPointer()
{
// Check if we have all the data we need yet
boolean aspectRatioAvailable = NativeLibrary.IsRunning() && !NativeLibrary.IsBooting();
boolean aspectRatioAvailable = NativeLibrary.IsRunningAndStarted();
if (!aspectRatioAvailable || mSurfacePosition == null)
return;