Merge pull request #56 from DanielGibson/fix-null-crashes

Fix crashes from this!=NULL removal
This commit is contained in:
Ryan C. Gordon 2016-07-03 01:19:00 -04:00 committed by GitHub
commit 570f166b26
6 changed files with 21 additions and 15 deletions

View File

@ -615,7 +615,7 @@ CAnimObject::CAnimObject(void)
/* Destructor. */ /* Destructor. */
CAnimObject::~CAnimObject(void) CAnimObject::~CAnimObject(void)
{ {
ao_AnimData->RemReference(); if(ao_AnimData != NULL) ao_AnimData->RemReference();
} }
// copy from another object of same class // copy from another object of same class
@ -818,9 +818,9 @@ BOOL CAnimObject::IsUpToDate(const CUpdateable &ud) const
void CAnimObject::SetData(CAnimData *pAD) void CAnimObject::SetData(CAnimData *pAD)
{ {
// mark new data as referenced once more // mark new data as referenced once more
pAD->AddReference(); if(pAD != NULL) pAD->AddReference();
// mark old data as referenced once less // mark old data as referenced once less
ao_AnimData->RemReference(); if(ao_AnimData != NULL) ao_AnimData->RemReference();
// remember new data // remember new data
ao_AnimData = pAD; ao_AnimData = pAD;
if( pAD != NULL) StartAnim( 0); if( pAD != NULL) StartAnim( 0);

View File

@ -169,7 +169,13 @@ void InitStreams(void)
} }
// find eventual extension for the mod's dlls // find eventual extension for the mod's dlls
_strModExt = ""; _strModExt = "";
// DG: apparently both ModEXT.txt and ModExt.txt exist in the wild.
CTFileName tmp;
if(ExpandFilePath(EFP_READ, CTString("ModEXT.txt"), tmp) != EFP_NONE) {
LoadStringVar(CTString("ModEXT.txt"), _strModExt); LoadStringVar(CTString("ModEXT.txt"), _strModExt);
} else {
LoadStringVar(CTString("ModExt.txt"), _strModExt);
}
CPrintF(TRANSV("Loading group files...\n")); CPrintF(TRANSV("Loading group files...\n"));

View File

@ -186,7 +186,7 @@ CEntity::~CEntity(void)
} }
// clear entity type // clear entity type
en_RenderType = RT_NONE; en_RenderType = RT_NONE;
en_pecClass->RemReference(); if(en_pecClass != NULL) en_pecClass->RemReference();
en_pecClass = NULL; en_pecClass = NULL;
en_fSpatialClassificationRadius = -1.0f; en_fSpatialClassificationRadius = -1.0f;

View File

@ -670,20 +670,20 @@ BOOL ENGINE_API IsDerivedFromClass(CEntity *pen, const char *pstrClassName);
// all standard smart pointer functions are here as inlines // all standard smart pointer functions are here as inlines
inline CEntityPointer::CEntityPointer(void) : ep_pen(NULL) {}; inline CEntityPointer::CEntityPointer(void) : ep_pen(NULL) {};
inline CEntityPointer::~CEntityPointer(void) { ep_pen->RemReference(); }; inline CEntityPointer::~CEntityPointer(void) { if(ep_pen != NULL) ep_pen->RemReference(); };
inline CEntityPointer::CEntityPointer(const CEntityPointer &penOther) : ep_pen(penOther.ep_pen) { inline CEntityPointer::CEntityPointer(const CEntityPointer &penOther) : ep_pen(penOther.ep_pen) {
ep_pen->AddReference(); }; if(ep_pen != NULL) ep_pen->AddReference(); };
inline CEntityPointer::CEntityPointer(CEntity *pen) : ep_pen(pen) { inline CEntityPointer::CEntityPointer(CEntity *pen) : ep_pen(pen) {
ep_pen->AddReference(); }; if(ep_pen != NULL) ep_pen->AddReference(); };
inline const CEntityPointer &CEntityPointer::operator=(CEntity *pen) { inline const CEntityPointer &CEntityPointer::operator=(CEntity *pen) {
pen->AddReference(); // must first add, then remove! if(pen != NULL) pen->AddReference(); // must first add, then remove!
ep_pen->RemReference(); if(ep_pen != NULL) ep_pen->RemReference();
ep_pen = pen; ep_pen = pen;
return *this; return *this;
} }
inline const CEntityPointer &CEntityPointer::operator=(const CEntityPointer &penOther) { inline const CEntityPointer &CEntityPointer::operator=(const CEntityPointer &penOther) {
penOther.ep_pen->AddReference(); // must first add, then remove! if(penOther.ep_pen != NULL) penOther.ep_pen->AddReference(); // must first add, then remove!
ep_pen->RemReference(); if(ep_pen != NULL) ep_pen->RemReference();
ep_pen = penOther.ep_pen; ep_pen = penOther.ep_pen;
return *this; return *this;
} }

View File

@ -807,7 +807,7 @@ extern BOOL ProbeMode( CTimerValue tvLast)
extern void UncacheShadows(void) extern void UncacheShadows(void)
{ {
// mute all sounds // mute all sounds
_pSound->Mute(); if(_pSound != NULL) _pSound->Mute();
// prepare new saturation factors for shadowmaps // prepare new saturation factors for shadowmaps
gfx_fSaturation = ClampDn( gfx_fSaturation, 0.0f); gfx_fSaturation = ClampDn( gfx_fSaturation, 0.0f);
shd_fSaturation = ClampDn( shd_fSaturation, 0.0f); shd_fSaturation = ClampDn( shd_fSaturation, 0.0f);

View File

@ -240,9 +240,9 @@ void CSoundObject::Play_internal( CSoundData *pCsdLink, SLONG slFlags)
Stop_internal(); Stop_internal();
// mark new data as referenced once more // mark new data as referenced once more
pCsdLink->AddReference(); if(pCsdLink != NULL) pCsdLink->AddReference();
// mark old data as referenced once less // mark old data as referenced once less
so_pCsdLink->RemReference(); if(so_pCsdLink != NULL) so_pCsdLink->RemReference();
// store init SoundData // store init SoundData
so_pCsdLink = pCsdLink; so_pCsdLink = pCsdLink;