From e4c3a768096f1e994aa511cce99e590306064aa9 Mon Sep 17 00:00:00 2001 From: Kim Kulling Date: Thu, 12 Sep 2024 14:04:42 +0200 Subject: [PATCH] Fix crashes --- samples/00_HelloWorld/HelloWorld.cpp | 4 +++- samples/01_ModelLoading/ModelLoading.cpp | 2 +- samples/03_Instancing/Instancing.cpp | 2 +- samples/04_terrain/TerrainRendering.cpp | 3 +-- src/Editor/src/OsreEdApp.cpp | 12 +++++++++-- src/Editor/src/main.cpp | 27 +++++------------------- src/Engine/App/AppBase.cpp | 6 +++--- src/Engine/App/AppBase.h | 16 +++++++++++++- 8 files changed, 39 insertions(+), 33 deletions(-) diff --git a/samples/00_HelloWorld/HelloWorld.cpp b/samples/00_HelloWorld/HelloWorld.cpp index 5e9ba6165..2b45a80f5 100644 --- a/samples/00_HelloWorld/HelloWorld.cpp +++ b/samples/00_HelloWorld/HelloWorld.cpp @@ -105,7 +105,9 @@ class HelloWorldApp : public App::AppBase { void onUpdate() override { Platform::Key key = AppBase::getKeyboardEventListener()->getLastKey(); - mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key)); + if (key != Platform::KEY_UNKNOWN) { + mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key)); + } RenderBackendService *rbSrv = ServiceProvider::getService(ServiceType::RenderService); diff --git a/samples/01_ModelLoading/ModelLoading.cpp b/samples/01_ModelLoading/ModelLoading.cpp index 60f36b4e0..fbc8ba049 100644 --- a/samples/01_ModelLoading/ModelLoading.cpp +++ b/samples/01_ModelLoading/ModelLoading.cpp @@ -185,7 +185,7 @@ class ModelLoadingApp : public App::AppBase { int main(int argc, char *argv[]) { ModelLoadingApp myApp(argc, argv); - if (!myApp.initWindow(10, 10, 1024, 768, "ModelLoader sample! Press o to import an Asset", false, false, App::RenderBackendType::OpenGLRenderBackend)) { + if (!myApp.initWindow(10, 10, 1024, 768, "ModelLoader sample! Press o to import an Asset", WindowMode::Windowed, WindowType::Root, App::RenderBackendType::OpenGLRenderBackend)) { return 1; } diff --git a/samples/03_Instancing/Instancing.cpp b/samples/03_Instancing/Instancing.cpp index 9d0e1fbed..fb1f6bc57 100644 --- a/samples/03_Instancing/Instancing.cpp +++ b/samples/03_Instancing/Instancing.cpp @@ -116,7 +116,7 @@ class InstancingApp : public App::AppBase { int main(int argc, char *argv[]) { InstancingApp myApp(argc, argv); - if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", false, false, RenderBackendType::OpenGLRenderBackend)) { + if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", WindowMode::Windowed, WindowType::Root, RenderBackendType::OpenGLRenderBackend)) { return 1; } diff --git a/samples/04_terrain/TerrainRendering.cpp b/samples/04_terrain/TerrainRendering.cpp index df0e5472c..b6e8b86e2 100644 --- a/samples/04_terrain/TerrainRendering.cpp +++ b/samples/04_terrain/TerrainRendering.cpp @@ -205,7 +205,7 @@ class TerrainRenderingApp : public App::AppBase { int main(int argc, char *argv[]) { TerrainRenderingApp myApp(argc, argv); - if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", false, false, RenderBackendType::OpenGLRenderBackend)) { + if (!myApp.initWindow(10, 10, 1024, 768, "Instancing-Sample", WindowMode::Windowed, WindowType::Root, RenderBackendType::OpenGLRenderBackend)) { return 1; } @@ -218,4 +218,3 @@ int main(int argc, char *argv[]) { return 0; } - diff --git a/src/Editor/src/OsreEdApp.cpp b/src/Editor/src/OsreEdApp.cpp index 5287c5761..e21245480 100644 --- a/src/Editor/src/OsreEdApp.cpp +++ b/src/Editor/src/OsreEdApp.cpp @@ -3,7 +3,7 @@ #include "OSREEdApp.h" #include "ProgressReporter.h" #include "Actions/ImportAction.h" - +#include "Platform/PlatformOperations.h" #include "RenderBackend/MeshBuilder.h" #include "App/Stage.h" #include "App/TransformController.h" @@ -154,8 +154,16 @@ bool OsreEdApp::onCreate() { } void OsreEdApp::onUpdate() { + if (AppBase::isKeyPressed(Platform::KEY_O) || AppBase::isKeyPressed(Platform::KEY_o)) { + IO::Uri modelLoc; + Platform::PlatformOperations::getFileOpenDialog("Choose asset for import", "*", modelLoc); + if (modelLoc.isValid()) { + loadAsset(modelLoc); + } + } + Platform::Key key = AppBase::getKeyboardEventListener()->getLastKey(); - if (mKeyboardTransCtrl != nullptr) { + if (key != Platform::KEY_UNKNOWN && mKeyboardTransCtrl != nullptr) { mKeyboardTransCtrl->update(mKeyboardTransCtrl->getKeyBinding(key)); } diff --git a/src/Editor/src/main.cpp b/src/Editor/src/main.cpp index a86671c5f..4700eacdc 100644 --- a/src/Editor/src/main.cpp +++ b/src/Editor/src/main.cpp @@ -34,7 +34,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #include "App/Entity.h" #include "Platform/AbstractWindow.h" #include "Common/glm_common.h" -#include "Platform/PlatformOperations.h" +//#include "Platform/PlatformOperations.h" #include "Platform/PlatformInterface.h" #include "Platform/win32/Win32Window.h" @@ -48,39 +48,22 @@ using namespace OSRE::Editor; static constexpr c8 Tag[] = "HelloWorldApp"; - int main(int argc, char *argv[]) { std::cout << "Editor version 0.1\n"; OsreEdApp osreApp(argc, argv); - if (!osreApp.initWindow(100, 100, 1024, 768, "test", false, true, App::RenderBackendType::OpenGLRenderBackend)) { + if (!osreApp.initWindow(100, 100, 1024, 768, "test", WindowMode::Windowed, WindowType::Root, App::RenderBackendType::OpenGLRenderBackend)) { return -1; } - IO::Uri modelLoc; - PlatformOperations::getFileOpenDialog("Select asset for import", "*", modelLoc); - if (modelLoc.isValid()) { - osreApp.loadAsset(modelLoc); - } // Main loop bool done = false; while (!done) { - - // 2. Show a simple window that we create ourselves. We use a Begin/End pair to create a named window. - { - static int counter = 0; - - App::Stage *stage = osreApp.getStage(); - if (stage != nullptr) { - World *world = stage->getActiveWorld(0); - } - - } + done = !osreApp.handleEvents(); + osreApp.update(); + osreApp.requestNextFrame(); } - osreApp.handleEvents(); - osreApp.update(); - osreApp.requestNextFrame(); return 0; } diff --git a/src/Engine/App/AppBase.cpp b/src/Engine/App/AppBase.cpp index 5c824cb63..885a861a4 100644 --- a/src/Engine/App/AppBase.cpp +++ b/src/Engine/App/AppBase.cpp @@ -82,7 +82,7 @@ AppBase::~AppBase() { delete mSettings; } -bool AppBase::initWindow(ui32 x, ui32 y, ui32 width, ui32 height, const String &title, bool fullscreen, bool childWindow, +bool AppBase::initWindow(ui32 x, ui32 y, ui32 width, ui32 height, const String &title, WindowMode mode, WindowType type, RenderBackendType renderer) { osre_assert(nullptr != mSettings); @@ -90,8 +90,8 @@ bool AppBase::initWindow(ui32 x, ui32 y, ui32 width, ui32 height, const String & mSettings->setInt(Settings::WinY, y); mSettings->setInt(Settings::WinWidth, width); mSettings->setInt(Settings::WinHeight, height); - mSettings->setBool(Settings::FullScreen, fullscreen); - mSettings->setBool(Settings::ChildWindow, childWindow); + mSettings->setBool(Settings::FullScreen, mode == WindowMode::Fullscreen); + mSettings->setBool(Settings::ChildWindow, type == WindowType::Child); mSettings->setString(Settings::WindowsTitle, title); if (renderer == RenderBackendType::OpenGLRenderBackend) { mSettings->setString(Settings::RenderAPI, "opengl"); diff --git a/src/Engine/App/AppBase.h b/src/Engine/App/AppBase.h index 00f1fcb82..36275a498 100644 --- a/src/Engine/App/AppBase.h +++ b/src/Engine/App/AppBase.h @@ -103,6 +103,20 @@ class OSRE_EXPORT KeyboardEventListener : public Platform::OSEventListener { char mKeymap[Platform::KEY_LAST]; }; +enum class WindowMode { + Invalid, + Windowed, + Fullscreen, + Count +}; + +enum class WindowType { + Invalid, + Root, + Child, + Count +}; + //------------------------------------------------------------------------------------------------- /// @ingroup Engine /// @@ -143,7 +157,7 @@ class OSRE_EXPORT AppBase { /// @param[in] renderer The requested render mode. /// @return true, if the window was generated. virtual bool initWindow( ui32 x, ui32 y, ui32 width, ui32 height, const String &title, - bool fullscreen, bool childWindow, RenderBackendType renderer); + WindowMode mode, WindowType type, RenderBackendType renderer); /// @brief Creates the application. /// @param settings [in] The user-defined settings.