Skip to content

Commit

Permalink
Add some missing locking in KeyMap.cpp.
Browse files Browse the repository at this point in the history
Plus minor assert change and java null check.
  • Loading branch information
hrydgard committed Sep 24, 2023
1 parent 559cc60 commit 3264209
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 8 deletions.
14 changes: 9 additions & 5 deletions Core/KeyMap.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -516,11 +516,11 @@ bool InputMappingsFromPspButton(int btn, std::vector<MultiInputMapping> *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;
Expand All @@ -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 };
Expand All @@ -563,6 +561,7 @@ MappedAnalogAxes MappedAxesForDevice(InputDeviceID deviceId) {
return MappedAnalogAxis{ -1 };
};

MappedAnalogAxes result;
std::lock_guard<std::recursive_mutex> 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);
Expand Down Expand Up @@ -621,6 +620,7 @@ bool ReplaceSingleKeyMapping(int btn, int index, MultiInputMapping key) {
}

void DeleteNthMapping(int key, int number) {
std::lock_guard<std::recursive_mutex> guard(g_controllerMapLock);
auto iter = g_controllerMap.find(key);
if (iter != g_controllerMap.end()) {
if (number < iter->second.size()) {
Expand Down Expand Up @@ -699,6 +699,8 @@ void LoadFromIni(IniFile &file) {
return;
}

std::lock_guard<std::recursive_mutex> guard(g_controllerMapLock);

Section *controls = file.GetOrCreateSection("ControlMapping");
for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) {
std::string value;
Expand Down Expand Up @@ -730,6 +732,8 @@ void LoadFromIni(IniFile &file) {
void SaveToIni(IniFile &file) {
Section *controls = file.GetOrCreateSection("ControlMapping");

std::lock_guard<std::recursive_mutex> guard(g_controllerMapLock);

for (size_t i = 0; i < ARRAY_SIZE(psp_button_names); i++) {
std::vector<MultiInputMapping> keys;
InputMappingsFromPspButton(psp_button_names[i].key, &keys, false);
Expand Down
2 changes: 1 addition & 1 deletion UI/NativeApp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
6 changes: 4 additions & 2 deletions android/src/org/ppsspp/ppsspp/NativeActivity.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

Expand Down

0 comments on commit 3264209

Please sign in to comment.