- tighten up code.. ensure pointers set to null after delete, etc

This commit is contained in:
Mark Vejvoda 2013-02-01 17:25:49 +00:00
parent bff9b1b3bc
commit 8dc637527a
19 changed files with 54 additions and 13 deletions

View File

@ -79,8 +79,10 @@ ParticleSystemType::~ParticleSystemType() {
memoryObjectList[this]--;
assert(memoryObjectList[this] == 0);
}
for(Children::iterator it = children.begin(); it != children.end(); ++it)
for(Children::iterator it = children.begin(); it != children.end(); ++it) {
delete *it;
}
children.clear();
}
void ParticleSystemType::copyAll(const ParticleSystemType &src) {

View File

@ -165,6 +165,7 @@ void cleanupCRCThread() {
}
if(preCacheThread->getRunningStatus() == false) {
delete preCacheThread;
preCacheThread=NULL;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("C - shutting down crc threads\n");
}
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -175,6 +176,7 @@ void cleanupCRCThread() {
if(preCacheThread->canShutdown(false) == true) {
if(SystemFlags::getSystemSettingType(SystemFlags::debugSystem).enabled) SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete preCacheThread;
preCacheThread=NULL;
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("E - shutting down crc threads\n");
//printf("Stopping broadcast thread [%p] - C\n",broadCastThread);
@ -288,8 +290,8 @@ void fatal(const char *s, ...) // failure exit
MessageBox(NULL, wstr, wstr1, MB_OK|MB_SYSTEMMODAL);
}
delete [] wstr;
delete [] wstr1;
if(wstr) delete [] wstr;
if(wstr1) delete [] wstr1;
#endif
//SDL_Quit();
}
@ -4602,6 +4604,7 @@ int glestMain(int argc, char** argv) {
printf("\nInvalid map name specified on commandline [%s] map [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(argv[0],foundInvalidArgs);
delete mainWindow;
mainWindow=NULL;
return 1;
}
}
@ -4640,6 +4643,7 @@ int glestMain(int argc, char** argv) {
printf("\nInvalid host specified on commandline [%s] host [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(argv[0],foundInvalidArgs);
delete mainWindow;
mainWindow=NULL;
return 1;
}
}
@ -4669,6 +4673,7 @@ int glestMain(int argc, char** argv) {
printf("\nInvalid host specified on commandline [%s] host [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(argv[0],foundInvalidArgs);
delete mainWindow;
mainWindow=NULL;
return 1;
}
}
@ -4692,6 +4697,7 @@ int glestMain(int argc, char** argv) {
printf("\nInvalid scenario name specified on commandline [%s] scenario [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(argv[0],foundInvalidArgs);
delete mainWindow;
mainWindow=NULL;
return 1;
}
}
@ -4711,6 +4717,7 @@ int glestMain(int argc, char** argv) {
printf("%s",renderer.getGlMoreInfo().c_str());
delete mainWindow;
mainWindow=NULL;
return 0;
}
@ -4828,12 +4835,14 @@ int glestMain(int argc, char** argv) {
}
delete mainWindow;
mainWindow=NULL;
return result;
}
else {
printf("\nInvalid model specified on commandline [%s] texture [%s]\n\n",argv[foundParamIndIndex],(paramPartTokens.size() >= 2 ? paramPartTokens[1].c_str() : NULL));
printParameterHelp(argv[0],foundInvalidArgs);
delete mainWindow;
mainWindow=NULL;
return 1;
}
}
@ -4844,6 +4853,7 @@ int glestMain(int argc, char** argv) {
runTechValidationReport(argc, argv);
delete mainWindow;
mainWindow=NULL;
return 0;
}
@ -4851,6 +4861,7 @@ int glestMain(int argc, char** argv) {
runTilesetValidationReport(argc, argv);
delete mainWindow;
mainWindow=NULL;
return 0;
}

View File

