diff --git a/source/glest_game/graphics/renderer.cpp b/source/glest_game/graphics/renderer.cpp index 88be69e6..bd16b717 100644 --- a/source/glest_game/graphics/renderer.cpp +++ b/source/glest_game/graphics/renderer.cpp @@ -477,6 +477,10 @@ void Renderer::manageParticleSystem(ParticleSystem *particleSystem, ResourceScop particleManager[rs]->manage(particleSystem); } +bool Renderer::validateParticleSystemStillExists(ParticleSystem * particleSystem,ResourceScope rs) const { + particleManager[rs]->validateParticleSystemStillExists(particleSystem); +} + void Renderer::cleanupParticleSystems(vector &particleSystems, ResourceScope rs) { particleManager[rs]->cleanupParticleSystems(particleSystems); } diff --git a/source/glest_game/graphics/renderer.h b/source/glest_game/graphics/renderer.h index 8874a982..554b991b 100644 --- a/source/glest_game/graphics/renderer.h +++ b/source/glest_game/graphics/renderer.h @@ -294,6 +294,7 @@ public: void manageParticleSystem(ParticleSystem *particleSystem, ResourceScope rs); void cleanupParticleSystems(vector &particleSystems,ResourceScope rs); void cleanupUnitParticleSystems(vector &particleSystems,ResourceScope rs); + bool validateParticleSystemStillExists(ParticleSystem * particleSystem,ResourceScope rs) const; void updateParticleManager(ResourceScope rs,int renderFps=-1); void renderParticleManager(ResourceScope rs); void swapBuffers(); diff --git a/source/glest_game/type_instances/unit.cpp b/source/glest_game/type_instances/unit.cpp index d1b56047..40955afd 100644 --- a/source/glest_game/type_instances/unit.cpp +++ b/source/glest_game/type_instances/unit.cpp @@ -262,7 +262,10 @@ Unit::~Unit(){ Renderer::getInstance().cleanupParticleSystems(fireParticleSystems,rsGame); // Must set this to null of it will be used below in stopDamageParticles() - fire = NULL; + + if(Renderer::getInstance().validateParticleSystemStillExists(fire,rsGame) == false) { + fire = NULL; + } } // fade(and by this remove) all unit particle systems @@ -985,7 +988,11 @@ bool Unit::update() { } } - if (fire!=NULL) { + if(Renderer::getInstance().validateParticleSystemStillExists(fire,rsGame) == false) { + fire = NULL; + } + + if (fire != NULL) { fire->setPos(getCurrVector()); } for(UnitParticleSystems::iterator it= unitParticleSystems.begin(); it != unitParticleSystems.end(); ++it) { @@ -1495,6 +1502,11 @@ CommandResult Unit::undoCommand(Command *command){ } void Unit::stopDamageParticles() { + + if(Renderer::getInstance().validateParticleSystemStillExists(fire,rsGame) == false) { + fire = NULL; + } + // stop fire if(fire != NULL) { SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d]\n",__FILE__,__FUNCTION__,__LINE__); @@ -1525,8 +1537,7 @@ void Unit::startDamageParticles(){ } // start fire if(type->getProperty(UnitType::pBurnable) && fire == NULL) { - FireParticleSystem *fps; - fps= new FireParticleSystem(200); + FireParticleSystem *fps = new FireParticleSystem(200); const Game *game = Renderer::getInstance().getGame(); fps->setSpeed(2.5f / game->getWorld()->getUpdateFps(this->getFactionIndex())); fps->setPos(getCurrVector()); diff --git a/source/shared_lib/include/graphics/particle.h b/source/shared_lib/include/graphics/particle.h index a7f8de66..4cf2f557 100644 --- a/source/shared_lib/include/graphics/particle.h +++ b/source/shared_lib/include/graphics/particle.h @@ -437,6 +437,7 @@ public: void cleanupParticleSystems(vector &particleSystems); void cleanupUnitParticleSystems(vector &particleSystems); int findParticleSystems(ParticleSystem *psFind, const vector &particleSystems) const; + bool validateParticleSystemStillExists(ParticleSystem * particleSystem) const; }; }}//end namespace diff --git a/source/shared_lib/include/graphics/vec.h b/source/shared_lib/include/graphics/vec.h index 463cb07a..1c51e19f 100644 --- a/source/shared_lib/include/graphics/vec.h +++ b/source/shared_lib/include/graphics/vec.h @@ -146,7 +146,7 @@ public: } std::string getString() const { - std::ostringstream streamOut; + std::ostringstream streamOut(std::ostringstream::out); streamOut << "x [" << x << "] y [" << y << "]"; return streamOut.str(); } @@ -330,7 +330,7 @@ public: } std::string getString() const { - std::ostringstream streamOut; + std::ostringstream streamOut(std::ostringstream::out); streamOut << "x [" << x << "] y [" << y << "] z [" << z << "]"; return streamOut.str(); } @@ -473,7 +473,7 @@ public: } std::string getString() const { - std::ostringstream streamOut; + std::ostringstream streamOut(std::ostringstream::out); streamOut << "x [" << x << "] y [" << y << "] z [" << z << "] w [" << w << "]"; return streamOut.str(); } diff --git a/source/shared_lib/include/platform/sdl/gl_wrap.h b/source/shared_lib/include/platform/sdl/gl_wrap.h index fe1b9338..61c2ce62 100644 --- a/source/shared_lib/include/platform/sdl/gl_wrap.h +++ b/source/shared_lib/include/platform/sdl/gl_wrap.h @@ -45,8 +45,13 @@ namespace Shared{ namespace Platform{ // ===================================================== class PlatformContextGl { +protected: + SDL_Surface *icon; + SDL_Surface *screen; + public: - virtual ~PlatformContextGl() {} + PlatformContextGl(); + virtual ~PlatformContextGl(); virtual void init(int colorBits, int depthBits, int stencilBits,bool hardware_acceleration, bool fullscreen_anti_aliasing); virtual void end(); diff --git a/source/shared_lib/include/platform/sdl/platform_main.h b/source/shared_lib/include/platform/sdl/platform_main.h index 92937028..4625b850 100644 --- a/source/shared_lib/include/platform/sdl/platform_main.h +++ b/source/shared_lib/include/platform/sdl/platform_main.h @@ -15,15 +15,15 @@ #include #include "leak_dumper.h" -#define MAIN_FUNCTION(X) int main(int argc, char **argv) \ -{ \ +#define MAIN_FUNCTION(X) int main(int argc, char **argv) \ +{ \ if(SDL_Init(SDL_INIT_EVERYTHING) < 0) { \ std::cerr << "Couldn't initialize SDL: " << SDL_GetError() << "\n"; \ return 1; \ } \ + atexit(SDL_Quit); \ SDL_EnableUNICODE(1); \ int result = X(argc, argv); \ - SDL_Quit(); \ return result; \ } diff --git a/source/shared_lib/sources/graphics/JPGReader.cpp b/source/shared_lib/sources/graphics/JPGReader.cpp index 7167a0ba..55fc5eed 100644 --- a/source/shared_lib/sources/graphics/JPGReader.cpp +++ b/source/shared_lib/sources/graphics/JPGReader.cpp @@ -71,7 +71,7 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const return NULL; } is.seekg(0, ios::beg); - uint8 * buffer = new uint8[length]; + uint8 *buffer = new uint8[length]; is.read((char*)buffer, length); //Check buffer (weak jpeg check) //if (buffer[0] != 0x46 || buffer[1] != 0xA0) { @@ -209,6 +209,9 @@ Pixmap2D* JPGReader::read(ifstream& is, const string& path, Pixmap2D* ret) const jpeg_finish_decompress( &cinfo ); jpeg_destroy_decompress( &cinfo ); delete[] row_pointer[0]; + + delete[] buffer; + return ret; } diff --git a/source/shared_lib/sources/graphics/particle.cpp b/source/shared_lib/sources/graphics/particle.cpp index 4d1fe100..c828ad8f 100644 --- a/source/shared_lib/sources/graphics/particle.cpp +++ b/source/shared_lib/sources/graphics/particle.cpp @@ -947,6 +947,11 @@ void ParticleManager::update(int renderFps) { if(chrono.getMillis() > 0) SystemFlags::OutputDebug(SystemFlags::debugPerformance,"In [%s::%s] Line: %d took msecs: %lld, particleSystemCount = %d, particleCount = %d\n",__FILE__,__FUNCTION__,__LINE__,chrono.getMillis(),particleSystemCount,particleCount); } +bool ParticleManager::validateParticleSystemStillExists(ParticleSystem * particleSystem) const { + int index = findParticleSystems(particleSystem, this->particleSystems); + return (index >= 0); +} + int ParticleManager::findParticleSystems(ParticleSystem *psFind, const vector &particleSystems) const { int result = -1; for (int i = 0; i < particleSystems.size(); i++) { diff --git a/source/shared_lib/sources/platform/posix/socket.cpp b/source/shared_lib/sources/platform/posix/socket.cpp index 4ec31c98..2689038a 100644 --- a/source/shared_lib/sources/platform/posix/socket.cpp +++ b/source/shared_lib/sources/platform/posix/socket.cpp @@ -626,7 +626,7 @@ std::vector Socket::getLocalIPAddressList() { } ipIdx++; } - } + } #ifndef WIN32 @@ -662,21 +662,26 @@ std::vector Socket::getLocalIPAddressList() { strncpy(ifrA.ifr_name, szBuf, maxIfNameLength); ifrA.ifr_name[maxIfNameLength] = '\0'; - ioctl(fd, SIOCGIFADDR, &ifr); + int result_ifaddrr = ioctl(fd, SIOCGIFADDR, &ifr); ioctl(fd, SIOCGIFFLAGS, &ifrA); close(fd); - sprintf(myhostaddr, "%s",inet_ntoa(((struct sockaddr_in *)&ifr.ifr_addr)->sin_addr)); - SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] szBuf [%s], myhostaddr = [%s], ifr.ifr_flags = %d, ifrA.ifr_flags = %d, ifr.ifr_name [%s]\n",__FILE__,__FUNCTION__,__LINE__,szBuf,myhostaddr,ifr.ifr_flags,ifrA.ifr_flags,ifr.ifr_name); + if(result_ifaddrr >= 0) { + struct sockaddr_in *pSockAddr = (struct sockaddr_in *)&ifr.ifr_addr; + if(pSockAddr != NULL) { + sprintf(myhostaddr, "%s",inet_ntoa(pSockAddr->sin_addr)); + SystemFlags::OutputDebug(SystemFlags::debugNetwork,"In [%s::%s Line: %d] szBuf [%s], myhostaddr = [%s], ifr.ifr_flags = %d, ifrA.ifr_flags = %d, ifr.ifr_name [%s]\n",__FILE__,__FUNCTION__,__LINE__,szBuf,myhostaddr,ifr.ifr_flags,ifrA.ifr_flags,ifr.ifr_name); - // Now only include interfaces that are both UP and running - if( (ifrA.ifr_flags & IFF_UP) == IFF_UP && - (ifrA.ifr_flags & IFF_RUNNING) == IFF_RUNNING) { - if( strlen(myhostaddr) > 0 && - strncmp(myhostaddr,"127.",4) != 0 && - strncmp(myhostaddr,"0.",2) != 0) { - if(std::find(ipList.begin(),ipList.end(),myhostaddr) == ipList.end()) { - ipList.push_back(myhostaddr); + // Now only include interfaces that are both UP and running + if( (ifrA.ifr_flags & IFF_UP) == IFF_UP && + (ifrA.ifr_flags & IFF_RUNNING) == IFF_RUNNING) { + if( strlen(myhostaddr) > 0 && + strncmp(myhostaddr,"127.",4) != 0 && + strncmp(myhostaddr,"0.",2) != 0) { + if(std::find(ipList.begin(),ipList.end(),myhostaddr) == ipList.end()) { + ipList.push_back(myhostaddr); + } + } } } } diff --git a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp index fef5ad6d..1308b818 100644 --- a/source/shared_lib/sources/platform/sdl/gl_wrap.cpp +++ b/source/shared_lib/sources/platform/sdl/gl_wrap.cpp @@ -34,6 +34,21 @@ namespace Shared{ namespace Platform{ // ====================================== // class PlatformContextGl // ====================================== +PlatformContextGl::PlatformContextGl() { + icon = NULL; + screen = NULL; +} + +PlatformContextGl::~PlatformContextGl() { + if(icon != NULL) { + SDL_FreeSurface(icon); + icon = NULL; + } + if(screen != NULL) { + SDL_FreeSurface(screen); + screen = NULL; + } +} void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool hardware_acceleration, bool fullscreen_anti_aliasing) { @@ -59,7 +74,13 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool #ifndef WIN32 if(fileExists("megaglest.bmp")) { - SDL_Surface *icon = SDL_LoadBMP("megaglest.bmp"); + + if(icon != NULL) { + SDL_FreeSurface(icon); + icon = NULL; + } + + icon = SDL_LoadBMP("megaglest.bmp"); //SDL_Surface *icon = IMG_Load("megaglest.ico"); @@ -84,7 +105,12 @@ void PlatformContextGl::init(int colorBits, int depthBits, int stencilBits,bool SystemFlags::OutputDebug(SystemFlags::debugSystem,"In [%s::%s Line: %d] about to set resolution: %d x %d, colorBits = %d.\n",__FILE__,__FUNCTION__,__LINE__,resW,resH,colorBits); - SDL_Surface* screen = SDL_SetVideoMode(resW, resH, colorBits, flags); + if(screen != NULL) { + SDL_FreeSurface(screen); + screen = NULL; + } + + screen = SDL_SetVideoMode(resW, resH, colorBits, flags); if(screen == 0) { std::ostringstream msg; msg << "Couldn't set video mode "