diff --git a/src/kiwano/base/Window.cpp b/src/kiwano/base/Window.cpp index bc2a5f80..00afa86c 100644 --- a/src/kiwano/base/Window.cpp +++ b/src/kiwano/base/Window.cpp @@ -66,7 +66,7 @@ namespace kiwano } } - HRESULT Window::Create(String const& title, int width, int height, LPCWSTR icon, bool fullscreen, WNDPROC proc) + void Window::Init(String const& title, int width, int height, LPCWSTR icon, bool fullscreen, WNDPROC proc) { HINSTANCE hinst = GetModuleHandleW(nullptr); WNDCLASSEX wcex = { 0 }; @@ -157,16 +157,17 @@ namespace kiwano if (handle_ == nullptr) { ::UnregisterClass(KGE_WND_CLASS_NAME, hinst); - return HRESULT_FROM_WIN32(GetLastError()); + ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError())); } + else + { + RECT rc; + GetClientRect(handle_, &rc); + width_ = rc.right - rc.left; + height_ = rc.bottom - rc.top; - RECT rc; - GetClientRect(handle_, &rc); - width_ = rc.right - rc.left; - height_ = rc.bottom - rc.top; - - SetMouseCursor(MouseCursor::Arrow); - return S_OK; + SetMouseCursor(MouseCursor::Arrow); + } } void Window::Prepare() diff --git a/src/kiwano/base/Window.h b/src/kiwano/base/Window.h index 3513ba20..19cf280a 100644 --- a/src/kiwano/base/Window.h +++ b/src/kiwano/base/Window.h @@ -60,7 +60,7 @@ namespace kiwano void SetMouseCursor(MouseCursor cursor); public: - HRESULT Create( + void Init( String const& title, int width, int height, diff --git a/src/kiwano/base/window.cpp b/src/kiwano/base/window.cpp index bc2a5f80..00afa86c 100644 --- a/src/kiwano/base/window.cpp +++ b/src/kiwano/base/window.cpp @@ -66,7 +66,7 @@ namespace kiwano } } - HRESULT Window::Create(String const& title, int width, int height, LPCWSTR icon, bool fullscreen, WNDPROC proc) + void Window::Init(String const& title, int width, int height, LPCWSTR icon, bool fullscreen, WNDPROC proc) { HINSTANCE hinst = GetModuleHandleW(nullptr); WNDCLASSEX wcex = { 0 }; @@ -157,16 +157,17 @@ namespace kiwano if (handle_ == nullptr) { ::UnregisterClass(KGE_WND_CLASS_NAME, hinst); - return HRESULT_FROM_WIN32(GetLastError()); + ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError())); } + else + { + RECT rc; + GetClientRect(handle_, &rc); + width_ = rc.right - rc.left; + height_ = rc.bottom - rc.top; - RECT rc; - GetClientRect(handle_, &rc); - width_ = rc.right - rc.left; - height_ = rc.bottom - rc.top; - - SetMouseCursor(MouseCursor::Arrow); - return S_OK; + SetMouseCursor(MouseCursor::Arrow); + } } void Window::Prepare() diff --git a/src/kiwano/base/window.h b/src/kiwano/base/window.h index 3513ba20..19cf280a 100644 --- a/src/kiwano/base/window.h +++ b/src/kiwano/base/window.h @@ -60,7 +60,7 @@ namespace kiwano void SetMouseCursor(MouseCursor cursor); public: - HRESULT Create( + void Init( String const& title, int width, int height, diff --git a/src/kiwano/macros.h b/src/kiwano/macros.h index 25260d3b..a9fa0c46 100644 --- a/src/kiwano/macros.h +++ b/src/kiwano/macros.h @@ -87,7 +87,7 @@ #ifndef KGE_ASSERT # ifdef KGE_DEBUG -# define KGE_ASSERT(EXPR) assert(EXPR) +# define KGE_ASSERT(EXPR) do { (void)((!!(EXPR)) || (_wassert(_CRT_WIDE(#EXPR), _CRT_WIDE(__FUNCTION__), (unsigned)(__LINE__)), 0)); } while(0) # else # define KGE_ASSERT __noop # endif diff --git a/src/kiwano/platform/Application.cpp b/src/kiwano/platform/Application.cpp index 157f1a29..31f2997c 100644 --- a/src/kiwano/platform/Application.cpp +++ b/src/kiwano/platform/Application.cpp @@ -80,15 +80,13 @@ namespace kiwano void Application::Init(const Options& options) { - ThrowIfFailed( - Window::GetInstance()->Create( - options.title, - options.width, - options.height, - options.icon, - options.fullscreen, - Application::WndProc - ) + Window::GetInstance()->Init( + options.title, + options.width, + options.height, + options.icon, + options.fullscreen, + Application::WndProc ); Renderer::GetInstance()->SetClearColor(options.clear_color); @@ -122,10 +120,9 @@ namespace kiwano void Application::Run() { - HWND hwnd = Window::GetInstance()->GetHandle(); + KGE_ASSERT(inited_ && "Calling Application::Run before Application::Init"); - if (!inited_) - throw std::exception("Calling Application::Run before Application::Init"); + HWND hwnd = Window::GetInstance()->GetHandle(); if (hwnd) {