From ca45ea6d0802d2604f3e9da52fc965f72a63b134 Mon Sep 17 00:00:00 2001 From: Leon Styhre Date: Wed, 20 Sep 2023 20:46:51 +0200 Subject: [PATCH] Controller input is now blocked during ROM directory rescans to avoid crashes --- es-app/src/views/ViewController.cpp | 11 ++++++----- es-app/src/views/ViewController.h | 5 ++--- es-core/src/Window.cpp | 4 ++++ es-core/src/Window.h | 2 ++ 4 files changed, 14 insertions(+), 8 deletions(-) diff --git a/es-app/src/views/ViewController.cpp b/es-app/src/views/ViewController.cpp index 52de54a88..377bfdfcb 100644 --- a/es-app/src/views/ViewController.cpp +++ b/es-app/src/views/ViewController.cpp @@ -47,7 +47,6 @@ ViewController::ViewController() noexcept , mWrappedViews {false} , mFadeOpacity {0} , mCancelledTransition {false} - , mLockInput {false} , mNextSystem {false} { mState.viewing = ViewMode::NOTHING; @@ -920,7 +919,8 @@ void ViewController::launch(FileData* game) onFileChanged(game, true); // This is a workaround so that any keys or button presses used for exiting the emulator // 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 ViewController::getSystemListView() bool ViewController::input(InputConfig* config, Input input) { - if (mLockInput) - return true; - // 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. // 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() { + mWindow->setBlockInput(true); + mGamelistViews.clear(); mSystemListView.reset(); mCurrentView.reset(); @@ -1431,6 +1430,7 @@ void ViewController::rescanROMDirectory() if (SystemData::sSystemVector.empty()) { // It's possible that there are no longer any games. + mWindow->setBlockInput(false); mWindow->invalidateCachedBackground(); noGamesDialog(); } @@ -1442,6 +1442,7 @@ void ViewController::rescanROMDirectory() SDL_PushEvent(&quit); return; } + mWindow->setBlockInput(false); goToStart(false); } } diff --git a/es-app/src/views/ViewController.h b/es-app/src/views/ViewController.h index d6628befa..125ae9ad6 100644 --- a/es-app/src/views/ViewController.h +++ b/es-app/src/views/ViewController.h @@ -88,9 +88,9 @@ public: void triggerGameLaunch(FileData* game) { mGameToLaunch = game; - mLockInput = true; + mWindow->setBlockInput(true); }; - bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); } + const bool getGameLaunchTriggered() { return (mGameToLaunch != nullptr); } std::vector& getGameEndEventParams() { return mGameEndEventParams; } bool input(InputConfig* config, Input input) override; @@ -192,7 +192,6 @@ private: float mWrapPreviousPositionX; float mFadeOpacity; bool mCancelledTransition; // Needed only for the Fade transition style. - bool mLockInput; bool mNextSystem; }; diff --git a/es-core/src/Window.cpp b/es-core/src/Window.cpp index b8fa672b7..4ef169f3c 100644 --- a/es-core/src/Window.cpp +++ b/es-core/src/Window.cpp @@ -37,6 +37,7 @@ Window::Window() noexcept , mFrameCountElapsed {0} , mAverageDeltaTime {10} , mTimeSinceLastInput {0} + , mBlockInput {false} , mNormalizeNextUpdate {false} , mRenderScreensaver {false} , mRenderMediaViewer {false} @@ -211,6 +212,9 @@ void Window::deinit() void Window::input(InputConfig* config, Input input) { + if (mBlockInput) + return; + mTimeSinceLastInput = 0; // The DebugSkipInputLogging option has to be set manually in es_settings.xml as diff --git a/es-core/src/Window.h b/es-core/src/Window.h index f9e10f16c..198e8c2a7 100644 --- a/es-core/src/Window.h +++ b/es-core/src/Window.h @@ -103,6 +103,7 @@ public: void update(int deltaTime); void render(); + void setBlockInput(const bool state) { mBlockInput = state; } void normalizeNextUpdate() { mNormalizeNextUpdate = true; } enum class SplashScreenState { @@ -213,6 +214,7 @@ private: int mAverageDeltaTime; unsigned int mTimeSinceLastInput; + bool mBlockInput; bool mNormalizeNextUpdate; bool mRenderScreensaver;