Skip to content

Commit 08a3940

Browse files
committed
Fix for #17
1 parent 6e61301 commit 08a3940

File tree

1 file changed

+22
-36
lines changed

1 file changed

+22
-36
lines changed

daabbcc/src/extension.cpp

Lines changed: 22 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,9 @@
66
#include <daabbcc/daabbcc.h>
77
#include <dmsdk/sdk.h>
88

9+
#define RETURN_INVALID_GROUP_ERROR(name, id) \
10+
return DM_LUA_ERROR("%s: Group ID [%i] is invalid or already removed!", name, id)
11+
912
////////////////////////////////////////
1013
// Group Operations
1114
////////////////////////////////////////
@@ -35,8 +38,7 @@ static int RemoveGroup(lua_State* L)
3538
bool isSet = daabbcc::SetTreeGroup(groupID);
3639
if (!isSet)
3740
{
38-
daabbcc::ErrorAssert("RemoveGroup", groupID);
39-
return 0;
41+
RETURN_INVALID_GROUP_ERROR("daabbcc.remove_group()", groupID);
4042
}
4143

4244
daabbcc::RemoveGroup(groupID);
@@ -129,13 +131,12 @@ static inline void ManifoldResult(lua_State* L, uint32_t queryResultSize, dmArra
129131
static inline int QueryIDSort(lua_State* L)
130132
{
131133
DM_LUA_STACK_CHECK(L, 2);
132-
uint8_t groupID = luaL_checkint(L, 1);
133134

135+
uint8_t groupID = luaL_checkint(L, 1);
134136
bool isSet = daabbcc::SetTreeGroup(groupID);
135137
if (!isSet)
136138
{
137-
daabbcc::ErrorAssert("QueryIDSort", groupID);
138-
return 0;
139+
RETURN_INVALID_GROUP_ERROR("daabbcc.query_id_sort()", groupID);
139140
}
140141

141142
int32_t proxyID = luaL_checkint(L, 2);
@@ -183,13 +184,12 @@ static inline int QueryIDSort(lua_State* L)
183184
static int QueryAABBSort(lua_State* L)
184185
{
185186
DM_LUA_STACK_CHECK(L, 2);
186-
uint8_t groupID = luaL_checkint(L, 1);
187187

188+
uint8_t groupID = luaL_checkint(L, 1);
188189
bool isSet = daabbcc::SetTreeGroup(groupID);
189190
if (!isSet)
190191
{
191-
daabbcc::ErrorAssert("QueryAABBSort", groupID);
192-
return 0;
192+
RETURN_INVALID_GROUP_ERROR("daabbcc.query_aabb_sort()", groupID);
193193
}
194194

195195
float x = luaL_checknumber(L, 2);
@@ -242,13 +242,12 @@ static int QueryAABBSort(lua_State* L)
242242
static int QueryAABB(lua_State* L)
243243
{
244244
DM_LUA_STACK_CHECK(L, 2);
245-
uint8_t groupID = luaL_checkint(L, 1);
246245

246+
uint8_t groupID = luaL_checkint(L, 1);
247247
bool isSet = daabbcc::SetTreeGroup(groupID);
248248
if (!isSet)
249249
{
250-
daabbcc::ErrorAssert("QueryAABB", groupID);
251-
return 0;
250+
RETURN_INVALID_GROUP_ERROR("daabbcc.query_aabb()", groupID);
252251
}
253252

254253
float x = luaL_checknumber(L, 2);
@@ -310,12 +309,10 @@ static int QueryID(lua_State* L)
310309
DM_LUA_STACK_CHECK(L, 2);
311310

312311
uint8_t groupID = luaL_checkint(L, 1);
313-
314312
bool isSet = daabbcc::SetTreeGroup(groupID);
315313
if (!isSet)
316314
{
317-
daabbcc::ErrorAssert("QueryID", groupID);
318-
return 0;
315+
RETURN_INVALID_GROUP_ERROR("daabbcc.query_id()", groupID);
319316
}
320317

321318
int32_t proxyID = luaL_checkint(L, 2);
@@ -377,12 +374,10 @@ static int RayCast(lua_State* L)
377374
DM_LUA_STACK_CHECK(L, 2);
378375

379376
uint8_t groupID = luaL_checkint(L, 1);
380-
381377
bool isSet = daabbcc::SetTreeGroup(groupID);
382378
if (!isSet)
383379
{
384-
daabbcc::ErrorAssert("RayCast", groupID);
385-
return 0;
380+
RETURN_INVALID_GROUP_ERROR("daabbcc.raycast()", groupID);
386381
}
387382

388383
float start_x = luaL_checknumber(L, 2);
@@ -443,12 +438,10 @@ static int RayCastSort(lua_State* L)
443438
DM_LUA_STACK_CHECK(L, 2);
444439

445440
uint8_t groupID = luaL_checkint(L, 1);
446-
447441
bool isSet = daabbcc::SetTreeGroup(groupID);
448442
if (!isSet)
449443
{
450-
daabbcc::ErrorAssert("RayCast", groupID);
451-
return 0;
444+
RETURN_INVALID_GROUP_ERROR("daabbcc.raycast_sort()", groupID);
452445
}
453446

454447
float start_x = luaL_checknumber(L, 2);
@@ -502,13 +495,13 @@ static int RayCastSort(lua_State* L)
502495

503496
static int AddProxy(lua_State* L)
504497
{
505-
uint8_t groupID = luaL_checkint(L, 1);
498+
DM_LUA_STACK_CHECK(L, 1);
506499

500+
uint8_t groupID = luaL_checkint(L, 1);
507501
bool isSet = daabbcc::SetTreeGroup(groupID);
508502
if (!isSet)
509503
{
510-
daabbcc::ErrorAssert("AddProxy", groupID);
511-
return 0;
504+
RETURN_INVALID_GROUP_ERROR("daabbcc.insert_aabb()", groupID);
512505
}
513506

514507
float x = luaL_checknumber(L, 2);
@@ -531,15 +524,13 @@ static int AddProxy(lua_State* L)
531524

532525
static int AddGameObject(lua_State* L)
533526
{
534-
// DM_LUA_STACK_CHECK(L, 1);
527+
DM_LUA_STACK_CHECK(L, 1);
535528

536529
uint8_t groupID = luaL_checkint(L, 1);
537-
538530
bool isSet = daabbcc::SetTreeGroup(groupID);
539531
if (!isSet)
540532
{
541-
dmLogError("AddGameObject: Group ID %i is invalid or already removed!", groupID);
542-
return 0;
533+
RETURN_INVALID_GROUP_ERROR("daabbcc.insert_gameobject()", groupID);
543534
}
544535

545536
dmGameObject::HInstance gameobjectInstance = dmScript::CheckGOInstance(L, 2);
@@ -578,12 +569,10 @@ static int MoveProxy(lua_State* L)
578569
DM_LUA_STACK_CHECK(L, 0);
579570

580571
uint8_t groupID = luaL_checkint(L, 1);
581-
582572
bool isSet = daabbcc::SetTreeGroup(groupID);
583573
if (!isSet)
584574
{
585-
daabbcc::ErrorAssert("MoveProxy", groupID);
586-
return 0;
575+
RETURN_INVALID_GROUP_ERROR("daabbcc.update_aabb()", groupID);
587576
}
588577

589578
int32_t proxyID = luaL_checkint(L, 2);
@@ -606,8 +595,7 @@ static int UpdateGameobjectSize(lua_State* L)
606595
bool isSet = daabbcc::SetTreeGroup(groupID);
607596
if (!isSet)
608597
{
609-
daabbcc::ErrorAssert("UpdateGameobjectSize", groupID);
610-
return 0;
598+
RETURN_INVALID_GROUP_ERROR("daabbcc.update_gameobject_size()", groupID);
611599
}
612600

613601
int32_t proxyID = luaL_checkint(L, 2);
@@ -628,8 +616,7 @@ static int RemoveProxy(lua_State* L)
628616
bool isSet = daabbcc::SetTreeGroup(groupID);
629617
if (!isSet)
630618
{
631-
daabbcc::ErrorAssert("RemoveProxy", groupID);
632-
return 0;
619+
RETURN_INVALID_GROUP_ERROR("daabbcc.remove()", groupID);
633620
}
634621

635622
int32_t proxyID = luaL_checkint(L, 2);
@@ -679,8 +666,7 @@ static int Rebuild(lua_State* L)
679666
bool isSet = daabbcc::SetTreeGroup(groupID);
680667
if (!isSet)
681668
{
682-
daabbcc::ErrorAssert("Rebuild", groupID);
683-
return 0;
669+
RETURN_INVALID_GROUP_ERROR("daabbcc.rebuild()", groupID);
684670
}
685671

686672
bool fullBuild = lua_toboolean(L, 2);

0 commit comments

Comments
 (0)