From 79db960a89d80f148b97f3dbccbf67f3d0f4e6fc Mon Sep 17 00:00:00 2001 From: Lynix Date: Mon, 29 Aug 2016 02:33:57 +0200 Subject: [PATCH] SDK: Fix console layer having trouble with late constructed windows Former-commit-id: e5882089bc09649b545da8ea8a222b89417851a0 [formerly 1a114b80d1a97b96e764a2732ce8200244389283] [formerly f36d163b9d5a52c2958468dd26d9086b86c6710b [formerly 71b9edd9938eb30860da96234605a001173eaa23]] Former-commit-id: 8fd9120c8333c10f95d66d859eef2c64c58efc28 [formerly 423c0088ec020881cbf207470787d86929f34fd4] Former-commit-id: e283df698adfb17f2d40156ad411e9a6acac1f7a --- SDK/include/NDK/Application.hpp | 2 +- SDK/src/NDK/Application.cpp | 13 ++++++++++--- src/Nazara/Utility/Window.cpp | 18 ++++++++++-------- 3 files changed, 21 insertions(+), 12 deletions(-) diff --git a/SDK/include/NDK/Application.hpp b/SDK/include/NDK/Application.hpp index 84b331e95..8c0eb18a9 100644 --- a/SDK/include/NDK/Application.hpp +++ b/SDK/include/NDK/Application.hpp @@ -88,7 +88,7 @@ namespace Ndk NazaraSlot(Nz::EventHandler, OnEvent, eventSlot); NazaraSlot(Nz::EventHandler, OnKeyPressed, keyPressedSlot); - NazaraSlot(Nz::EventHandler, OnResized, resizedSlot); + NazaraSlot(Nz::RenderTarget, OnRenderTargetSizeChange, resizedSlot); NazaraSlot(Nz::Log, OnLogWrite, logSlot); }; diff --git a/SDK/src/NDK/Application.cpp b/SDK/src/NDK/Application.cpp index 8ecb5d454..68396f128 100644 --- a/SDK/src/NDK/Application.cpp +++ b/SDK/src/NDK/Application.cpp @@ -144,9 +144,16 @@ namespace Ndk { std::unique_ptr overlay = std::make_unique(); - overlay->console = std::make_unique(*info.overlayWorld, Nz::Vector2f(Nz::Vector2ui(info.window->GetWidth(), info.window->GetHeight() / 4)), overlay->lua); + Nz::Vector2ui windowDimensions; + if (info.window->IsValid()) + windowDimensions.Set(info.window->GetWidth(), info.window->GetHeight() / 4); + else + windowDimensions.MakeZero(); + + overlay->console = std::make_unique(*info.overlayWorld, Nz::Vector2f(windowDimensions), overlay->lua); Console& consoleRef = *overlay->console; + // Redirect logs toward the console overlay->logSlot.Connect(Nz::Log::OnLogWrite, [&consoleRef] (const Nz::String& str) { @@ -201,9 +208,9 @@ namespace Ndk consoleRef.Show(!consoleRef.IsVisible()); }); - overlay->resizedSlot.Connect(eventHandler.OnResized, [&consoleRef] (const Nz::EventHandler*, const Nz::WindowEvent::SizeEvent& event) + overlay->resizedSlot.Connect(info.renderTarget->OnRenderTargetSizeChange, [&consoleRef] (const Nz::RenderTarget* renderTarget) { - consoleRef.SetSize({float(event.width), event.height / 4.f}); + consoleRef.SetSize({float(renderTarget->GetWidth()), renderTarget->GetHeight() / 4.f}); }); info.console = std::move(overlay); diff --git a/src/Nazara/Utility/Window.cpp b/src/Nazara/Utility/Window.cpp index 02ed0f40a..7ba78dcb9 100644 --- a/src/Nazara/Utility/Window.cpp +++ b/src/Nazara/Utility/Window.cpp @@ -3,6 +3,7 @@ // For conditions of distribution and use, see copyright notice in Config.hpp #include +#include #include #include #include @@ -60,25 +61,22 @@ namespace Nz else if (style & WindowStyle_Closable || style & WindowStyle_Resizable) style |= WindowStyle_Titlebar; - m_impl = new WindowImpl(this); - if (!m_impl->Create(mode, title, style)) + std::unique_ptr impl = std::make_unique(this); + if (!impl->Create(mode, title, style)) { NazaraError("Failed to create window implementation"); - delete m_impl; - m_impl = nullptr; - return false; } + m_impl = impl.release(); + CallOnExit destroyOnFailure([this] () { Destroy(); }); + m_closed = false; m_ownsWindow = true; if (!OnWindowCreated()) { NazaraError("Failed to initialize window extension"); - delete m_impl; - m_impl = nullptr; - return false; } @@ -93,6 +91,10 @@ namespace Nz if (opened) m_impl->SetPosition(position.x, position.y); + OnWindowResized(); + + destroyOnFailure.Reset(); + return true; }