From 2c57936c500403bc3d71f1f6f1d36cc6589b9ec8 Mon Sep 17 00:00:00 2001 From: Wunkolo Date: Mon, 17 Jul 2023 10:23:10 -0700 Subject: [PATCH] Fix `EmulatorConfig` initialization order `config` was being consumed much too early before it has a chance to call `load`. This caused GPU to read weird uninitialized data, and then `load` called, and then further initialization to occur based on default data and the data inside of `config.toml`. `EmulatorConfig` needs to be loaded in first before any sort of initialization happens, by adding a new constructor so that it can be initialized sooner. --- include/config.hpp | 1 + include/emulator.hpp | 2 +- src/config.cpp | 2 ++ src/emulator.cpp | 4 +++- 4 files changed, 7 insertions(+), 2 deletions(-) diff --git a/include/config.hpp b/include/config.hpp index adbddd32..6bccdad6 100644 --- a/include/config.hpp +++ b/include/config.hpp @@ -8,6 +8,7 @@ struct EmulatorConfig { bool shaderJitEnabled = false; RendererType rendererType = RendererType::OpenGL; + EmulatorConfig(const std::filesystem::path& path); void load(const std::filesystem::path& path); void save(const std::filesystem::path& path); }; \ No newline at end of file diff --git a/include/emulator.hpp b/include/emulator.hpp index 5df986dc..d99eff1d 100644 --- a/include/emulator.hpp +++ b/include/emulator.hpp @@ -25,13 +25,13 @@ enum class ROMType { }; class Emulator { + EmulatorConfig config; CPU cpu; GPU gpu; Memory memory; Kernel kernel; Crypto::AESEngine aesEngine; - EmulatorConfig config; SDL_Window* window; #ifdef PANDA3DS_ENABLE_OPENGL diff --git a/src/config.cpp b/src/config.cpp index 7df73dbd..6923204d 100644 --- a/src/config.cpp +++ b/src/config.cpp @@ -9,6 +9,8 @@ // We are legally allowed, as per the author's wish, to use the above code without any licensing restrictions // However we still want to follow the license as closely as possible and offer the proper attributions. +EmulatorConfig::EmulatorConfig(const std::filesystem::path& path) { load(path); } + void EmulatorConfig::load(const std::filesystem::path& path) { // If the configuration file does not exist, create it and return std::error_code error; diff --git a/src/emulator.cpp b/src/emulator.cpp index 07ce61b5..8ab6e06e 100644 --- a/src/emulator.cpp +++ b/src/emulator.cpp @@ -14,7 +14,9 @@ __declspec(dllexport) DWORD AmdPowerXpressRequestHighPerformance = 1; } #endif -Emulator::Emulator() : kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory, config), memory(cpu.getTicksRef()) { +Emulator::Emulator() + : config(std::filesystem::current_path() / "config.toml"), kernel(cpu, memory, gpu), cpu(memory, kernel), gpu(memory, config), + memory(cpu.getTicksRef()) { if (SDL_Init(SDL_INIT_VIDEO | SDL_INIT_EVENTS) < 0) { Helpers::panic("Failed to initialize SDL2"); }