diff --git a/Editor/GeneralWindow.cpp b/Editor/GeneralWindow.cpp index 702af8267..9e82d024f 100644 --- a/Editor/GeneralWindow.cpp +++ b/Editor/GeneralWindow.cpp @@ -448,26 +448,29 @@ void GeneralWindow::Create(EditorComponent* _editor) { editor->main->config.GetSection("options").Set("theme", currentTheme); wi::Archive archive(wi::helper::GetCurrentPath() + "/themes/" + currentTheme + ".witheme"); - uint64_t version = 0; - archive >> version; - archive >> theme_color_idle.rgba; - archive >> theme_color_focus.rgba; - archive >> theme_color_background.rgba; - archive >> theme.shadow_color.rgba; - archive >> theme.font.color.rgba; - archive >> theme.font.shadow_color.rgba; - std::string imageresourcename; - archive >> imageresourcename; - wi::vector imagedata; - archive >> imagedata; - static uint64_t cnt = 0; - if (imagedata.empty()) + if (archive.IsOpen()) { - editor->themeEditorWnd.imageResource = {}; - } - else - { - editor->themeEditorWnd.imageResource = wi::resourcemanager::Load(wi::helper::GetCurrentPath() + "/themes/" + imageresourcename, wi::resourcemanager::Flags::IMPORT_RETAIN_FILEDATA, imagedata.data(), imagedata.size()); + uint64_t version = 0; + archive >> version; + archive >> theme_color_idle.rgba; + archive >> theme_color_focus.rgba; + archive >> theme_color_background.rgba; + archive >> theme.shadow_color.rgba; + archive >> theme.font.color.rgba; + archive >> theme.font.shadow_color.rgba; + std::string imageresourcename; + archive >> imageresourcename; + wi::vector imagedata; + archive >> imagedata; + static uint64_t cnt = 0; + if (imagedata.empty()) + { + editor->themeEditorWnd.imageResource = {}; + } + else + { + editor->themeEditorWnd.imageResource = wi::resourcemanager::Load(wi::helper::GetCurrentPath() + "/themes/" + imageresourcename, wi::resourcemanager::Flags::IMPORT_RETAIN_FILEDATA, imagedata.data(), imagedata.size()); + } } } break; @@ -1136,23 +1139,23 @@ void GeneralWindow::ReloadThemes() if (currentTheme == "Dark") { - themeCombo.SetSelectedByUserdataWithoutCallback((uint64_t)Theme::Dark); + themeCombo.SetSelectedByUserdata((uint64_t)Theme::Dark); } else if (currentTheme == "Bright") { - themeCombo.SetSelectedByUserdataWithoutCallback((uint64_t)Theme::Bright); + themeCombo.SetSelectedByUserdata((uint64_t)Theme::Bright); } else if (currentTheme == "Soft") { - themeCombo.SetSelectedByUserdataWithoutCallback((uint64_t)Theme::Soft); + themeCombo.SetSelectedByUserdata((uint64_t)Theme::Soft); } else if (currentTheme == "Hacking") { - themeCombo.SetSelectedByUserdataWithoutCallback((uint64_t)Theme::Hacking); + themeCombo.SetSelectedByUserdata((uint64_t)Theme::Hacking); } else if (currentTheme == "Nord") { - themeCombo.SetSelectedByUserdataWithoutCallback((uint64_t)Theme::Nord); + themeCombo.SetSelectedByUserdata((uint64_t)Theme::Nord); } else { @@ -1160,7 +1163,7 @@ void GeneralWindow::ReloadThemes() { if (currentTheme == themeCombo.GetItemText(i)) { - themeCombo.SetSelectedWithoutCallback(i); + themeCombo.SetSelected(i); break; } } diff --git a/Editor/WeatherWindow.cpp b/Editor/WeatherWindow.cpp index 2d661868e..e85fce1cd 100644 --- a/Editor/WeatherWindow.cpp +++ b/Editor/WeatherWindow.cpp @@ -1036,6 +1036,8 @@ void WeatherWindow::SetEntity(wi::ecs::Entity entity) void WeatherWindow::Update() { + if (editor == nullptr) + return; Scene& scene = editor->GetCurrentScene(); if (scene.weathers.GetCount() > 0) { diff --git a/Editor/main_SDL2.cpp b/Editor/main_SDL2.cpp index 380104c89..2bea1088a 100644 --- a/Editor/main_SDL2.cpp +++ b/Editor/main_SDL2.cpp @@ -208,7 +208,7 @@ int main(int argc, char *argv[]) bool fullscreen = false; wi::Timer timer; - if (wi::helper::FileExists("config.ini") && editor.config.Open("config.ini")) + if (editor.config.Open("config.ini")) { if (editor.config.Has("width")) { diff --git a/Editor/main_Windows.cpp b/Editor/main_Windows.cpp index 2bcf507b5..ebba1aa05 100644 --- a/Editor/main_Windows.cpp +++ b/Editor/main_Windows.cpp @@ -152,7 +152,7 @@ int APIENTRY wWinMain(_In_ HINSTANCE hInstance, bool borderless = false; wi::Timer timer; - if (wi::helper::FileExists("config.ini") && editor.config.Open("config.ini")) + if (editor.config.Open("config.ini")) { if (editor.config.Has("width")) { diff --git a/WickedEngine/wiConfig.cpp b/WickedEngine/wiConfig.cpp index 5c5bac651..729f0105b 100644 --- a/WickedEngine/wiConfig.cpp +++ b/WickedEngine/wiConfig.cpp @@ -2,6 +2,7 @@ #include "wiHelper.h" #include +#include namespace wi::config { @@ -95,6 +96,8 @@ namespace wi::config bool File::Open(const char* filename) { this->filename = filename; // even if file couldn't be loaded, we remember the filename so it can be created on commit + if (!wi::helper::FileExists(filename)) + return false; wi::vector filedata; if (!wi::helper::FileRead(filename, filedata)) return false; @@ -308,6 +311,8 @@ namespace wi::config } } } + static std::mutex locker; + std::scoped_lock lck(locker); wi::helper::FileWrite(filename, (const uint8_t*)text.c_str(), text.length()); } Section& File::GetSection(const char* name)