Skip to content

Commit be6c558

Browse files
committed
Correct the clearing/destruction order when switching JITs.
Fixes #20502
1 parent 28caa6f commit be6c558

File tree

2 files changed

+14
-16
lines changed

2 files changed

+14
-16
lines changed

Core/MIPS/IR/IRJit.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -119,6 +119,9 @@ class IRBlock {
119119
class IRBlockCache : public JitBlockCacheDebugInterface {
120120
public:
121121
IRBlockCache(bool compileToNative);
122+
~IRBlockCache() {
123+
Clear();
124+
}
122125

123126
void Clear();
124127
std::vector<int> FindInvalidatedBlockNumbers(u32 address, u32 length);

Core/MIPS/MIPS.cpp

Lines changed: 11 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -228,39 +228,34 @@ void MIPSState::UpdateCore(CPUCore desired) {
228228
return;
229229
}
230230

231+
if (MIPSComp::jit) {
232+
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
233+
delete MIPSComp::jit;
234+
MIPSComp::jit = nullptr;
235+
}
236+
231237
PSP_CoreParameter().cpuCore = desired;
232-
MIPSComp::JitInterface *oldjit = MIPSComp::jit;
233238
MIPSComp::JitInterface *newjit = nullptr;
234239

235240
switch (PSP_CoreParameter().cpuCore) {
236241
case CPUCore::JIT:
237242
case CPUCore::JIT_IR:
238243
INFO_LOG(Log::CPU, "Switching to JIT%s", PSP_CoreParameter().cpuCore == CPUCore::JIT_IR ? " IR" : "");
239-
if (oldjit) {
240-
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
241-
MIPSComp::jit = nullptr;
242-
delete oldjit;
243-
}
244244
newjit = MIPSComp::CreateNativeJit(this, PSP_CoreParameter().cpuCore == CPUCore::JIT_IR);
245245
break;
246246

247247
case CPUCore::IR_INTERPRETER:
248248
INFO_LOG(Log::CPU, "Switching to IR interpreter");
249-
if (oldjit) {
250-
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
251-
MIPSComp::jit = nullptr;
252-
delete oldjit;
253-
}
254249
newjit = new MIPSComp::IRJit(this, false);
255250
break;
256251

257252
case CPUCore::INTERPRETER:
258253
INFO_LOG(Log::CPU, "Switching to interpreter");
259-
if (oldjit) {
260-
std::lock_guard<std::recursive_mutex> guard(MIPSComp::jitLock);
261-
MIPSComp::jit = nullptr;
262-
delete oldjit;
263-
}
254+
break;
255+
256+
default:
257+
WARN_LOG(Log::CPU, "Invalid value for cpuCore, falling back to interpreter");
258+
// Leave as nullptr.
264259
break;
265260
}
266261

0 commit comments

Comments
 (0)