Skip to content

Commit 7651718

Browse files
author
nitrocaster
committed
Fix invalid smart casts.
1 parent d33f8d2 commit 7651718

File tree

3 files changed

+9
-9
lines changed

3 files changed

+9
-9
lines changed

src/xrGame/GameObject.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ extern MagicBox3 MagicMinBox (int iQuantity, const Fvector* akPoint);
4747

4848
ENGINE_API bool g_dedicated_server;
4949

50-
CGameObject::CGameObject ()
50+
CGameObject::CGameObject () : scriptBinder(this)
5151
{
5252
// CUsableScriptObject init
5353
m_bNonscriptUsable = true;

src/xrGame/script_binder.cpp

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -19,8 +19,9 @@
1919
// comment next string when commiting
2020
//#define DBG_DISABLE_SCRIPTS
2121

22-
CScriptBinder::CScriptBinder ()
22+
CScriptBinder::CScriptBinder (CGameObject *owner)
2323
{
24+
this->owner = owner;
2425
init ();
2526
}
2627

@@ -87,10 +88,8 @@ void CScriptBinder::reload (LPCSTR section)
8788
return;
8889
}
8990

90-
CGameObject *game_object = smart_cast<CGameObject*>(this);
91-
9291
try {
93-
lua_function (game_object ? game_object->lua_game_object() : 0);
92+
lua_function (owner->lua_game_object());
9493
}
9594
catch(...) {
9695
clear ();
@@ -148,7 +147,7 @@ void CScriptBinder::net_Destroy ()
148147
{
149148
if (m_object) {
150149
#ifdef _DEBUG
151-
Msg ("* Core object %s is UNbinded from the script object",smart_cast<CGameObject*>(this) ? *smart_cast<CGameObject*>(this)->cName() : "");
150+
Msg ("* Core object %s is UNbinded from the script object", owner->cName());
152151
#endif // _DEBUG
153152
try {
154153
m_object->net_Destroy ();
@@ -165,7 +164,7 @@ void CScriptBinder::set_object (CScriptBinderObject *object)
165164
if (IsGameTypeSingle()) {
166165
VERIFY2 (!m_object,"Cannot bind to the object twice!");
167166
#ifdef _DEBUG
168-
Msg ("* Core object %s is binded with the script object",smart_cast<CGameObject*>(this) ? *smart_cast<CGameObject*>(this)->cName() : "");
167+
Msg ("* Core object %s is binded with the script object", owner->cName());
169168
#endif // _DEBUG
170169
m_object = object;
171170
} else {

src/xrGame/script_binder.h

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,14 @@
1111
class CSE_Abstract;
1212
class CScriptBinderObject;
1313
class NET_Packet;
14+
class CGameObject;
1415

1516
class CScriptBinder {
1617
protected:
1718
CScriptBinderObject *m_object;
18-
19+
CGameObject *owner;
1920
public:
20-
CScriptBinder ();
21+
CScriptBinder (CGameObject *owner);
2122
virtual ~CScriptBinder ();
2223
void init ();
2324
void clear ();

0 commit comments

Comments
 (0)