Skip to content

Commit

Permalink
Fixed: Attempt to use memory zone before it was initialized
Browse files Browse the repository at this point in the history
ddstring_t will now automatically switch to using standard
memory allocation if the memory zone is not available.
  • Loading branch information
skyjake committed Feb 7, 2012
1 parent 2913b29 commit b77bd6b
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 4 deletions.
11 changes: 10 additions & 1 deletion doomsday/engine/portable/include/dd_zone.h
Expand Up @@ -38,7 +38,16 @@
#define PU_REFRESHTRANS 13
#define PU_REFRESHRAW 17

int Z_Init(void);
/**
* Determines if the memory zone is available for allocations.
*/
boolean Z_IsInited(void);

/**
* Initialize the memory zone.
*/
int Z_Init(void);

void Z_Shutdown(void);
void Z_EnableFastMalloc(boolean isEnabled);
//void Z_PrintStatus(void);
Expand Down
8 changes: 5 additions & 3 deletions doomsday/engine/portable/src/dd_zone.c
Expand Up @@ -190,9 +190,11 @@ memvolume_t *Z_Create(size_t volumeSize)
return vol;
}

/**
* Initialize the memory zone.
*/
boolean Z_IsInited(void)
{
return zoneMutex != 0;
}

int Z_Init(void)
{
zoneMutex = Sys_CreateMutex("ZONE_MUTEX");
Expand Down
8 changes: 8 additions & 0 deletions doomsday/engine/portable/src/m_string.c
Expand Up @@ -106,6 +106,14 @@ void Str_Init(ddstring_t *str)
Con_Error("Attempted String::Init with invalid reference (this==0).");
return; // Unreachable.
}

if(!Z_IsInited())
{
// The memory zone is not available at the moment.
Str_InitStd(str);
return;
}

memset(str, 0, sizeof(*str));

// Init the memory management.
Expand Down

0 comments on commit b77bd6b

Please sign in to comment.