From 326420977226f7a952393fc0fdc73dfb288ed121 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Henrik=20Rydg=C3=A5rd?= Date: Sun, 24 Sep 2023 12:33:01 +0200 Subject: [PATCH] Add some missing locking in KeyMap.cpp. Plus minor assert change and java null check. --- Core/KeyMap.cpp | 14 +++++++++----- UI/NativeApp.cpp | 2 +- android/src/org/ppsspp/ppsspp/NativeActivity.java | 6 ++++-- 3 files changed, 14 insertions(+), 8 deletions(-) diff --git a/Core/KeyMap.cpp b/Core/KeyMap.cpp index 0b9a18dff118..fae0a0665fea 100644 --- a/Core/KeyMap.cpp +++ b/Core/KeyMap.cpp @@ -516,11 +516,11 @@ bool InputMappingsFromPspButton(int btn, std::vector *mapping return false; } bool mapped = false; - for (auto iter2 = iter->second.begin(); iter2 != iter->second.end(); ++iter2) { - bool ignore = ignoreMouse && iter2->HasMouse(); + for (auto &iter2 : iter->second) { + bool ignore = ignoreMouse && iter2.HasMouse(); if (mappings && !ignore) { mapped = true; - mappings->push_back(*iter2); + mappings->push_back(iter2); } } return mapped; @@ -536,8 +536,6 @@ bool PspButtonHasMappings(int btn) { } MappedAnalogAxes MappedAxesForDevice(InputDeviceID deviceId) { - MappedAnalogAxes result{}; - // Find the axisId mapped for a specific virtual button. auto findAxisId = [&](int btn) -> MappedAnalogAxis { MappedAnalogAxis info{ -1 }; @@ -563,6 +561,7 @@ MappedAnalogAxes MappedAxesForDevice(InputDeviceID deviceId) { return MappedAnalogAxis{ -1 }; }; + MappedAnalogAxes result; std::lock_guard guard(g_controllerMapLock); result.leftX = findAxisIdPair(VIRTKEY_AXIS_X_MIN, VIRTKEY_AXIS_X_MAX); result.leftY = findAxisIdPair(VIRTKEY_AXIS_Y_MIN, VIRTKEY_AXIS_Y_MAX); @@ -621,6 +620,7 @@ bool ReplaceSingleKeyMapping(int btn, int index, MultiInputMapping key) { } void DeleteNthMapping(int key, int number) { + std::lock_guard guard(g_controllerMapLock); auto iter = g_controllerMap.find(key); if (iter != g_controllerMap.end()) { if (number < iter->second.size()) { @@ -699,6 +699,8 @@ void LoadFromIni(IniFile &file) { return; } + std::lock_guard guard(g_controllerMapLock); + Section *controls = file.GetOrCreateSection("ControlMapping"); for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) { std::string value; @@ -730,6 +732,8 @@ void LoadFromIni(IniFile &file) { void SaveToIni(IniFile &file) { Section *controls = file.GetOrCreateSection("ControlMapping"); + std::lock_guard guard(g_controllerMapLock); + for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) { std::vector keys; InputMappingsFromPspButton(psp_button_names[i].key, &keys, false); diff --git a/UI/NativeApp.cpp b/UI/NativeApp.cpp index 618c430d7571..cd622c087388 100644 --- a/UI/NativeApp.cpp +++ b/UI/NativeApp.cpp @@ -828,7 +828,7 @@ bool CreateGlobalPipelines(); bool NativeInitGraphics(GraphicsContext *graphicsContext) { INFO_LOG(SYSTEM, "NativeInitGraphics"); - _assert_(g_screenManager); + _assert_msg_(g_screenManager, "No screenmanager, bad init order. Backend = %d", g_Config.iGPUBackend); // We set this now so any resize during init is processed later. resized = false; diff --git a/android/src/org/ppsspp/ppsspp/NativeActivity.java b/android/src/org/ppsspp/ppsspp/NativeActivity.java index eae7d71a4c93..db4a4c1c931d 100644 --- a/android/src/org/ppsspp/ppsspp/NativeActivity.java +++ b/android/src/org/ppsspp/ppsspp/NativeActivity.java @@ -765,8 +765,10 @@ protected void onDestroy() { mGLSurfaceView.onDestroy(); mGLSurfaceView = null; } else { - mSurfaceView.onDestroy(); - mSurfaceView = null; + if (mSurfaceView != null) { + mSurfaceView.onDestroy(); + mSurfaceView = null; + } mSurface = null; }