Controller input is now blocked during ROM directory rescans to avoid crashes

This commit is contained in:
Leon Styhre 2023-09-20 20:46:51 +02:00
parent 7467e8a7f9
commit ca45ea6d08
4 changed files with 14 additions and 8 deletions

View file

@ -47,7 +47,6 @@ ViewController::ViewController() noexcept
, mWrappedViews {false} , mWrappedViews {false}
, mFadeOpacity {0} , mFadeOpacity {0}
, mCancelledTransition {false} , mCancelledTransition {false}
, mLockInput {false}
, mNextSystem {false} , mNextSystem {false}
{ {
mState.viewing = ViewMode::NOTHING; mState.viewing = ViewMode::NOTHING;
@ -920,7 +919,8 @@ void ViewController::launch(FileData* game)
onFileChanged(game, true); onFileChanged(game, true);
// This is a workaround so that any keys or button presses used for exiting the emulator // This is a workaround so that any keys or button presses used for exiting the emulator
// are not captured upon returning. // are not captured upon returning.
setAnimation(new LambdaAnimation([](float t) {}, 1), 0, [this] { mLockInput = false; }); setAnimation(new LambdaAnimation([](float t) {}, 1), 0,
[this] { mWindow->setBlockInput(false); });
}); });
} }
@ -1069,9 +1069,6 @@ std::shared_ptr<SystemView> ViewController::getSystemListView()
bool ViewController::input(InputConfig* config, Input input) bool ViewController::input(InputConfig* config, Input input)
{ {
if (mLockInput)
return true;
// If using the %RUNINBACKGROUND% variable in a launch command or if enabling the // If using the %RUNINBACKGROUND% variable in a launch command or if enabling the
// RunInBackground setting, ES-DE will run in the background while a game is launched. // RunInBackground setting, ES-DE will run in the background while a game is launched.
// If we're in this state and then register some input, it means that the user is back in ES-DE. // If we're in this state and then register some input, it means that the user is back in ES-DE.
@ -1411,6 +1408,8 @@ void ViewController::reloadAll()
void ViewController::rescanROMDirectory() void ViewController::rescanROMDirectory()
{ {
mWindow->setBlockInput(true);
mGamelistViews.clear(); mGamelistViews.clear();
mSystemListView.reset(); mSystemListView.reset();
mCurrentView.reset(); mCurrentView.reset();
@ -1431,6 +1430,7 @@ void ViewController::rescanROMDirectory()
if (SystemData::sSystemVector.empty()) { if (SystemData::sSystemVector.empty()) {
// It's possible that there are no longer any games. // It's possible that there are no longer any games.
mWindow->setBlockInput(false);
mWindow->invalidateCachedBackground(); mWindow->invalidateCachedBackground();
noGamesDialog(); noGamesDialog();
} }
@ -1442,6 +1442,7 @@ void ViewController::rescanROMDirectory()
SDL_PushEvent(&quit); SDL_PushEvent(&quit);
return; return;
} }
mWindow->setBlockInput(false);
goToStart(false); goToStart(false);
} }
} }

View file

@ -88,9 +88,9 @@ public:
void triggerGameLaunch(FileData* game) void triggerGameLaunch(FileData* game)
{ {
mGameToLaunch = game; mGameToLaunch = game;
mLockInput = true; mWindow->setBlockInput(true);
}; };
bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); } const bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); }
std::vector<std::string>& getGameEndEventParams() { return mGameEndEventParams; } std::vector<std::string>& getGameEndEventParams() { return mGameEndEventParams; }
bool input(InputConfig* config, Input input) override; bool input(InputConfig* config, Input input) override;
@ -192,7 +192,6 @@ private:
float mWrapPreviousPositionX; float mWrapPreviousPositionX;
float mFadeOpacity; float mFadeOpacity;
bool mCancelledTransition; // Needed only for the Fade transition style. bool mCancelledTransition; // Needed only for the Fade transition style.
bool mLockInput;
bool mNextSystem; bool mNextSystem;
}; };

View file

@ -37,6 +37,7 @@ Window::Window() noexcept
, mFrameCountElapsed {0} , mFrameCountElapsed {0}
, mAverageDeltaTime {10} , mAverageDeltaTime {10}
, mTimeSinceLastInput {0} , mTimeSinceLastInput {0}
, mBlockInput {false}
, mNormalizeNextUpdate {false} , mNormalizeNextUpdate {false}
, mRenderScreensaver {false} , mRenderScreensaver {false}
, mRenderMediaViewer {false} , mRenderMediaViewer {false}
@ -211,6 +212,9 @@ void Window::deinit()
void Window::input(InputConfig* config, Input input) void Window::input(InputConfig* config, Input input)
{ {
if (mBlockInput)
return;
mTimeSinceLastInput = 0; mTimeSinceLastInput = 0;
// The DebugSkipInputLogging option has to be set manually in es_settings.xml as // The DebugSkipInputLogging option has to be set manually in es_settings.xml as

View file

@ -103,6 +103,7 @@ public:
void update(int deltaTime); void update(int deltaTime);
void render(); void render();
void setBlockInput(const bool state) { mBlockInput = state; }
void normalizeNextUpdate() { mNormalizeNextUpdate = true; } void normalizeNextUpdate() { mNormalizeNextUpdate = true; }
enum class SplashScreenState { enum class SplashScreenState {
@ -213,6 +214,7 @@ private:
int mAverageDeltaTime; int mAverageDeltaTime;
unsigned int mTimeSinceLastInput; unsigned int mTimeSinceLastInput;
bool mBlockInput;
bool mNormalizeNextUpdate; bool mNormalizeNextUpdate;
bool mRenderScreensaver; bool mRenderScreensaver;