Skip to content

Commit

Permalink
Merge pull request #2168 from Ghabry/battle-bug-reports
Browse files Browse the repository at this point in the history
Battle 2k: Prevent crash when battle action is NULL
  • Loading branch information
carstene1ns authored Apr 25, 2020
2 parents b28066d + 8dcfa41 commit 88439c4
Show file tree
Hide file tree
Showing 2 changed files with 28 additions and 1 deletion.
7 changes: 7 additions & 0 deletions src/scene_battle.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -627,6 +627,13 @@ void Scene_Battle::CreateEnemyActionSkill(Game_Enemy* enemy, const RPG::EnemyAct

void Scene_Battle::ActionSelectedCallback(Game_Battler* for_battler) {
assert(for_battler->GetBattleAlgorithm() != nullptr);

if (for_battler->GetBattleAlgorithm() == nullptr) {
Output::Warning("ActionSelectedCallback: Invalid action for battler %d (%s)",
for_battler->GetId(), for_battler->GetName().c_str());
Output::Warning("Please report a bug!");
}

battle_actions.push_back(for_battler);

if (for_battler->GetType() == Game_Battler::Type_Ally) {
Expand Down
22 changes: 21 additions & 1 deletion src/scene_battle_rpg2k.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -317,7 +317,12 @@ void Scene_Battle_Rpg2k::ProcessActions() {
// such as death, paralyze, confuse, etc..
PrepareBattleAction(battler);
}

auto* alg = battler->GetBattleAlgorithm().get();
if (alg == nullptr) {
Output::Warning("ProcessActions: Invalid action for battler %d (%s)", battler->GetId(), battler->GetName().c_str());
Output::Warning("Please report a bug!");
}

if (ProcessBattleAction(alg)) {
battle_action_pending = false;
Expand Down Expand Up @@ -395,6 +400,12 @@ bool Scene_Battle_Rpg2k::ProcessNextSubState(int substate, Game_BattleAlgorithm:
}

bool Scene_Battle_Rpg2k::ProcessBattleAction(Game_BattleAlgorithm::AlgorithmBase* action) {
if (action == nullptr) {
Output::Warning("ProcessBattleAction: Invalid battle action");
Output::Warning("Please report a bug!");
return true;
}

if (!battle_action_pending) {
// First time we are called, do initialization.
battle_action_wait = 0;
Expand Down Expand Up @@ -538,7 +549,8 @@ bool Scene_Battle_Rpg2k::ProcessActionUsage1(Game_BattleAlgorithm::AlgorithmBase
if (!action->GetTarget()) {
// No target but not a target-only action.
// Maybe a bug report will help later
Output::Warning("Battle: BattleAction without valid target.");
Output::Warning("ProcessActionUsage1: BattleAction without valid target.");
Output::Warning("Please report a bug!");
return true;
}

Expand Down Expand Up @@ -1313,6 +1325,14 @@ void Scene_Battle_Rpg2k::CreateExecutionOrder() {
[](Game_Battler* l, Game_Battler* r) {
return l->GetBattleOrderAgi() > r->GetBattleOrderAgi();
});

for (const auto& battler : battle_actions) {
if (std::count(battle_actions.begin(), battle_actions.end(), battler) > 1) {
Output::Warning("CreateExecutionOrder: Battler %d (%s) has multiple battle actions", battler->GetId(), battler->GetName().c_str());
Output::Warning("Please report a bug!");
break;
}
}
}

void Scene_Battle_Rpg2k::CreateEnemyActions() {
Expand Down

0 comments on commit 88439c4

Please sign in to comment.