Use custom assert to hide private file information

This commit is contained in:
Nomango 2019-08-18 18:33:44 +08:00
parent 253548dafe
commit cb19ce830d
6 changed files with 32 additions and 33 deletions

View File

@ -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); HINSTANCE hinst = GetModuleHandleW(nullptr);
WNDCLASSEX wcex = { 0 }; WNDCLASSEX wcex = { 0 };
@ -157,16 +157,17 @@ namespace kiwano
if (handle_ == nullptr) if (handle_ == nullptr)
{ {
::UnregisterClass(KGE_WND_CLASS_NAME, hinst); ::UnregisterClass(KGE_WND_CLASS_NAME, hinst);
return HRESULT_FROM_WIN32(GetLastError()); ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
} }
else
{
RECT rc; RECT rc;
GetClientRect(handle_, &rc); GetClientRect(handle_, &rc);
width_ = rc.right - rc.left; width_ = rc.right - rc.left;
height_ = rc.bottom - rc.top; height_ = rc.bottom - rc.top;
SetMouseCursor(MouseCursor::Arrow); SetMouseCursor(MouseCursor::Arrow);
return S_OK; }
} }
void Window::Prepare() void Window::Prepare()

View File

@ -60,7 +60,7 @@ namespace kiwano
void SetMouseCursor(MouseCursor cursor); void SetMouseCursor(MouseCursor cursor);
public: public:
HRESULT Create( void Init(
String const& title, String const& title,
int width, int width,
int height, int height,

View File

@ -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); HINSTANCE hinst = GetModuleHandleW(nullptr);
WNDCLASSEX wcex = { 0 }; WNDCLASSEX wcex = { 0 };
@ -157,16 +157,17 @@ namespace kiwano
if (handle_ == nullptr) if (handle_ == nullptr)
{ {
::UnregisterClass(KGE_WND_CLASS_NAME, hinst); ::UnregisterClass(KGE_WND_CLASS_NAME, hinst);
return HRESULT_FROM_WIN32(GetLastError()); ThrowIfFailed(HRESULT_FROM_WIN32(GetLastError()));
} }
else
{
RECT rc; RECT rc;
GetClientRect(handle_, &rc); GetClientRect(handle_, &rc);
width_ = rc.right - rc.left; width_ = rc.right - rc.left;
height_ = rc.bottom - rc.top; height_ = rc.bottom - rc.top;
SetMouseCursor(MouseCursor::Arrow); SetMouseCursor(MouseCursor::Arrow);
return S_OK; }
} }
void Window::Prepare() void Window::Prepare()

View File

@ -60,7 +60,7 @@ namespace kiwano
void SetMouseCursor(MouseCursor cursor); void SetMouseCursor(MouseCursor cursor);
public: public:
HRESULT Create( void Init(
String const& title, String const& title,
int width, int width,
int height, int height,

View File

@ -87,7 +87,7 @@
#ifndef KGE_ASSERT #ifndef KGE_ASSERT
# ifdef KGE_DEBUG # 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 # else
# define KGE_ASSERT __noop # define KGE_ASSERT __noop
# endif # endif

View File

@ -80,15 +80,13 @@ namespace kiwano
void Application::Init(const Options& options) void Application::Init(const Options& options)
{ {
ThrowIfFailed( Window::GetInstance()->Init(
Window::GetInstance()->Create(
options.title, options.title,
options.width, options.width,
options.height, options.height,
options.icon, options.icon,
options.fullscreen, options.fullscreen,
Application::WndProc Application::WndProc
)
); );
Renderer::GetInstance()->SetClearColor(options.clear_color); Renderer::GetInstance()->SetClearColor(options.clear_color);
@ -122,10 +120,9 @@ namespace kiwano
void Application::Run() void Application::Run()
{ {
HWND hwnd = Window::GetInstance()->GetHandle(); KGE_ASSERT(inited_ && "Calling Application::Run before Application::Init");
if (!inited_) HWND hwnd = Window::GetInstance()->GetHandle();
throw std::exception("Calling Application::Run before Application::Init");
if (hwnd) if (hwnd)
{ {