bugfix for particle cleanup

This commit is contained in:
Mark Vejvoda 2013-09-24 03:44:15 +00:00
parent f66a0834c9
commit 875eb95790
5 changed files with 58 additions and 29 deletions

View File

@ -969,6 +969,10 @@ bool Renderer::validateParticleSystemStillExists(ParticleSystem * particleSystem
return particleManager[rs]->validateParticleSystemStillExists(particleSystem);
}
void Renderer::removeParticleSystemsForParticleOwner(ParticleOwner * particleOwner,ResourceScope rs) {
return particleManager[rs]->removeParticleSystemsForParticleOwner(particleOwner);
}
void Renderer::cleanupParticleSystems(vector<ParticleSystem *> &particleSystems, ResourceScope rs) {
particleManager[rs]->cleanupParticleSystems(particleSystems);
}

View File

@ -476,6 +476,7 @@ public:
void cleanupParticleSystems(vector<ParticleSystem *> &particleSystems,ResourceScope rs);
void cleanupUnitParticleSystems(vector<UnitParticleSystem *> &particleSystems,ResourceScope rs);
bool validateParticleSystemStillExists(ParticleSystem * particleSystem,ResourceScope rs) const;
void removeParticleSystemsForParticleOwner(ParticleOwner * particleOwner,ResourceScope rs);
void updateParticleManager(ResourceScope rs,int renderFps=-1);
void renderParticleManager(ResourceScope rs);
void swapBuffers();

View File

@ -585,7 +585,9 @@ Unit::~Unit() {
delete currentAttackBoostOriginatorEffect.currentAppliedEffect;
currentAttackBoostOriginatorEffect.currentAppliedEffect = NULL;
Renderer::getInstance().cleanupParticleSystems(attackParticleSystems,rsGame);
//Renderer::getInstance().cleanupParticleSystems(attackParticleSystems,rsGame);
Renderer::getInstance().removeParticleSystemsForParticleOwner(this,rsGame);
#ifdef LEAK_CHECK_UNITS
Unit::mapMemoryList2[this->unitPath] = this->getId();
@ -630,6 +632,34 @@ void Unit::dumpMemoryList() {
}
#endif
void Unit::end(ParticleSystem *particleSystem) {
vector<ParticleSystem*>::iterator iterFind = find(attackParticleSystems.begin(),attackParticleSystems.end(),particleSystem);
if(iterFind != attackParticleSystems.end()) {
attackParticleSystems.erase(iterFind);
}
vector<UnitParticleSystem*>::iterator iterFind1 = find(smokeParticleSystems.begin(),smokeParticleSystems.end(),particleSystem);
if(iterFind1 != smokeParticleSystems.end()) {
smokeParticleSystems.erase(iterFind1);
}
iterFind = find(fireParticleSystems.begin(),fireParticleSystems.end(),particleSystem);
if(iterFind != fireParticleSystems.end()) {
fireParticleSystems.erase(iterFind);
}
iterFind1 = find(damageParticleSystems.begin(),damageParticleSystems.end(),particleSystem);
if(iterFind1 != damageParticleSystems.end()) {
damageParticleSystems.erase(iterFind1);
}
iterFind1 = find(unitParticleSystems.begin(),unitParticleSystems.end(),particleSystem);
if(iterFind1 != unitParticleSystems.end()) {
unitParticleSystems.erase(iterFind1);
}
if(particleSystem == fire) {
fire = NULL;
}
}
//bool Unit::isUnitDeleted(void *unit) {
// bool result = false;
// MutexSafeWrapper safeMutex(&mutexDeletedUnits,string(__FILE__) + "_" + intToStr(__LINE__));
@ -4092,34 +4122,6 @@ bool Unit::showTranslatedTechTree() const {
return (this->game != NULL ? this->game->showTranslatedTechTree() : true);
}
void Unit::end(ParticleSystem *particleSystem) {
vector<ParticleSystem*>::iterator iterFind = find(attackParticleSystems.begin(),attackParticleSystems.end(),particleSystem);
if(iterFind != attackParticleSystems.end()) {
attackParticleSystems.erase(iterFind);
}
vector<UnitParticleSystem*>::iterator iterFind1 = find(smokeParticleSystems.begin(),smokeParticleSystems.end(),particleSystem);
if(iterFind1 != smokeParticleSystems.end()) {
smokeParticleSystems.erase(iterFind1);
}
iterFind = find(fireParticleSystems.begin(),fireParticleSystems.end(),particleSystem);
if(iterFind != fireParticleSystems.end()) {
fireParticleSystems.erase(iterFind);
}
iterFind1 = find(damageParticleSystems.begin(),damageParticleSystems.end(),particleSystem);
if(iterFind1 != damageParticleSystems.end()) {
damageParticleSystems.erase(iterFind1);
}
iterFind1 = find(unitParticleSystems.begin(),unitParticleSystems.end(),particleSystem);
if(iterFind1 != unitParticleSystems.end()) {
unitParticleSystems.erase(iterFind1);
}
if(particleSystem == fire) {
fire = NULL;
}
}
string Unit::getNetworkCRCDecHpList() const {
string result = "";
for(unsigned int index = 0; index < networkCRCDecHpList.size(); ++index) {

View File

@ -625,6 +625,7 @@ public:
void cleanupUnitParticleSystems(vector<UnitParticleSystem *> &particleSystems);
int findParticleSystems(ParticleSystem *psFind, const vector<ParticleSystem *> &particleSystems) const;
bool validateParticleSystemStillExists(ParticleSystem * particleSystem) const;
void removeParticleSystemsForParticleOwner(ParticleOwner * particleOwner);
bool hasActiveParticleSystem(ParticleSystem::ParticleSystemType type) const;
};

View File

@ -2198,6 +2198,22 @@ bool ParticleManager::validateParticleSystemStillExists(ParticleSystem * particl
return (index >= 0);
}
void ParticleManager::removeParticleSystemsForParticleOwner(ParticleOwner *particleOwner) {
if(particleOwner != NULL && particleSystems.empty() == false) {
vector<ParticleSystem *> cleanupParticleSystemsList;
for(unsigned int index = 0; index < particleSystems.size(); ++index) {
ParticleSystem *ps= particleSystems[index];
if(ps != NULL && ps->getParticleOwner() == particleOwner) {
cleanupParticleSystemsList.push_back(ps);
}
}
if(cleanupParticleSystemsList.empty() == false) {
cleanupParticleSystems(cleanupParticleSystemsList);
}
}
}
int ParticleManager::findParticleSystems(ParticleSystem *psFind, const vector<ParticleSystem *> &particleSystems) const{
int result= -1;
for(unsigned int i= 0; i < particleSystems.size(); i++){
@ -2221,6 +2237,11 @@ void ParticleManager::cleanupParticleSystems(ParticleSystem *ps) {
// }
// deleteList[ps]++;
// This code causes segfault on game end, no need to fade, just delete
//if(ps->getState() != ParticleSystem::sFade) {
// ps->fade();
//}
if(ps != NULL) {
ps->callParticleOwnerEnd(ps);
}