mirror of
https://github.com/mitch030504/Wiicompiled_VR_Frame.git
synced 2026-10-06 05:00:27 +02:00
Report graphics startup failures instead of aborting
When no backend could create a window and a WebGPU device, aurora hit an ASSERT and the process aborted with only SDL's last error in the log. Keep the first adapter, device or window error, return it from aurora_initialize with a new initializationStatus, and have the runtime throw it so the existing fatal popup and fatal log record the reason. ImGui shutdown now skips backends that never initialized, so the shutdown that follows a failed start does not crash. From upstream patchzyy/Wiicompiled 6f14bde (#244, KartPad batch). Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com> Claude-Session: https://claude.ai/code/session_01Wg7mB8ogCWmp9GH19Uc82B
This commit is contained in:
5 files changed
+52
-1
No files matched your search
@@ -295,12 +295,20 @@ typedef struct {
|
|||||||
bool xrHeadsetOnly;
|
bool xrHeadsetOnly;
|
||||||
} AuroraConfig;
|
} AuroraConfig;
|
||||||
|
|
||||||
|
typedef enum {
|
||||||
|
AURORA_INITIALIZATION_SUCCESS = 0,
|
||||||
|
AURORA_INITIALIZATION_GRAPHICS_UNAVAILABLE = 1,
|
||||||
|
} AuroraInitializationStatus;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
AuroraBackend backend;
|
AuroraBackend backend;
|
||||||
const char* userPath;
|
const char* userPath;
|
||||||
const char* cachePath;
|
const char* cachePath;
|
||||||
SDL_Window* window;
|
SDL_Window* window;
|
||||||
AuroraWindowSize windowSize;
|
AuroraWindowSize windowSize;
|
||||||
|
AuroraInitializationStatus initializationStatus;
|
||||||
|
// On failure, owned by SDL on the calling thread. Copy before another SDL call.
|
||||||
|
const char* initializationError;
|
||||||
} AuroraInfo;
|
} AuroraInfo;
|
||||||
|
|
||||||
AuroraInfo aurora_initialize(int argc, char* argv[], const AuroraConfig* config);
|
AuroraInfo aurora_initialize(int argc, char* argv[], const AuroraConfig* config);
|
||||||
|
|||||||
@@ -1229,15 +1229,23 @@ AuroraInfo initialize(int argc, char* argv[], const AuroraConfig& config) noexce
|
|||||||
const AuroraBackend requestedBackend = config.desiredBackend;
|
const AuroraBackend requestedBackend = config.desiredBackend;
|
||||||
AuroraBackend selectedBackend = requestedBackend;
|
AuroraBackend selectedBackend = requestedBackend;
|
||||||
bool windowCreated = false;
|
bool windowCreated = false;
|
||||||
|
std::string firstGraphicsError;
|
||||||
|
const auto rememberGraphicsError = [&] {
|
||||||
|
if (firstGraphicsError.empty() && SDL_GetError()[0] != '\0') {
|
||||||
|
firstGraphicsError = SDL_GetError();
|
||||||
|
}
|
||||||
|
};
|
||||||
if (selectedBackend != BACKEND_AUTO) {
|
if (selectedBackend != BACKEND_AUTO) {
|
||||||
Log.info("Requested graphics backend: {}", backend_name(selectedBackend));
|
Log.info("Requested graphics backend: {}", backend_name(selectedBackend));
|
||||||
if (window::create_window(selectedBackend)) {
|
if (window::create_window(selectedBackend)) {
|
||||||
if (webgpu::initialize(selectedBackend)) {
|
if (webgpu::initialize(selectedBackend)) {
|
||||||
windowCreated = true;
|
windowCreated = true;
|
||||||
} else {
|
} else {
|
||||||
|
rememberGraphicsError();
|
||||||
window::destroy_window();
|
window::destroy_window();
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
rememberGraphicsError();
|
||||||
Log.error("Failed to create a window for backend {}: {}", backend_name(selectedBackend), SDL_GetError());
|
Log.error("Failed to create a window for backend {}: {}", backend_name(selectedBackend), SDL_GetError());
|
||||||
}
|
}
|
||||||
if (!windowCreated) {
|
if (!windowCreated) {
|
||||||
@@ -1254,18 +1262,28 @@ AuroraInfo initialize(int argc, char* argv[], const AuroraConfig& config) noexce
|
|||||||
for (const auto backendType : PreferredBackendOrder) {
|
for (const auto backendType : PreferredBackendOrder) {
|
||||||
selectedBackend = backendType;
|
selectedBackend = backendType;
|
||||||
if (!window::create_window(selectedBackend)) {
|
if (!window::create_window(selectedBackend)) {
|
||||||
|
rememberGraphicsError();
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (webgpu::initialize(selectedBackend)) {
|
if (webgpu::initialize(selectedBackend)) {
|
||||||
windowCreated = true;
|
windowCreated = true;
|
||||||
break;
|
break;
|
||||||
} else {
|
} else {
|
||||||
|
rememberGraphicsError();
|
||||||
window::destroy_window();
|
window::destroy_window();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
ASSERT(windowCreated, "Error creating window: {}", SDL_GetError());
|
if (!windowCreated) {
|
||||||
|
if (firstGraphicsError.empty()) firstGraphicsError = "No supported graphics backend is available";
|
||||||
|
SDL_SetError("%s", firstGraphicsError.c_str());
|
||||||
|
Log.error("Graphics initialization failed: {}", firstGraphicsError);
|
||||||
|
return {
|
||||||
|
.initializationStatus = AURORA_INITIALIZATION_GRAPHICS_UNAVAILABLE,
|
||||||
|
.initializationError = SDL_GetError(),
|
||||||
|
};
|
||||||
|
}
|
||||||
if (requestedBackend != BACKEND_AUTO && selectedBackend != requestedBackend) {
|
if (requestedBackend != BACKEND_AUTO && selectedBackend != requestedBackend) {
|
||||||
Log.error(
|
Log.error(
|
||||||
"Graphics backend fallback in effect: video.graphics_api requested {}, "
|
"Graphics backend fallback in effect: video.graphics_api requested {}, "
|
||||||
|
|||||||
@@ -85,18 +85,30 @@ void initialize() noexcept {
|
|||||||
|
|
||||||
void shutdown() noexcept {
|
void shutdown() noexcept {
|
||||||
ZoneScoped;
|
ZoneScoped;
|
||||||
|
// Startup can fail before either backend initializes. A context alone does
|
||||||
|
// not mean its renderer/platform backend owns resources to release.
|
||||||
|
if (ImGui::GetCurrentContext() != nullptr) {
|
||||||
|
ImGuiIO& io = ImGui::GetIO();
|
||||||
|
if (io.BackendRendererUserData != nullptr) {
|
||||||
if (g_useSdlRenderer) {
|
if (g_useSdlRenderer) {
|
||||||
ImGui_ImplSDLRenderer3_Shutdown();
|
ImGui_ImplSDLRenderer3_Shutdown();
|
||||||
} else {
|
} else {
|
||||||
ImGui_ImplWGPU_Shutdown();
|
ImGui_ImplWGPU_Shutdown();
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
if (io.BackendPlatformUserData != nullptr) {
|
||||||
ImGui_ImplSDL3_Shutdown();
|
ImGui_ImplSDL3_Shutdown();
|
||||||
|
}
|
||||||
ImGui::DestroyContext();
|
ImGui::DestroyContext();
|
||||||
|
}
|
||||||
for (const auto& texture : g_sdlTextures) {
|
for (const auto& texture : g_sdlTextures) {
|
||||||
SDL_DestroyTexture(texture);
|
SDL_DestroyTexture(texture);
|
||||||
}
|
}
|
||||||
g_sdlTextures.clear();
|
g_sdlTextures.clear();
|
||||||
g_wgpuTextures.clear();
|
g_wgpuTextures.clear();
|
||||||
|
g_useSdlRenderer = false;
|
||||||
|
g_scale = 0.f;
|
||||||
|
g_frameDataBuilt = true;
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_event(const SDL_Event& event) noexcept {
|
void process_event(const SDL_Event& event) noexcept {
|
||||||
|
|||||||
@@ -627,12 +627,16 @@ bool initialize(AuroraBackend auroraBackend) {
|
|||||||
g_adapter = std::move(adapter);
|
g_adapter = std::move(adapter);
|
||||||
} else {
|
} else {
|
||||||
Log.warn("Adapter request failed: {}", message);
|
Log.warn("Adapter request failed: {}", message);
|
||||||
|
const std::string_view reason{message};
|
||||||
|
SDL_SetError("Graphics adapter unavailable: %.*s",
|
||||||
|
static_cast<int>(std::min<size_t>(reason.size(), 512)), reason.data());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const auto status = g_instance.WaitAny(future, 5000000000);
|
const auto status = g_instance.WaitAny(future, 5000000000);
|
||||||
if (status != wgpu::WaitStatus::Success) {
|
if (status != wgpu::WaitStatus::Success) {
|
||||||
Log.error("Failed to create {} adapter: {}", magic_enum::enum_name(backend),
|
Log.error("Failed to create {} adapter: {}", magic_enum::enum_name(backend),
|
||||||
magic_enum::enum_name(status));
|
magic_enum::enum_name(status));
|
||||||
|
SDL_SetError("Graphics adapter request did not complete within its startup deadline");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!g_adapter) {
|
if (!g_adapter) {
|
||||||
@@ -845,11 +849,16 @@ bool initialize(AuroraBackend auroraBackend) {
|
|||||||
g_device = std::move(device);
|
g_device = std::move(device);
|
||||||
} else {
|
} else {
|
||||||
Log.warn("Device request failed: {}", message);
|
Log.warn("Device request failed: {}", message);
|
||||||
|
const std::string_view reason{message};
|
||||||
|
SDL_SetError("Graphics device unavailable: %.*s",
|
||||||
|
static_cast<int>(std::min<size_t>(reason.size(), 512)),
|
||||||
|
reason.data());
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
const auto status = g_instance.WaitAny(future, 5000000000);
|
const auto status = g_instance.WaitAny(future, 5000000000);
|
||||||
if (status != wgpu::WaitStatus::Success) {
|
if (status != wgpu::WaitStatus::Success) {
|
||||||
Log.error("Failed to create device: {}", magic_enum::enum_name(status));
|
Log.error("Failed to create device: {}", magic_enum::enum_name(status));
|
||||||
|
SDL_SetError("Graphics device request did not complete within its startup deadline");
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (!g_device) {
|
if (!g_device) {
|
||||||
|
|||||||
@@ -1551,6 +1551,10 @@ int RuntimeMain(int argc, char** argv) {
|
|||||||
WiiRemoteInput::ConfigureSdlHints(RuntimeConfigFile::WiiRemotesEnabled(true));
|
WiiRemoteInput::ConfigureSdlHints(RuntimeConfigFile::WiiRemotesEnabled(true));
|
||||||
|
|
||||||
const AuroraInfo auroraInfo = aurora_initialize(0, nullptr, &auroraConfig);
|
const AuroraInfo auroraInfo = aurora_initialize(0, nullptr, &auroraConfig);
|
||||||
|
if (auroraInfo.initializationStatus != AURORA_INITIALIZATION_SUCCESS) {
|
||||||
|
throw std::runtime_error(auroraInfo.initializationError != nullptr
|
||||||
|
? auroraInfo.initializationError : "No supported graphics backend is available");
|
||||||
|
}
|
||||||
if (requestedBackend != BACKEND_AUTO && auroraInfo.backend != requestedBackend) {
|
if (requestedBackend != BACKEND_AUTO && auroraInfo.backend != requestedBackend) {
|
||||||
RT_LOG(RT_TAG_RUNTIME) << "graphics_api=\"" << backend
|
RT_LOG(RT_TAG_RUNTIME) << "graphics_api=\"" << backend
|
||||||
<< "\" is not available on this system; aurora fell back to \""
|
<< "\" is not available on this system; aurora fell back to \""
|
||||||
|
|||||||
Reference in new issue
Block a user