[renderer] Clear the visibility components on scene reset

I don't know why it didn't happen during the demo loop, but going from
the start map to e1m1 caused a segfault due to the efrags for a lava
ball getting double freed (however, I do think it might be because the
ball passed through at least two leafs, while entities in the demos did
not). The double free was because SCR_NewScene (indirectly) freed all
the efrags without removing them from entities, and then the client code
deleting the entities caused the visibility components to get deleted
and thus the efrags freed a second time. Using ECS_RemoveEntities on the
visibility component ensures the entities don't have a visibility
component to remove when they are later deleted.
This commit is contained in:
Bill Currie 2022-11-17 21:57:53 +09:00
parent ac0079f872
commit 06f410b0b6
2 changed files with 6 additions and 5 deletions

View file

@ -102,15 +102,13 @@ R_ClearEfragChain (efrag_t *ef)
while (ef) {
prev = &ef->leaf->efrags;
while (1) {
walk = *prev;
if (!walk)
break;
while ((walk = *prev)) {
if (walk == ef) { // remove this fragment
*prev = ef->leafnext;
break;
} else
} else {
prev = &walk->leafnext;
}
}
old = ef;

View file

@ -470,6 +470,9 @@ SCR_Init (void)
void
SCR_NewScene (scene_t *scene)
{
if (scr_scene) {
ECS_RemoveEntities (scr_scene->reg, scene_visibility);
}
scr_scene = scene;
if (scene) {
mod_brush_t *brush = &scr_scene->worldmodel->brush;