Android: Fix race/crash when switching away/back to the emulation activity

This commit is contained in:
Connor McLaughlin
2020-10-27 11:58:46 +10:00
parent 80a377d45a
commit 7ce55ca800
4 changed files with 13 additions and 8 deletions

View File

@ -447,6 +447,11 @@ void AndroidHostInterface::SurfaceChanged(ANativeWindow* surface, int format, in
wi.surface_height = height;
m_display->ChangeRenderWindow(wi);
if (surface && System::GetState() == System::State::Paused)
System::SetState(System::State::Running);
else if (!surface && System::IsRunning())
System::SetState(System::State::Paused);
}
}
@ -523,7 +528,8 @@ void AndroidHostInterface::SetControllerAxisState(u32 index, s32 button_code, fl
false);
}
void AndroidHostInterface::RefreshGameList(bool invalidate_cache, bool invalidate_database, ProgressCallback* progress_callback)
void AndroidHostInterface::RefreshGameList(bool invalidate_cache, bool invalidate_database,
ProgressCallback* progress_callback)
{
m_game_list->SetSearchDirectoriesFromSettings(m_settings_interface);
m_game_list->Refresh(invalidate_cache, invalidate_database, progress_callback);

View File

@ -29,7 +29,6 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
private SharedPreferences mPreferences;
private boolean mWasDestroyed = false;
private boolean mStopRequested = false;
private boolean mWasPausedOnSurfaceLoss = false;
private boolean mApplySettingsOnSurfaceRestored = false;
private String mGameTitle = null;
private EmulationSurfaceView mContentView;
@ -128,10 +127,6 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
AndroidHostInterface.getInstance().surfaceChanged(holder.getSurface(), format, width, height);
updateOrientation();
if (holder.getSurface() != null && !hadSurface && AndroidHostInterface.getInstance().isEmulationThreadPaused() && !mWasPausedOnSurfaceLoss) {
AndroidHostInterface.getInstance().pauseEmulationThread(false);
}
if (mApplySettingsOnSurfaceRestored) {
AndroidHostInterface.getInstance().applySettings();
mApplySettingsOnSurfaceRestored = false;
@ -159,8 +154,6 @@ public class EmulationActivity extends AppCompatActivity implements SurfaceHolde
if (!mStopRequested)
AndroidHostInterface.getInstance().saveResumeState(true);
mWasPausedOnSurfaceLoss = AndroidHostInterface.getInstance().isEmulationThreadPaused();
AndroidHostInterface.getInstance().pauseEmulationThread(true);
AndroidHostInterface.getInstance().surfaceChanged(null, 0, 0, 0);
}