Make sure never to call GetPSprite when the ReadyWeapon is null

This commit is contained in:
Leonard2 2016-06-01 23:00:04 +02:00
parent 9ee5e57340
commit 8244d2c844
5 changed files with 28 additions and 26 deletions

View file

@ -271,9 +271,10 @@ DEFINE_ACTION_FUNCTION_PARAMS(AActor, A_GauntletAttack)
{ {
if (!weapon->DepleteAmmo (weapon->bAltFire)) if (!weapon->DepleteAmmo (weapon->bAltFire))
return 0; return 0;
player->GetPSprite(PSP_WEAPON)->x = ((pr_gatk() & 3) - 2);
player->GetPSprite(PSP_WEAPON)->y = WEAPONTOP + (pr_gatk() & 3);
} }
player->GetPSprite(PSP_WEAPON)->x = ((pr_gatk()&3)-2);
player->GetPSprite(PSP_WEAPON)->y = WEAPONTOP + (pr_gatk()&3);
Angle = self->Angles.Yaw; Angle = self->Angles.Yaw;
if (power) if (power)
{ {
@ -440,9 +441,10 @@ DEFINE_ACTION_FUNCTION(AActor, A_FireMacePL1)
{ {
if (!weapon->DepleteAmmo(weapon->bAltFire)) if (!weapon->DepleteAmmo(weapon->bAltFire))
return 0; return 0;
player->GetPSprite(PSP_WEAPON)->x = ((pr_maceatk() & 3) - 2);
player->GetPSprite(PSP_WEAPON)->y = WEAPONTOP + (pr_maceatk() & 3);
} }
player->GetPSprite(PSP_WEAPON)->x = ((pr_maceatk() & 3) - 2);
player->GetPSprite(PSP_WEAPON)->y = WEAPONTOP + (pr_maceatk() & 3);
ball = P_SpawnPlayerMissile(self, PClass::FindActor("MaceFX1"), self->Angles.Yaw + (((pr_maceatk() & 7) - 4) * (360. / 256))); ball = P_SpawnPlayerMissile(self, PClass::FindActor("MaceFX1"), self->Angles.Yaw + (((pr_maceatk() & 7) - 4) * (360. / 256)));
if (ball) if (ball)
{ {
@ -1158,11 +1160,11 @@ IMPLEMENT_CLASS (APhoenixRodPowered)
void APhoenixRodPowered::EndPowerup () void APhoenixRodPowered::EndPowerup ()
{ {
Owner->player->GetPSprite(PSP_WEAPON)->SetState(SisterWeapon->GetReadyState());
DepleteAmmo (bAltFire); DepleteAmmo (bAltFire);
Owner->player->refire = 0; Owner->player->refire = 0;
S_StopSound (Owner, CHAN_WEAPON); S_StopSound (Owner, CHAN_WEAPON);
Owner->player->ReadyWeapon = SisterWeapon; Owner->player->ReadyWeapon = SisterWeapon;
Owner->player->GetPSprite(PSP_WEAPON)->SetState(SisterWeapon->GetReadyState());
} }
class APhoenixFX1 : public AActor class APhoenixFX1 : public AActor

View file

@ -934,8 +934,6 @@ void cht_Take (player_t *player, const char *name, int amount)
player->ReadyWeapon = nullptr; player->ReadyWeapon = nullptr;
player->PendingWeapon = WP_NOCHANGE; player->PendingWeapon = WP_NOCHANGE;
player->GetPSprite(PSP_WEAPON)->SetState(nullptr);
player->GetPSprite(PSP_FLASH)->SetState(nullptr);
} }
} }

View file

@ -1001,8 +1001,6 @@ void AActor::ClearInventory()
{ {
player->ReadyWeapon = nullptr; player->ReadyWeapon = nullptr;
player->PendingWeapon = WP_NOCHANGE; player->PendingWeapon = WP_NOCHANGE;
player->GetPSprite(PSP_WEAPON)->SetState(nullptr);
player->GetPSprite(PSP_FLASH)->SetState(nullptr);
} }
} }

View file

@ -1031,6 +1031,11 @@ DEFINE_ACTION_FUNCTION(AInventory, A_Lower)
{ {
return 0; return 0;
} }
if (nullptr == player->ReadyWeapon)
{
P_BringUpWeapon(player);
return 0;
}
psp = player->GetPSprite(PSP_WEAPON); psp = player->GetPSprite(PSP_WEAPON);
if (player->morphTics || player->cheats & CF_INSTANTWEAPSWITCH) if (player->morphTics || player->cheats & CF_INSTANTWEAPSWITCH)
{ {
@ -1084,6 +1089,10 @@ DEFINE_ACTION_FUNCTION(AInventory, A_Raise)
P_DropWeapon(player); P_DropWeapon(player);
return 0; return 0;
} }
if (player->ReadyWeapon == nullptr)
{
return 0;
}
psp = player->GetPSprite(PSP_WEAPON); psp = player->GetPSprite(PSP_WEAPON);
psp->y -= RAISESPEED; psp->y -= RAISESPEED;
if (psp->y > WEAPONTOP) if (psp->y > WEAPONTOP)
@ -1091,14 +1100,7 @@ DEFINE_ACTION_FUNCTION(AInventory, A_Raise)
return 0; return 0;
} }
psp->y = WEAPONTOP; psp->y = WEAPONTOP;
if (player->ReadyWeapon != nullptr) psp->SetState(player->ReadyWeapon->GetReadyState());
{
psp->SetState(player->ReadyWeapon->GetReadyState());
}
else
{
psp->SetState(nullptr);
}
return 0; return 0;
} }

View file

@ -1376,14 +1376,16 @@ void APlayerPawn::MorphPlayerThink ()
void APlayerPawn::ActivateMorphWeapon () void APlayerPawn::ActivateMorphWeapon ()
{ {
PClassActor *morphweapon = PClass::FindActor (MorphWeapon); PClassActor *morphweapon = PClass::FindActor (MorphWeapon);
DPSprite *pspr = player->GetPSprite(PSP_WEAPON);
player->PendingWeapon = WP_NOCHANGE; player->PendingWeapon = WP_NOCHANGE;
pspr->y = WEAPONTOP;
if (player->ReadyWeapon != nullptr)
{
player->GetPSprite(PSP_WEAPON)->y = WEAPONTOP;
}
if (morphweapon == nullptr || !morphweapon->IsDescendantOf (RUNTIME_CLASS(AWeapon))) if (morphweapon == nullptr || !morphweapon->IsDescendantOf (RUNTIME_CLASS(AWeapon)))
{ // No weapon at all while morphed! { // No weapon at all while morphed!
player->ReadyWeapon = nullptr; player->ReadyWeapon = nullptr;
pspr->SetState(nullptr);
} }
else else
{ {
@ -1398,14 +1400,14 @@ void APlayerPawn::ActivateMorphWeapon ()
} }
if (player->ReadyWeapon != nullptr) if (player->ReadyWeapon != nullptr)
{ {
pspr->SetState(player->ReadyWeapon->GetReadyState()); player->GetPSprite(PSP_WEAPON)->SetState(player->ReadyWeapon->GetReadyState());
}
else
{
pspr->SetState(nullptr);
} }
} }
player->GetPSprite(PSP_FLASH)->SetState(nullptr);
if (player->ReadyWeapon != nullptr)
{
player->GetPSprite(PSP_FLASH)->SetState(nullptr);
}
player->PendingWeapon = WP_NOCHANGE; player->PendingWeapon = WP_NOCHANGE;
} }