summaryrefslogtreecommitdiff
path: root/Source/Android/app/src/main/java
diff options
context:
space:
mode:
authorConnor McLaughlin <stenzek@gmail.com>2019-11-08 10:45:21 +1000
committerGitHub <noreply@github.com>2019-11-08 10:45:21 +1000
commit18ba1fd723f20ac29ac7dce8686382169fc50ccb (patch)
tree1575dd58ef30a7901189f8eee65135829d1083fd /Source/Android/app/src/main/java
parent28bf88641f3f3b11bcf0a819894acd89a88fa9c9 (diff)
parentc007dd1852896efe1671ade96fa50080a030a51b (diff)
Merge pull request #8452 from JosJuice/android-emulationactivity-rotation-crash
Android: Replace emulation rotation crash workaround with proper fix
Diffstat (limited to 'Source/Android/app/src/main/java')
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java2
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java15
-rw-r--r--Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java22
3 files changed, 16 insertions, 23 deletions
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java
index dc3c48c338..0595100e09 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/NativeLibrary.java
@@ -400,6 +400,8 @@ public final class NativeLibrary
*/
public static native void StopEmulation();
+ public static native void WaitUntilDoneBooting();
+
/**
* Returns true if emulation is running (or is paused).
*/
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
index 518a7bc38c..ad97625af0 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/activities/EmulationActivity.java
@@ -235,10 +235,6 @@ public final class EmulationActivity extends AppCompatActivity
{
super.onCreate(savedInstanceState);
- // Find the EmulationFragment
- mEmulationFragment = (EmulationFragment) getSupportFragmentManager()
- .findFragmentById(R.id.frame_emulation_fragment);
-
if (savedInstanceState == null)
{
// Get params we were passed
@@ -251,9 +247,7 @@ public final class EmulationActivity extends AppCompatActivity
}
else
{
- // Could have recreated the activity(rotate) before creating the fragment. If the fragment
- // doesn't exist, treat this as a new start.
- activityRecreated = mEmulationFragment != null;
+ activityRecreated = true;
restoreState(savedInstanceState);
}
@@ -311,9 +305,10 @@ public final class EmulationActivity extends AppCompatActivity
setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_SENSOR_LANDSCAPE);
}
- if (!(mDeviceHasTouchScreen && lockLandscape &&
- getResources().getConfiguration().orientation == Configuration.ORIENTATION_PORTRAIT) &&
- mEmulationFragment == null)
+ // Find or create the EmulationFragment
+ mEmulationFragment = (EmulationFragment) getSupportFragmentManager()
+ .findFragmentById(R.id.frame_emulation_fragment);
+ if (mEmulationFragment == null)
{
mEmulationFragment = EmulationFragment.newInstance(mPaths);
getSupportFragmentManager().beginTransaction()
diff --git a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java
index 1ff9ba8ea0..64959601bb 100644
--- a/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java
+++ b/Source/Android/app/src/main/java/org/dolphinemu/dolphinemu/fragments/EmulationFragment.java
@@ -316,8 +316,6 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
state = State.PAUSED;
Log.debug("[EmulationFragment] Pausing emulation.");
- // Release the surface before pausing, since emulation has to be running for that.
- NativeLibrary.SurfaceDestroyed();
NativeLibrary.PauseEmulation();
}
else
@@ -381,19 +379,17 @@ public final class EmulationFragment extends Fragment implements SurfaceHolder.C
mSurface = null;
Log.debug("[EmulationFragment] Surface destroyed.");
- if (state == State.RUNNING)
+ if (state != State.STOPPED)
{
- NativeLibrary.SurfaceDestroyed();
- state = State.PAUSED;
- }
- else if (state == State.PAUSED)
- {
- Log.warning("[EmulationFragment] Surface cleared while emulation paused.");
- }
- else
- {
- Log.warning("[EmulationFragment] Surface cleared while emulation stopped.");
+ // 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();
}
}