OpenXRay / xray-16

Improved version of the X-Ray Engine, the game engine used in the world-famous S.T.A.L.K.E.R. game series by GSC Game World. Join OpenXRay! ;)
https://discord.gg/sjRMQwv
Other
3k stars 454 forks source link

Game crashes during loading a game level #1625

Closed antoncxx closed 8 months ago

antoncxx commented 8 months ago

Describe the bug Game crashes during level loading.

To Reproduce Steps to reproduce the behavior:

  1. Start game
  2. Start new game or load a save
  3. Application terminates because of memory corruption.

Expected behavior Game loads as usual

Screenshots, videos If applicable, add screenshots to help explain your problem.

BugTrap error report OpenXRay_error_report_240303-151450.zip

Desktop (please complete the following information):

Additional context

void CSoundRender_Scene::set_geometry_occ(CDB::MODEL* M, const Fbox& /*aabb*/)
{
    xr_delete(M);
    geom_MODEL = M;
}

Just removing xr_delete(M); solves the issue.

antoncxx commented 8 months ago

Following up, It seems like deleting model from the CSoundRender_Scene object corrupts Game Level Object in memory. I tried to compare memory dumps with and without xr_delete(M);. between 2 points, which are the following:

1. Before setting geometry occlusion

...
Sound->set_geometry_occ(ObjectSpace.GetStaticModel(), ObjectSpace.GetBoundingVolume());
...

2. Before the first addressing g_pGameLevel object after that

...
const shared_str level_name = g_pGameLevel->name();
...

In the first case, when ocllusion was set without model deletion, 2 dumps were identical: mem_dump_point_1_no_delete.txt mem_dump_point_2_no_delete.txt

In the second, which included model deletion, they match for 96.3% (I tried it several times and the percentages stayed the same), meaning that some region of it was overwritten. mem_dumb_point_2_delete.txt mem_dump_point_1_delete.txt

Worth mentioning, that I compared memory block, that started at g_pGameLevel with length of 560472 bytes, which is the result of sizeof(CGameLevel) on my machine.