vk: clear EntityData on new map regardless of save-load

Entity data gets reallocate on every NewMap regardless of whether it was a load from a save. Thus all entity pointers and data are invalidated. EntityData keeps things using pointers as keys.
Make sure it is properly cleared on `R_NewMap()`

Fixes #562
This commit is contained in:
Ivan 'provod' Avdeev 2023-09-14 13:48:39 -04:00
parent 7d115168ae
commit 06a7de02a8
2 changed files with 7 additions and 3 deletions

View File

@ -89,7 +89,6 @@ static void loadLights( const model_t *const map ) {
// Clears all old map data
static void mapLoadBegin( const model_t *const map ) {
VK_EntityDataClear();
R_StudioCacheClear();
R_GeometryBuffer_MapClear();
@ -239,6 +238,11 @@ void R_NewMap( void ) {
INFO( "R_NewMap, loading save: %d", is_save_load );
// New map causes entites to be reallocated regardless of whether it was save-load.
// This realloc invalidates all previous entity data and pointers.
// Make sure that EntityData doesn't accidentally reference old pointers.
VK_EntityDataClear();
// Skip clearing already loaded data if the map hasn't changed.
if (is_save_load)
return;

View File

@ -2207,8 +2207,8 @@ static r_studio_entity_model_t *studioEntityModelGet(const cl_entity_t* entity)
return NULL;
}
DEBUG("Created studio entity %p model %s: %p (bodyparts=%d)",
entity, entity->model->name, entmodel, entmodel->bodyparts_count);
DEBUG("Created studio entity %p(%d) model %s: %p (bodyparts=%d)",
entity, entity->index, entity->model->name, entmodel, entmodel->bodyparts_count);
VK_EntityDataSet(entity, entmodel, &studioEntityModelDestroy);
return entmodel;