diff options
| author | fusion32 <marcopuzziello@gmail.com> | 2025-09-12 02:28:35 -0300 |
|---|---|---|
| committer | fusion32 <marcopuzziello@gmail.com> | 2025-09-12 02:28:35 -0300 |
| commit | af49c0bd105d244afc169df15d14e5401cb4e362 (patch) | |
| tree | 20ddd9df14098c82996913d4f2678af4ae9f70aa /src/crmain.cc | |
| parent | 02ae61bca44238ab5d0f09590c3b705dd4b67914 (diff) | |
| download | game-af49c0bd105d244afc169df15d14e5401cb4e362.tar.gz game-af49c0bd105d244afc169df15d14e5401cb4e362.zip | |
fix crash when a summon would attack before despawning (#28)
Diffstat (limited to 'src/crmain.cc')
| -rw-r--r-- | src/crmain.cc | 20 |
1 files changed, 14 insertions, 6 deletions
diff --git a/src/crmain.cc b/src/crmain.cc index f2f13ac..15c72b8 100644 --- a/src/crmain.cc +++ b/src/crmain.cc @@ -457,12 +457,12 @@ int TCreature::Damage(TCreature *Attacker, int Damage, int DamageType){ return 0; } - if(this->Type == PLAYER){ - if(this->Connection != NULL && Attacker != NULL){ + if(Attacker != NULL && this->Type == PLAYER){ + if(this->Connection != NULL){ SendMarkCreature(this->Connection, Attacker->ID, COLOR_BLACK); } - if(Attacker != NULL && Attacker->Type == PLAYER + if(Attacker->Type == PLAYER && DamageType != DAMAGE_POISON_PERIODIC && DamageType != DAMAGE_FIRE_PERIODIC && DamageType != DAMAGE_ENERGY_PERIODIC){ @@ -479,7 +479,15 @@ int TCreature::Damage(TCreature *Attacker, int Damage, int DamageType){ uint32 MasterID = Attacker->GetMaster(); if(MasterID != 0){ - Responsible = GetCreature(MasterID); + // NOTE(fusion): This is very subtle but we could hit a case where the + // master logs out or dies but the summon has a ToDoAttack queued, in + // which case it would try to attack before checking whether it should + // despawn in `TMonster::IdleStimulus`, causing `Responsible` to be NULL + // even though `Attacker` is not. + TCreature *Master = GetCreature(MasterID); + if(Master != NULL){ + Responsible = Master; + } } Attacker->BlockLogout(60, this->Type == PLAYER); @@ -653,8 +661,8 @@ int TCreature::Damage(TCreature *Attacker, int Damage, int DamageType){ } this->Skills[SKILL_HITPOINTS]->Change(-Damage); - if(Responsible != NULL){ - ASSERT(Attacker != NULL); + if(Attacker != NULL){ + ASSERT(Responsible != NULL); if(Responsible == Attacker){ this->Combat.AddDamageToCombatList(Attacker->ID, Damage); }else{ |
