Skip to content

Commit

Permalink
spearmint: Provide better zone debug messages from renderer
Browse files Browse the repository at this point in the history
  • Loading branch information
zturtleman committed Aug 6, 2017
1 parent 303be6a commit cc46702
Show file tree
Hide file tree
Showing 4 changed files with 27 additions and 4 deletions.
15 changes: 15 additions & 0 deletions code/qcommon/common.c
Original file line number Diff line number Diff line change
Expand Up @@ -3109,13 +3109,23 @@ void Com_ReadFromPipe( void )
Com_RefMalloc
============
*/
#ifdef ZONE_DEBUG
void *Com_RefMalloc( int size, char *label, char *file, int line ) {
return Z_TagMallocDebug( size, TAG_RENDERER, label, file, line );
}

void Com_RefFree( void *pointer, char *label, char *file, int line ) {
Z_FreeDebug( pointer, label, file, line );
}
#else
void *Com_RefMalloc( int size ) {
return Z_TagMalloc( size, TAG_RENDERER );
}

void Com_RefFree( void *pointer ) {
Z_Free( pointer );
}
#endif

int Com_ScaledMilliseconds(void) {
return Sys_Milliseconds()*com_timescale->value;
Expand Down Expand Up @@ -3232,8 +3242,13 @@ void Com_InitRef( refimport_t *ri ) {
ri->Printf = Com_RefPrintf;
ri->Error = Com_Error;
ri->Milliseconds = Com_ScaledMilliseconds;
#ifdef ZONE_DEBUG
ri->MallocDebug = Com_RefMalloc;
ri->FreeDebug = Com_RefFree;
#else
ri->Malloc = Com_RefMalloc;
ri->Free = Com_RefFree;
#endif
#ifdef HUNK_DEBUG
ri->Hunk_AllocDebug = Hunk_AllocDebug;
#else
Expand Down
4 changes: 4 additions & 0 deletions code/qcommon/q_shared.h
Original file line number Diff line number Diff line change
Expand Up @@ -257,6 +257,10 @@ typedef enum {
} errorParm_t;


#if !defined(NDEBUG) && !defined(BSPC)
#define ZONE_DEBUG
#endif

#if !defined(NDEBUG) && !defined(BSPC)
#define HUNK_DEBUG
#endif
Expand Down
4 changes: 0 additions & 4 deletions code/qcommon/qcommon.h
Original file line number Diff line number Diff line change
Expand Up @@ -1060,10 +1060,6 @@ temp file loading
*/

#if !defined(NDEBUG) && !defined(BSPC)
#define ZONE_DEBUG
#endif

#ifdef ZONE_DEBUG
#define Z_TagMalloc(size, tag) Z_TagMallocDebug(size, tag, #size, __FILE__, __LINE__)
#define Z_Malloc(size) Z_MallocDebug(size, #size, __FILE__, __LINE__)
Expand Down
8 changes: 8 additions & 0 deletions code/renderercommon/tr_public.h
Original file line number Diff line number Diff line change
Expand Up @@ -162,9 +162,17 @@ typedef struct {
void *(*Hunk_AllocateTempMemory)( int size );
void (*Hunk_FreeTempMemory)( void *block );

#ifdef ZONE_DEBUG
#define Malloc(size) MallocDebug(size, #size, __FILE__, __LINE__)
#define Free(ptr) FreeDebug(ptr, #ptr, __FILE__, __LINE__)
// dynamic memory allocator for things that need to be freed
void *(*MallocDebug)( int bytes, char *label, char *file, int line );
void (*FreeDebug)( void *buf, char *label, char *file, int line );
#else
// dynamic memory allocator for things that need to be freed
void *(*Malloc)( int bytes );
void (*Free)( void *buf );
#endif

cvar_t *(*Cvar_Get)( const char *name, const char *value, int flags );
cvar_t *(*Cvar_Set)( const char *name, const char *value );
Expand Down

0 comments on commit cc46702

Please sign in to comment.