Puppylight crash fix

This commit is contained in:
Fazana
2021-09-10 12:16:58 +01:00
parent b80529d0e9
commit 72ad4966d0
2 changed files with 11 additions and 1 deletions

View File

@@ -20,6 +20,7 @@
#include "profiler.h"
#include "spawn_object.h"
#include "puppyprint.h"
#include "puppylights.h"
/**
@@ -386,6 +387,8 @@ s32 unload_deactivated_objects_in_list(struct ObjectNode *objList) {
obj = obj->next;
if ((gCurrentObject->activeFlags & ACTIVE_FLAG_ACTIVE) != ACTIVE_FLAG_ACTIVE) {
if (gCurrentObject->oLightID != 0xFFFF)
obj_disable_light(gCurrentObject);
// Prevent object from respawning after exiting and re-entering the
// area
if (!(gCurrentObject->oFlags & OBJ_FLAG_PERSISTENT_RESPAWN)) {

View File

@@ -187,6 +187,7 @@ void puppylights_iterate(struct PuppyLight *light, Lights1 *src, struct Object *
void puppylights_run(Lights1 *src, struct Object *obj, s32 flags, u32 baseColour)
{
s32 i;
s32 numlights = 0;
if (gCurrLevelNum < 4)
return;
@@ -222,7 +223,10 @@ void puppylights_run(Lights1 *src, struct Object *obj, s32 flags, u32 baseColour
for (i = 0; i < gNumLights; i++)
{
if (gPuppyLights[i]->rgba[3] > 0 && gPuppyLights[i]->active == TRUE && gPuppyLights[i]->area == gCurrAreaIndex && (gPuppyLights[i]->room == -1 || gPuppyLights[i]->room == gMarioCurrentRoom))
{
puppylights_iterate(gPuppyLights[i], src, obj);
numlights++;
}
}
}
@@ -248,7 +252,7 @@ void puppylights_object_emit(struct Object *obj)
{
if (ABS(gNumLights - gDynLightStart) < MAX_LIGHTS_DYNAMIC)
goto deallocate;
for (i = gDynLightStart; i < MAX_LIGHTS; i++)
for (i = gDynLightStart; i < MIN(gDynLightStart+MAX_LIGHTS_DYNAMIC, MAX_LIGHTS); i++)
{
if (gPuppyLights[i]->active == TRUE)
continue;
@@ -272,7 +276,10 @@ void puppylights_object_emit(struct Object *obj)
{
deallocate:
if (obj->oLightID != 0xFFFF)
{
gPuppyLights[obj->oLightID]->active = FALSE;
gPuppyLights[obj->oLightID]->flags = 0;
}
obj->oLightID = 0xFFFF;
}
}