mirror of
https://github.com/coop-deluxe/sm64coopdx.git
synced 2024-11-22 03:55:11 +00:00
Prevent rending of corrupted graphnodes, only run lua GC once per frame
This commit is contained in:
parent
ab585db973
commit
18bf5847a2
14 changed files with 87 additions and 8 deletions
|
@ -80,6 +80,7 @@ override_field_invisible = {
|
|||
"Mod": [ "files" ],
|
||||
"MarioState": [ "visibleToEnemies" ],
|
||||
"NetworkPlayer": [ "gag"],
|
||||
"GraphNode": [ "_guard1", "_guard2" ],
|
||||
}
|
||||
|
||||
override_field_immutable = {
|
||||
|
|
|
@ -11490,6 +11490,9 @@ COOP_OBJ_FLAG_NETWORK = (1 << 0)
|
|||
--- @type integer
|
||||
COOP_OBJ_FLAG_NON_SYNC = (1 << 2)
|
||||
|
||||
--- @type integer
|
||||
GRAPH_NODE_GUARD = 0xAA
|
||||
|
||||
--- @type integer
|
||||
MAX_PLAYERS = 16
|
||||
|
||||
|
|
|
@ -8371,6 +8371,11 @@ function camera_is_frozen()
|
|||
-- ...
|
||||
end
|
||||
|
||||
--- @return nil
|
||||
function camera_reset_overrides()
|
||||
-- ...
|
||||
end
|
||||
|
||||
--- @return nil
|
||||
function camera_unfreeze()
|
||||
-- ...
|
||||
|
|
|
@ -4068,6 +4068,7 @@
|
|||
- COOP_OBJ_FLAG_LUA
|
||||
- COOP_OBJ_FLAG_NETWORK
|
||||
- COOP_OBJ_FLAG_NON_SYNC
|
||||
- GRAPH_NODE_GUARD
|
||||
- MAX_PLAYERS
|
||||
- OBJECT_MAX_BHV_STACK
|
||||
- PLAY_MODE_CHANGE_AREA
|
||||
|
|
|
@ -470,6 +470,24 @@
|
|||
|
||||
<br />
|
||||
|
||||
## [camera_reset_overrides](#camera_reset_overrides)
|
||||
|
||||
### Lua Example
|
||||
`camera_reset_overrides()`
|
||||
|
||||
### Parameters
|
||||
- None
|
||||
|
||||
### Returns
|
||||
- None
|
||||
|
||||
### C Prototype
|
||||
`void camera_reset_overrides(void);`
|
||||
|
||||
[:arrow_up_small:](#)
|
||||
|
||||
<br />
|
||||
|
||||
## [camera_unfreeze](#camera_unfreeze)
|
||||
|
||||
### Lua Example
|
||||
|
|
|
@ -1562,6 +1562,7 @@
|
|||
- [camera_config_set_y_sensitivity](functions-5.md#camera_config_set_y_sensitivity)
|
||||
- [camera_freeze](functions-5.md#camera_freeze)
|
||||
- [camera_is_frozen](functions-5.md#camera_is_frozen)
|
||||
- [camera_reset_overrides](functions-5.md#camera_reset_overrides)
|
||||
- [camera_unfreeze](functions-5.md#camera_unfreeze)
|
||||
- [course_is_main_course](functions-5.md#course_is_main_course)
|
||||
- [deref_s32_pointer](functions-5.md#deref_s32_pointer)
|
||||
|
|
|
@ -114,16 +114,20 @@ struct AnimationTable {
|
|||
|
||||
#define ANIMINDEX_NUMPARTS(animindex) (sizeof(animindex) / sizeof(u16) / 6 - 1)
|
||||
|
||||
#define GRAPH_NODE_GUARD 0xAA
|
||||
|
||||
struct GraphNode
|
||||
{
|
||||
/*0x00*/ s16 type; // structure type
|
||||
/*0x02*/ s16 flags; // hi = drawing layer, lo = rendering modes
|
||||
/*0x04*/ struct GraphNode *prev;
|
||||
/*0x08*/ struct GraphNode *next;
|
||||
/*0x0C*/ struct GraphNode *parent;
|
||||
/*0x10*/ struct GraphNode *children;
|
||||
/*0x14*/ const void *georef;
|
||||
/*????*/ u8 extraFlags;
|
||||
s16 type; // structure type
|
||||
s16 flags; // hi = drawing layer, lo = rendering modes
|
||||
struct GraphNode *prev;
|
||||
u8 _guard1;
|
||||
struct GraphNode *next;
|
||||
u8 _guard2;
|
||||
struct GraphNode *parent;
|
||||
struct GraphNode *children;
|
||||
const void *georef;
|
||||
u8 extraFlags;
|
||||
};
|
||||
|
||||
struct AnimInfo
|
||||
|
|
|
@ -33,6 +33,8 @@ void init_scene_graph_node_links(struct GraphNode *graphNode, s32 type) {
|
|||
graphNode->parent = NULL;
|
||||
graphNode->children = NULL;
|
||||
graphNode->georef = NULL;
|
||||
graphNode->_guard1 = GRAPH_NODE_GUARD;
|
||||
graphNode->_guard2 = GRAPH_NODE_GUARD;
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1677,6 +1677,7 @@ s32 update_level(void) {
|
|||
}
|
||||
|
||||
s32 init_level(void) {
|
||||
sync_objects_clear();
|
||||
reset_dialog_render_state();
|
||||
|
||||
s32 val4 = 0;
|
||||
|
|
|
@ -58,6 +58,23 @@ void dynamic_pool_free(struct DynamicPool *pool, void* ptr) {
|
|||
LOG_ERROR("Failed to find memory to free in dynamic pool: %p", ptr);
|
||||
}
|
||||
|
||||
bool dynamic_pool_contains(struct DynamicPool *pool, void* ptr) {
|
||||
if (!pool || !ptr) { return false; }
|
||||
|
||||
struct DynamicPoolNode* node = pool->tail;
|
||||
struct DynamicPoolNode* next = node;
|
||||
|
||||
while (node) {
|
||||
struct DynamicPoolNode* prev = node->prev;
|
||||
if (node->ptr == ptr) {
|
||||
return true;
|
||||
}
|
||||
next = node;
|
||||
node = prev;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
void dynamic_pool_free_pool(struct DynamicPool *pool) {
|
||||
if (!pool) { return; }
|
||||
struct DynamicPoolNode* node = pool->tail;
|
||||
|
|
|
@ -1503,6 +1503,11 @@ void geo_process_node_and_siblings(struct GraphNode *firstNode) {
|
|||
break;
|
||||
}
|
||||
|
||||
if (curGraphNode->_guard1 != GRAPH_NODE_GUARD || curGraphNode->_guard2 != GRAPH_NODE_GUARD) {
|
||||
LOG_ERROR("Graph Node corrupted!");
|
||||
break;
|
||||
}
|
||||
|
||||
// Sanity check our stack index, If we above or equal to our stack size. Return to prevent OOB\.
|
||||
if ((gMatStackIndex + 1) >= MATRIX_STACK_SIZE) { break; }
|
||||
|
||||
|
|
|
@ -39,7 +39,9 @@ int smlua_pcall(lua_State* L, int nargs, int nresults, UNUSED int errfunc) {
|
|||
lua_pushcfunction(L, smlua_error_handler);
|
||||
int errorHandlerIndex = 1;
|
||||
lua_insert(L, errorHandlerIndex);
|
||||
|
||||
int rc = lua_pcall(L, nargs, nresults, errorHandlerIndex);
|
||||
|
||||
lua_remove(L, errorHandlerIndex);
|
||||
return rc;
|
||||
}
|
||||
|
@ -113,6 +115,7 @@ static void smlua_load_script(struct Mod* mod, struct ModFile* file, u16 remoteI
|
|||
}
|
||||
|
||||
// run chunks
|
||||
LOG_INFO("Executing '%s'", file->relativePath);
|
||||
if (smlua_pcall(L, 0, LUA_MULTRET, 0) != LUA_OK) {
|
||||
LOG_LUA("Failed to execute lua script '%s'.", file->cachedPath);
|
||||
LOG_LUA("%s", smlua_to_string(L, lua_gettop(L)));
|
||||
|
@ -187,6 +190,7 @@ void smlua_update(void) {
|
|||
// Collect our garbage after calling our hooks.
|
||||
// If we don't, Lag can quickly build up from our mods.
|
||||
lua_gc(L, LUA_GCCOLLECT, 0);
|
||||
lua_gc(L, LUA_GCSTOP, 0);
|
||||
}
|
||||
|
||||
void smlua_shutdown(void) {
|
||||
|
|
|
@ -4012,6 +4012,7 @@ char gSmluaConstants[] = ""
|
|||
"ANIM_FLAG_5 = (1 << 5)\n"
|
||||
"ANIM_FLAG_6 = (1 << 6)\n"
|
||||
"ANIM_FLAG_7 = (1 << 7)\n"
|
||||
"GRAPH_NODE_GUARD = 0xAA\n"
|
||||
"PLAY_MODE_NORMAL = 0\n"
|
||||
"PLAY_MODE_PAUSED = 2\n"
|
||||
"PLAY_MODE_CHANGE_AREA = 3\n"
|
||||
|
|
|
@ -27820,6 +27820,21 @@ int smlua_func_camera_is_frozen(UNUSED lua_State* L) {
|
|||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_camera_reset_overrides(UNUSED lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
int top = lua_gettop(L);
|
||||
if (top != 0) {
|
||||
LOG_LUA_LINE("Improper param count for '%s': Expected %u, Received %u", "camera_reset_overrides", 0, top);
|
||||
return 0;
|
||||
}
|
||||
|
||||
|
||||
camera_reset_overrides();
|
||||
|
||||
return 1;
|
||||
}
|
||||
|
||||
int smlua_func_camera_unfreeze(UNUSED lua_State* L) {
|
||||
if (L == NULL) { return 0; }
|
||||
|
||||
|
@ -31515,6 +31530,7 @@ void smlua_bind_functions_autogen(void) {
|
|||
smlua_bind_function(L, "camera_config_set_y_sensitivity", smlua_func_camera_config_set_y_sensitivity);
|
||||
smlua_bind_function(L, "camera_freeze", smlua_func_camera_freeze);
|
||||
smlua_bind_function(L, "camera_is_frozen", smlua_func_camera_is_frozen);
|
||||
smlua_bind_function(L, "camera_reset_overrides", smlua_func_camera_reset_overrides);
|
||||
smlua_bind_function(L, "camera_unfreeze", smlua_func_camera_unfreeze);
|
||||
smlua_bind_function(L, "course_is_main_course", smlua_func_course_is_main_course);
|
||||
smlua_bind_function(L, "deref_s32_pointer", smlua_func_deref_s32_pointer);
|
||||
|
|
Loading…
Reference in a new issue