add E2D_ASSERT
This commit is contained in:
parent
406ea51b57
commit
a29584f756
|
|
@ -32,8 +32,7 @@ namespace easy2d
|
||||||
, times_(0)
|
, times_(0)
|
||||||
, total_times_(times)
|
, total_times_(times)
|
||||||
{
|
{
|
||||||
if (!action)
|
E2D_ASSERT(action && "Loop action contains a null action");
|
||||||
logs::Warningln("Loop action contains a null action");
|
|
||||||
|
|
||||||
action_ = action;
|
action_ = action;
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -43,8 +43,7 @@ namespace easy2d
|
||||||
|
|
||||||
void ActionManager::AddAction(spAction const& action)
|
void ActionManager::AddAction(spAction const& action)
|
||||||
{
|
{
|
||||||
if (!action)
|
E2D_ASSERT(action && "AddAction failed, NULL pointer exception");
|
||||||
logs::Warningln("AddAction failed, action is nullptr");
|
|
||||||
|
|
||||||
if (action)
|
if (action)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,7 @@ namespace easy2d
|
||||||
|
|
||||||
void EventDispatcher::AddListener(spEventListener const & listener)
|
void EventDispatcher::AddListener(spEventListener const & listener)
|
||||||
{
|
{
|
||||||
if (!listener)
|
E2D_ASSERT(listener && "AddListener failed, NULL pointer exception");
|
||||||
logs::Warningln("AddListener failed, action is nullptr");
|
|
||||||
|
|
||||||
if (listener)
|
if (listener)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -57,8 +57,7 @@ namespace easy2d
|
||||||
|
|
||||||
void Frames::Add(spImage const& frame)
|
void Frames::Add(spImage const& frame)
|
||||||
{
|
{
|
||||||
if (!frame)
|
E2D_ASSERT(frame && "Frames::Add failed, NULL pointer exception");
|
||||||
logs::Warningln("Frames::Add failed, frame is nullptr.");
|
|
||||||
|
|
||||||
if (frame)
|
if (frame)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -156,8 +156,7 @@ namespace easy2d
|
||||||
|
|
||||||
void Game::EnterScene(spScene const & scene)
|
void Game::EnterScene(spScene const & scene)
|
||||||
{
|
{
|
||||||
if (!scene)
|
E2D_ASSERT(scene && "Game::EnterScene failed, NULL pointer exception");
|
||||||
logs::Warningln("Game::EnterScene failed, scene is nullptr");
|
|
||||||
|
|
||||||
if (curr_scene_ == scene || next_scene_ == scene)
|
if (curr_scene_ == scene || next_scene_ == scene)
|
||||||
return;
|
return;
|
||||||
|
|
@ -450,22 +449,13 @@ namespace easy2d
|
||||||
|
|
||||||
LRESULT CALLBACK Game::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
LRESULT CALLBACK Game::WndProc(HWND hwnd, UINT msg, WPARAM wparam, LPARAM lparam)
|
||||||
{
|
{
|
||||||
LRESULT result = 0;
|
|
||||||
bool was_handled = false;
|
|
||||||
|
|
||||||
Game * game = reinterpret_cast<Game*>(
|
Game * game = reinterpret_cast<Game*>(
|
||||||
static_cast<LONG_PTR>(::GetWindowLongW(hwnd, GWLP_USERDATA))
|
static_cast<LONG_PTR>(::GetWindowLongW(hwnd, GWLP_USERDATA))
|
||||||
);
|
);
|
||||||
|
|
||||||
if (game)
|
if (game && game->HandleMessage(hwnd, msg, wparam, lparam))
|
||||||
{
|
return 0;
|
||||||
was_handled = game->HandleMessage(hwnd, msg, wparam, lparam);
|
|
||||||
}
|
|
||||||
|
|
||||||
if (!was_handled)
|
return ::DefWindowProcW(hwnd, msg, wparam, lparam);
|
||||||
{
|
|
||||||
result = ::DefWindowProcW(hwnd, msg, wparam, lparam);
|
|
||||||
}
|
|
||||||
return result;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -71,6 +71,10 @@ namespace easy2d
|
||||||
if (geometry_ && geometry_->geo_)
|
if (geometry_ && geometry_->geo_)
|
||||||
{
|
{
|
||||||
auto graphics = Graphics::Instance();
|
auto graphics = Graphics::Instance();
|
||||||
|
|
||||||
|
if (geometry_->GetTransformMatrix().IsIdentity())
|
||||||
|
graphics->SetTransform(GetTransformMatrix());
|
||||||
|
else
|
||||||
graphics->SetTransform(geometry_->GetTransformMatrix() * GetTransformMatrix());
|
graphics->SetTransform(geometry_->GetTransformMatrix() * GetTransformMatrix());
|
||||||
|
|
||||||
graphics->FillGeometry(
|
graphics->FillGeometry(
|
||||||
|
|
|
||||||
|
|
@ -388,8 +388,7 @@ namespace easy2d
|
||||||
|
|
||||||
void Node::AddChild(spNode const& child, int z_order)
|
void Node::AddChild(spNode const& child, int z_order)
|
||||||
{
|
{
|
||||||
if (!child)
|
E2D_ASSERT(child && "Node::AddChild failed, NULL pointer exception");
|
||||||
logs::Warningln("Node::AddChild failed, child is nullptr");
|
|
||||||
|
|
||||||
if (child)
|
if (child)
|
||||||
{
|
{
|
||||||
|
|
@ -472,8 +471,7 @@ namespace easy2d
|
||||||
|
|
||||||
bool Node::RemoveChild(spNode const& child)
|
bool Node::RemoveChild(spNode const& child)
|
||||||
{
|
{
|
||||||
if (!child)
|
E2D_ASSERT(child && "Node::RemoveChild failed, NULL pointer exception");
|
||||||
logs::Warningln("Node::RemoveChild failed, child is nullptr");
|
|
||||||
|
|
||||||
if (children_.IsEmpty())
|
if (children_.IsEmpty())
|
||||||
return false;
|
return false;
|
||||||
|
|
|
||||||
|
|
@ -42,8 +42,7 @@ namespace easy2d
|
||||||
|
|
||||||
void TaskManager::AddTask(spTask const& task)
|
void TaskManager::AddTask(spTask const& task)
|
||||||
{
|
{
|
||||||
if (!task)
|
E2D_ASSERT(task && "AddTask failed, NULL pointer exception");
|
||||||
logs::Warningln("AddTask failed, task is nullptr");
|
|
||||||
|
|
||||||
if (task)
|
if (task)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -24,7 +24,6 @@
|
||||||
#include "ObjectBase.h"
|
#include "ObjectBase.h"
|
||||||
#include "intrusive/SmartPointer.hpp"
|
#include "intrusive/SmartPointer.hpp"
|
||||||
#include "d2dres.hpp"
|
#include "d2dres.hpp"
|
||||||
#include <assert.h>
|
|
||||||
|
|
||||||
#ifndef E2D_DECLARE_SMART_PTR
|
#ifndef E2D_DECLARE_SMART_PTR
|
||||||
#define E2D_DECLARE_SMART_PTR(class_name)\
|
#define E2D_DECLARE_SMART_PTR(class_name)\
|
||||||
|
|
@ -92,4 +91,20 @@ namespace easy2d
|
||||||
|
|
||||||
E2D_DECLARE_NS_SMART_PTR(ui, Button);
|
E2D_DECLARE_NS_SMART_PTR(ui, Button);
|
||||||
E2D_DECLARE_NS_SMART_PTR(ui, Menu);
|
E2D_DECLARE_NS_SMART_PTR(ui, Menu);
|
||||||
|
|
||||||
|
|
||||||
|
template <typename Dest, typename Src>
|
||||||
|
inline Dest* SafeCast(Src* ptr)
|
||||||
|
{
|
||||||
|
if (!ptr)
|
||||||
|
return nullptr;
|
||||||
|
|
||||||
|
#ifdef E2D_DEBUG
|
||||||
|
Dest* cast = dynamic_cast<Dest*>(ptr);
|
||||||
|
E2D_ASSERT(cast);
|
||||||
|
return cast;
|
||||||
|
#endif
|
||||||
|
|
||||||
|
return static_cast<Dest*>(ptr);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -19,7 +19,7 @@
|
||||||
// THE SOFTWARE.
|
// THE SOFTWARE.
|
||||||
|
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <stdexcept>
|
#include "../macros.h"
|
||||||
#include <functional>
|
#include <functional>
|
||||||
|
|
||||||
#undef DEBUG_CHECK_LIST
|
#undef DEBUG_CHECK_LIST
|
||||||
|
|
@ -156,7 +156,7 @@ namespace easy2d
|
||||||
while (tmp != child)
|
while (tmp != child)
|
||||||
{
|
{
|
||||||
if (tmp == last_)
|
if (tmp == last_)
|
||||||
throw std::logic_error("The node to be removed is not in this list");
|
E2D_ASSERT(false && "The node to be removed is not in this list");
|
||||||
tmp = tmp->next_;
|
tmp = tmp->next_;
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
@ -218,14 +218,14 @@ namespace easy2d
|
||||||
for (size_t i = 0; i < size; ++i)
|
for (size_t i = 0; i < size; ++i)
|
||||||
{
|
{
|
||||||
if (i == 0)
|
if (i == 0)
|
||||||
temp_vec[i]->prev_ = ItemType();
|
temp_vec[i]->prev_ = nullptr;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
temp_vec[i]->prev_ = temp_vec[i - 1];
|
temp_vec[i]->prev_ = temp_vec[i - 1];
|
||||||
temp_vec[i - 1]->next_ = temp_vec[i];
|
temp_vec[i - 1]->next_ = temp_vec[i];
|
||||||
}
|
}
|
||||||
if (i == size - 1)
|
if (i == size - 1)
|
||||||
temp_vec[i]->next_ = ItemType();
|
temp_vec[i]->next_ = nullptr;
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
temp_vec[i]->next_ = temp_vec[i + 1];
|
temp_vec[i]->next_ = temp_vec[i + 1];
|
||||||
|
|
@ -257,13 +257,11 @@ namespace easy2d
|
||||||
|
|
||||||
if (p)
|
if (p)
|
||||||
{
|
{
|
||||||
if (p->prev_ != tmp)
|
E2D_ASSERT(p->prev_ == tmp && "Check list failed");
|
||||||
throw std::logic_error("Check list failed");
|
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
{
|
{
|
||||||
if (tmp != last_)
|
E2D_ASSERT(tmp == last_ && "Check list failed");
|
||||||
throw std::logic_error("Check list failed");
|
|
||||||
}
|
}
|
||||||
} while (p);
|
} while (p);
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -22,14 +22,6 @@
|
||||||
#include "../macros.h"
|
#include "../macros.h"
|
||||||
#include <utility>
|
#include <utility>
|
||||||
|
|
||||||
#ifndef E2D_INTRUSIVE_PTR_ASSERT
|
|
||||||
# ifdef E2D_DEBUG
|
|
||||||
# define E2D_INTRUSIVE_PTR_ASSERT(expr, msg) do { if (!(expr)) throw std::runtime_error(msg); } while(0);
|
|
||||||
# else
|
|
||||||
# define E2D_INTRUSIVE_PTR_ASSERT __noop
|
|
||||||
# endif
|
|
||||||
#endif
|
|
||||||
|
|
||||||
namespace easy2d
|
namespace easy2d
|
||||||
{
|
{
|
||||||
namespace intrusive
|
namespace intrusive
|
||||||
|
|
@ -82,19 +74,19 @@ namespace easy2d
|
||||||
|
|
||||||
inline Type* operator ->() const
|
inline Type* operator ->() const
|
||||||
{
|
{
|
||||||
E2D_INTRUSIVE_PTR_ASSERT(ptr_ != nullptr, "Invalid pointer");
|
E2D_ASSERT(ptr_ != nullptr, "Invalid pointer");
|
||||||
return ptr_;
|
return ptr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Type& operator *() const
|
inline Type& operator *() const
|
||||||
{
|
{
|
||||||
E2D_INTRUSIVE_PTR_ASSERT(ptr_ != nullptr, "Invalid pointer");
|
E2D_ASSERT(ptr_ != nullptr, "Invalid pointer");
|
||||||
return *ptr_;
|
return *ptr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
inline Type** operator &()
|
inline Type** operator &()
|
||||||
{
|
{
|
||||||
E2D_INTRUSIVE_PTR_ASSERT(ptr_ == nullptr, "Memory leak");
|
E2D_ASSERT(ptr_ == nullptr, "Memory leak");
|
||||||
return &ptr_;
|
return &ptr_;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -82,6 +82,7 @@
|
||||||
#include <wincodec.h>
|
#include <wincodec.h>
|
||||||
|
|
||||||
// C++ RunTime Header Files
|
// C++ RunTime Header Files
|
||||||
|
#include <cstdlib>
|
||||||
#include <string>
|
#include <string>
|
||||||
#include <map>
|
#include <map>
|
||||||
#include <set>
|
#include <set>
|
||||||
|
|
@ -97,3 +98,12 @@
|
||||||
# define E2D_NOEXCEPT throw()
|
# define E2D_NOEXCEPT throw()
|
||||||
# define E2D_CONSTEXPR const
|
# define E2D_CONSTEXPR const
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
|
#ifndef E2D_ASSERT
|
||||||
|
# ifdef E2D_DEBUG
|
||||||
|
# define E2D_ASSERT(expr) if (!(expr)) { ::OutputDebugStringA("[easy2d] Assert failed: " #expr "\n"); abort(); }
|
||||||
|
# else
|
||||||
|
# define E2D_ASSERT __noop
|
||||||
|
# endif
|
||||||
|
#endif
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue