Skip to content

Commit

Permalink
KOTOR: Fix crash when equipping a left weapon after drawing
Browse files Browse the repository at this point in the history
For future reference, using [] operator on a map will create an element with a default value (nullptr). Also, inserting an element with a duplicate key ends with no-op.
  • Loading branch information
vkremianskii authored and DrMcCoy committed Mar 13, 2019
1 parent f5af771 commit 12bbc2c
Showing 1 changed file with 3 additions and 3 deletions.
6 changes: 3 additions & 3 deletions src/engines/kotorbase/creature.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -635,11 +635,11 @@ void Creature::playDefaultHeadAnimation() {
}

void Creature::playDrawWeaponAnimation() {
if (!_model || !_info.isInventorySlotEquipped(kInventorySlotRightWeapon))
if (!_model)
return;

Item *rightWeapon = _equipment[kInventorySlotRightWeapon];
Item *leftWeapon = _equipment[kInventorySlotLeftWeapon];
Item *rightWeapon = _info.isInventorySlotEquipped(kInventorySlotRightWeapon) ? _equipment[kInventorySlotRightWeapon] : nullptr;
Item *leftWeapon = _info.isInventorySlotEquipped(kInventorySlotLeftWeapon) ? _equipment[kInventorySlotLeftWeapon] : nullptr;

if (rightWeapon && !leftWeapon) {
switch (rightWeapon->getWeaponWield()) {
Expand Down

0 comments on commit 12bbc2c

Please sign in to comment.