Fix water runner interaction

- Add null check for bbox for moveable check
- Null after free when freeing runner
scene_man
En Yi 2023-07-25 20:43:39 +08:00
parent f81029b482
commit 2e368704ce
2 changed files with 18 additions and 4 deletions

View File

@ -1028,13 +1028,19 @@ void moveable_update_system(Scene_t* scene)
{
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
any_solid |= p_other_bbox->solid;
if (p_other_bbox != NULL)
{
any_solid |= p_other_bbox->solid;
}
}
sc_map_foreach_key(&tilemap.tiles[tile_idx2].entities_set, idx_to_check)
{
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
any_solid |= p_other_bbox->solid;
if (p_other_bbox != NULL)
{
any_solid |= p_other_bbox->solid;
}
}
if (!any_solid)
{
@ -1057,13 +1063,19 @@ void moveable_update_system(Scene_t* scene)
{
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
any_solid |= p_other_bbox->solid;
if (p_other_bbox != NULL)
{
any_solid |= p_other_bbox->solid;
}
}
sc_map_foreach_key(&tilemap.tiles[tile_idx2].entities_set, idx_to_check)
{
Entity_t* other_ent = get_entity(&scene->ent_manager, idx_to_check);
CBBox_t* p_other_bbox = get_component(other_ent, CBBOX_COMP_T);
any_solid |= p_other_bbox->solid;
if (p_other_bbox != NULL)
{
any_solid |= p_other_bbox->solid;
}
}
if (!any_solid)
{

View File

@ -40,7 +40,9 @@ void free_water_runner(Entity_t* ent, EntityManager_t* ent_manager)
{
CWaterRunner_t* p_crunner = get_component(ent, CWATERRUNNER_T);
free(p_crunner->bfs_tilemap.tilemap);
p_crunner->bfs_tilemap.tilemap = NULL;
free(p_crunner->visited);
p_crunner->visited = NULL;
sc_queue_term(&p_crunner->bfs_queue);
remove_entity(ent_manager, ent->m_id);
}