Skip to content

Commit

Permalink
Make stopping emulation not pause or crash UI
Browse files Browse the repository at this point in the history
* Make the UI and main thread available when stopping emulation.
* Make BlockingCallFromMainThread always execute, preventing bugs when it unexpectedly did not.
* Add error code for when starting emulation when Emu.Kill() is in progress.
  • Loading branch information
elad335 committed Jun 26, 2023
1 parent 9b344cb commit 30bf786
Show file tree
Hide file tree
Showing 8 changed files with 403 additions and 248 deletions.
40 changes: 22 additions & 18 deletions rpcs3/Emu/Cell/lv2/sys_process.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -425,7 +425,6 @@ void lv2_exitspawn(ppu_thread& ppu, std::vector<std::string>& argv, std::vector<

std::string path = vfs::get(argv[0]);
std::string hdd1 = vfs::get("/dev_hdd1/");
std::string old_config = Emu.GetUsedConfig();

const u128 klic = g_fxo->get<loaded_npdrm_keys>().last_key();

Expand Down Expand Up @@ -457,27 +456,32 @@ void lv2_exitspawn(ppu_thread& ppu, std::vector<std::string>& argv, std::vector<
g_fxo->init<lv2_memory_container>(std::min(old_size - total_size, sdk_suggested_mem) + total_size);
};

Emu.Kill(false);
Emu.argv = std::move(argv);
Emu.envp = std::move(envp);
Emu.data = std::move(data);
Emu.disc = std::move(disc);
Emu.hdd1 = std::move(hdd1);
Emu.init_mem_containers = std::move(func);

if (klic)
Emu.after_kill_callback = [func = std::move(func), argv = std::move(argv), envp = std::move(envp), data = std::move(data),
disc = std::move(disc), path = std::move(path), hdd1 = std::move(hdd1), old_config = Emu.GetUsedConfig(), klic]() mutable
{
Emu.klic.emplace_back(klic);
}
Emu.argv = std::move(argv);
Emu.envp = std::move(envp);
Emu.data = std::move(data);
Emu.disc = std::move(disc);
Emu.hdd1 = std::move(hdd1);
Emu.init_mem_containers = std::move(func);

if (klic)
{
Emu.klic.emplace_back(klic);
}

Emu.SetForceBoot(true);
Emu.SetForceBoot(true);

auto res = Emu.BootGame(path, "", true, cfg_mode::continuous, old_config);
auto res = Emu.BootGame(path, "", true, cfg_mode::continuous, old_config);

if (res != game_boot_result::no_errors)
{
sys_process.fatal("Failed to boot from exitspawn! (path=\"%s\", error=%s)", path, res);
}
if (res != game_boot_result::no_errors)
{
sys_process.fatal("Failed to boot from exitspawn! (path=\"%s\", error=%s)", path, res);
}
};

Emu.Kill(false);
});

// Wait for GUI thread
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,15 @@ namespace rsx

Emu.CallFromMainThread([suspend_mode]()
{
Emu.Kill(false, true);

if (!suspend_mode)
{
Emu.Restart();
Emu.after_kill_callback = []()
{
Emu.Restart();
};
}

Emu.Kill(false, true);
});

return page_navigation::exit;
Expand Down
Loading

0 comments on commit 30bf786

Please sign in to comment.