extraction: detect task crashing (#6386)

This commit is contained in:
Philip Dubé
2026-03-22 06:03:41 +00:00
committed by GitHub
parent b65c1c8317
commit 96c4fef05c

View File

@@ -6,6 +6,7 @@
#include <fstream>
#include <vector>
#include <chrono>
#include <optional>
#include "ResourceManagerHelpers.h"
#include <fast/Fast3dWindow.h>
@@ -408,7 +409,6 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
Extractor extract;
PromptSteps promptStep = PS_FILE_CHECK;
bool generatedIsMQ = false;
std::atomic<bool> extracting = false;
std::atomic<size_t> extractCount = 0, totalExtract = 0;
std::string installPath = Ship::Context::GetAppBundlePath();
@@ -444,8 +444,9 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
}
std::shared_ptr<BS::thread_pool> threadPool = std::make_shared<BS::thread_pool>(1);
std::optional<std::future<void>> extractionTask;
while (!extractDone) {
if (SohGui::PopupsQueued() > 0 || extracting) {
if (SohGui::PopupsQueued() > 0 || extractionTask.has_value()) {
goto render;
}
switch (extractStep) {
@@ -582,20 +583,16 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
if (std::filesystem::exists(Ship::Context::GetAppDirectoryPath(appShortName) + "/" + archive)) {
std::string msg = "Archive for current ROM, " + archive + ", already exists.\nExtract again?";
SohGui::RegisterPopup("Confirm Re-extract", msg.c_str(), "Yes", "No", [&]() {
extracting = true;
threadPool->submit_task([&]() -> void {
extractionTask = threadPool->submit_task([&]() -> void {
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
&extractCount, &totalExtract);
extracting = false;
extractCount = totalExtract = 0;
});
});
} else {
extracting = true;
threadPool->submit_task([&]() -> void {
extractionTask = threadPool->submit_task([&]() -> void {
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
&extractCount, &totalExtract);
extracting = false;
extractCount = totalExtract = 0;
});
}
@@ -648,12 +645,10 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
promptStep = PS_FILE_CHECK;
continue;
}
extracting = true;
threadPool->submit_task([&]() -> void {
extractionTask = threadPool->submit_task([&]() -> void {
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
&extractCount, &totalExtract);
generatedIsMQ = extract.IsMasterQuest();
extracting = false;
promptStep = PS_SECOND;
extractCount = 0;
totalExtract = 0;
@@ -668,11 +663,9 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
: RomSearchMode::MQ)) {
extractStep = ES_VERIFY;
} else {
extracting = true;
threadPool->submit_task([&]() -> void {
extractionTask = threadPool->submit_task([&]() -> void {
extract.CallZapd(installPath, Ship::Context::GetAppDirectoryPath(appShortName),
&extractCount, &totalExtract);
extracting = false;
extractStep = ES_VERIFY;
extractCount = 0;
totalExtract = 0;
@@ -722,10 +715,19 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
gui->StartDraw();
sohFast3dWindow->StartFrame();
sohFast3dWindow->RunGuiOnly();
if (extracting && !ImGui::IsPopupOpen("ROM Extraction")) {
if (extractionTask.has_value()) {
auto status = extractionTask->wait_for(std::chrono::milliseconds(0));
if (status == std::future_status::ready) {
try {
extractionTask->get();
} catch (const std::exception& e) {
SohGui::RegisterPopup("Extraction Crashed", e.what(), "Close", "", []() { exit(1); });
}
extractionTask.reset();
} else {
if (!ImGui::IsPopupOpen("ROM Extraction")) {
ImGui::OpenPopup("ROM Extraction");
}
if (extracting) {
ImGui::PushStyleVar(ImGuiStyleVar_FrameRounding, 3.0f);
ImGui::PushStyleVar(ImGuiStyleVar_FramePadding, ImVec2(10.0f, 8.0f));
auto color = UIWidgets::ColorValues.at(THEME_COLOR);
@@ -747,6 +749,7 @@ void OTRGlobals::RunExtract(int argc, char* argv[]) {
ImGui::PopStyleColor(3);
ImGui::PopStyleVar(2);
}
}
gui->EndDraw();
sohFast3dWindow->EndFrame();
ImGui::PopStyleColor(2);