@ -246,10 +246,11 @@ void MainMenu::setState(MenuState *newstate) {
//this->state = newstate;
if(oldstate != NULL && oldstate != newstate) {
MenuState *oldstatePtr = oldstate;
delete oldstate;
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
if(oldstate != this->state) {
if(oldstatePtr != this->state) {
oldstate=this->state;
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
}

View File

@ -50,6 +50,7 @@ public:
StaticSound *&operator[](int i) {return sounds[i];}
const Sounds &getSounds() const {return sounds;}
void clearSounds() {sounds.clear();}
Sounds *getSoundsPtr() {return &sounds;}
StaticSound *getRandSound() const;
};

View File

@ -63,6 +63,7 @@ DamageMultiplierTable::DamageMultiplierTable(){
DamageMultiplierTable::~DamageMultiplierTable(){
delete [] values;
values=NULL;
}
void DamageMultiplierTable::init(int attackTypeCount, int armorTypeCount){

View File

@ -742,6 +742,7 @@ AttackSkillType::~AttackSkillType() {
delete splashParticleSystemType;
splashParticleSystemType = NULL;
deleteValues(projSounds.getSounds().begin(), projSounds.getSounds().end());
projSounds.clearSounds();
}
void AttackSkillType::load(const XmlNode *sn, const XmlNode *attackBoostsNode,

View File

@ -143,10 +143,15 @@ UnitType::UnitType() : ProducibleType() {
UnitType::~UnitType(){
deleteValues(commandTypes.begin(), commandTypes.end());
commandTypes.clear();
deleteValues(skillTypes.begin(), skillTypes.end());
skillTypes.clear();
deleteValues(selectionSounds.getSounds().begin(), selectionSounds.getSounds().end());
selectionSounds.clearSounds();
deleteValues(commandSounds.getSounds().begin(), commandSounds.getSounds().end());
commandSounds.clearSounds();
delete [] cellMap;
cellMap=NULL;
//remove damageParticleSystemTypes
while(!damageParticleSystemTypes.empty()){
delete damageParticleSystemTypes.back();

View File

@ -140,6 +140,7 @@ SurfaceCell::SurfaceCell() {
SurfaceCell::~SurfaceCell() {
delete object;
object=NULL;
}
void SurfaceCell::end(){

View File

@ -63,6 +63,7 @@ public:
for(Factories::iterator it= factories.begin(); it!=factories.end(); ++it){
delete it->second;
}
factories.clear();
}
template<typename R>

View File

@ -77,6 +77,7 @@ void FontManager::end() {
if(fonts[i] != NULL) {
fonts[i]->end();
delete fonts[i];
fonts[i]=NULL;
}
}
fonts.clear();

View File

@ -115,7 +115,9 @@ void TextFTGL::cleanupFont() {
delete ftFont;
ftFont = NULL;
free((void*)fontFile);
if(fontFile) {
free((void*)fontFile);
}
fontFile = NULL;
}
@ -149,7 +151,9 @@ void TextFTGL::init(string fontName, string fontFamilyName, int fontSize) {
if(ftFont->Error()) {
printf("FTGL: error loading font: %s\n", fontFile);
delete ftFont; ftFont = NULL;
free((void*)fontFile);
if(fontFile) {
free((void*)fontFile);
}
fontFile = NULL;
throw megaglest_runtime_error("FTGL: error loading font");
}

View File

@ -51,8 +51,9 @@ InterpolationData::InterpolationData(const Mesh *mesh) {
InterpolationData::~InterpolationData(){
delete [] vertices;
vertices=NULL;
delete [] normals;
normals=NULL;
for(std::map<float, std::map<bool, Vec3f *> >::iterator iterVert = cacheVertices.begin();
iterVert != cacheVertices.end(); ++iterVert) {
@ -61,6 +62,7 @@ InterpolationData::~InterpolationData(){
delete [] iterVert2->second;
}
}
cacheVertices.clear();
for(std::map<float, std::map<bool, Vec3f *> >::iterator iterVert = cacheNormals.begin();
iterVert != cacheNormals.end(); ++iterVert) {
@ -69,6 +71,7 @@ InterpolationData::~InterpolationData(){
delete [] iterVert2->second;
}
}
cacheNormals.clear();
}
void InterpolationData::update(float t, bool cycle){

View File

@ -56,6 +56,7 @@ void ModelManager::end(){
if(models[i] != NULL) {
models[i]->end();
delete models[i];
models[i]=NULL;
}
}
models.clear();

View File

@ -492,6 +492,7 @@ void ParticleSystem::fade(){
state= sFade;
if(particleObserver != NULL){
particleObserver->update(this);
particleObserver=NULL;
}
for(int i=getChildCount()-1; i>=0; i--)
getChild(i)->fade();
@ -1539,6 +1540,7 @@ void ProjectileParticleSystem::update(){
if(particleObserver != NULL){
particleObserver->update(this);
particleObserver=NULL;
}
if(nextParticleSystem != NULL){

View File

@ -495,6 +495,7 @@ void SimpleTaskThread::execute() {
if(SystemFlags::VERBOSE_MODE_ENABLED) printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
delete this;
}
return;
}
}

View File

@ -97,7 +97,7 @@ void createGlFontBitmaps(uint32 &base, const string &type, int size, int width,
size, 0, 0, 0, width, FALSE, FALSE, FALSE, charSet,
OUT_TT_ONLY_PRECIS, CLIP_DEFAULT_PRECIS, DEFAULT_QUALITY,
DEFAULT_PITCH| (useRealFontName.c_str() ? FF_DONTCARE:FF_SWISS), wstr);
delete [] wstr;
if(wstr) delete [] wstr;
assert(font!=NULL);
HDC dc= wglGetCurrentDC();

View File

@ -137,7 +137,7 @@ LONG WINAPI PlatformExceptionHandler::handler(LPEXCEPTION_POINTERS pointers){
CREATE_ALWAYS,
FILE_ATTRIBUTE_NORMAL,
0);
delete [] wstr;
if(wstr) delete [] wstr;
//printf("In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -332,13 +332,13 @@ void message(string message){
LPWSTR wstr = Ansi2WideString(message.c_str());
MessageBox(NULL, wstr, L"Message", MB_OK | MB_SYSTEMMODAL);
delete [] wstr;
if(wstr) delete [] wstr;
}
bool ask(string message){
LPWSTR wstr = Ansi2WideString(message.c_str());
bool result = MessageBox(NULL, wstr, L"Confirmation", MB_YESNO | MB_SYSTEMMODAL) == IDYES;
delete [] wstr;
if(wstr) delete [] wstr;
return result;
}
@ -355,8 +355,8 @@ void exceptionMessage(const exception &excp){
LPWSTR wstr = Ansi2WideString(message.c_str());
LPWSTR wstr1 = Ansi2WideString(title.c_str());
MessageBox(NULL, wstr, wstr1, MB_ICONSTOP | MB_OK | MB_SYSTEMMODAL);
delete [] wstr;
delete [] wstr1;
if(wstr) delete [] wstr;
if(wstr1) delete [] wstr1;
}
//int getScreenW(){

View File

@ -430,6 +430,7 @@ void SoundPlayerOpenAL::end() {
i != staticSources.end(); ++i) {
delete *i;
}
staticSources.clear();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSound).enabled) SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);
@ -437,6 +438,7 @@ void SoundPlayerOpenAL::end() {
i != streamSources.end(); ++i) {
delete *i;
}
streamSources.clear();
if(SystemFlags::getSystemSettingType(SystemFlags::debugSound).enabled) SystemFlags::OutputDebug(SystemFlags::debugSound,"In [%s::%s %d]\n",__FILE__,__FUNCTION__,__LINE__);

View File

@ -473,6 +473,7 @@ XmlTree::~XmlTree() {
}
delete rootNode;
rootNode=NULL;
}
// =====================================================
@ -574,9 +575,11 @@ XmlNode::~XmlNode() {
for(unsigned int i=0; i<children.size(); ++i) {
delete children[i];
}
children.clear();
for(unsigned int i=0; i<attributes.size(); ++i) {
delete attributes[i];
}
attributes.clear();
}
XmlAttribute *XmlNode::getAttribute(unsigned int i) const {