Skip to content

Commit

Permalink
Fixed: Fatal error during game change
Browse files Browse the repository at this point in the history
An attempt was made to dereference a dangling pointer to the objlink
blockmap once a map had been played and the game subsequently changed.

The objlink blockmaps are allocated with a Zone purge level >= PU_MAP
thus pointers to them will be invalid after a game change.
  • Loading branch information
danij-deng committed Jan 8, 2012
1 parent 4dc0aed commit 78d24e1
Show file tree
Hide file tree
Showing 3 changed files with 30 additions and 2 deletions.
11 changes: 11 additions & 0 deletions doomsday/engine/portable/include/p_objlink.h
Expand Up @@ -39,6 +39,17 @@ typedef enum {

#define VALID_OBJTYPE(val) ((val) >= OT_MOBJ && (val) < NUM_OBJ_TYPES)

/**
* To be called during a game change/on shutdown to destroy the objlink
* blockmap. This is necessary because the blockmaps are allocated from
* the Zone with a >= PU_MAP purge level and access to them is handled
* with global pointers.
*
* \todo Encapsulate allocation of and access to the objlink blockmaps
* within de::Map
*/
void R_DestroyObjlinkBlockmap(void);

/**
* Construct the objlink blockmap for the current map.
*/
Expand Down
4 changes: 2 additions & 2 deletions doomsday/engine/portable/src/dd_main.c
Expand Up @@ -1073,7 +1073,7 @@ boolean DD_ChangeGame2(Game* game, boolean allowReload)
Con_SaveDefaults();

LO_Clear();
//R_DestroyObjlinks();
R_DestroyObjlinkBlockmap();
R_ClearAnimGroups();

P_PtcShutdown();
Expand Down Expand Up @@ -1514,7 +1514,7 @@ int DD_Main(void)

// Try to locate all required data files for all registered games.
Con_InitProgress(200);
Con_Busy(BUSYF_STARTUP | BUSYF_PROGRESS_BAR | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
Con_Busy(BUSYF_STARTUP | BUSYF_PROGRESS_BAR | (verbose? BUSYF_CONSOLE_OUTPUT : 0),
"Locating game resources...", DD_LocateAllGameResourcesWorker, 0);

// Unless we reenter busy-mode due to automatic game selection, we won't be
Expand Down
17 changes: 17 additions & 0 deletions doomsday/engine/portable/src/p_objlink.c
Expand Up @@ -249,6 +249,23 @@ void R_InitObjlinkBlockmapForMap(void)
ssecContacts = Z_Calloc(sizeof *ssecContacts * numSSectors, PU_MAPSTATIC, 0);
}

void R_DestroyObjlinkBlockmap(void)
{
int i;
for(i = 0; i < NUM_OBJ_TYPES; ++i)
{
objlinkblockmap_t* obm = chooseObjlinkBlockmap((objtype_t)i);
if(!obm->gridmap) continue;
Gridmap_Delete(obm->gridmap);
obm->gridmap = NULL;
}
if(ssecContacts)
{
Z_Free(ssecContacts);
ssecContacts = NULL;
}
}

int clearObjlinkBlock(void* obj, void* paramaters)
{
objlinkblock_t* block = (objlinkblock_t*)obj;
Expand Down

0 comments on commit 78d24e1

Please sign in to comment.