Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash caused by IsReflect #2342

Merged
merged 1 commit into from Sep 17, 2020
Merged

Fix crash caused by IsReflect #2342

merged 1 commit into from Sep 17, 2020

Conversation

ghost
Copy link

@ghost ghost commented Sep 16, 2020

This PR fixes #2340. The IsReflect() method caused crashes because it tried to access targets even when they doesn't exist (Switch skills never have targets).

@@ -1428,6 +1428,8 @@ bool Game_BattleAlgorithm::Skill::IsReflected() const {
if (party_target) {
std::vector<Game_Battler*> targetlist;
party_target->GetActiveBattlers(targetlist);
// Return false if no targets exist
if (targetlist.size() == 0) return false;
Copy link
Contributor

@fmatthew5876 fmatthew5876 Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Is this needed? The loop below will already not iterate anything if the list is empty

Copy link
Author

@ghost ghost Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You are right, this check is unnecessary.

@@ -1439,6 +1441,8 @@ bool Game_BattleAlgorithm::Skill::IsReflected() const {
}
}
} else {
// Return false if no target exist
Copy link
Contributor

@fmatthew5876 fmatthew5876 Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

How about just else if (GetTarget() != nullptr) and then fall through if no targets

Copy link
Author

@ghost ghost Sep 16, 2020

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Your proposal works for me. I changed the code according to your suggestion.

The IsReflect() method caused crashes because it tried to access
targets even when they doesn't exist (Switch skills never have
targets).
@ghost
Copy link
Author

ghost commented Sep 16, 2020

Updated the PR.

@fmatthew5876 fmatthew5876 added the backport to stable Pull requests with changes backported to our stable, maintenance branch label Sep 16, 2020
@Ghabry Ghabry added this to the 0.6.3 milestone Sep 16, 2020
Ghabry
Ghabry approved these changes Sep 17, 2020
@Ghabry Ghabry merged commit 13a8421 into EasyRPG:master Sep 17, 2020
7 checks passed
@ghost ghost deleted the issue-2340 branch Sep 18, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backport to stable Pull requests with changes backported to our stable, maintenance branch Battle Crash Regression
Development

Successfully merging this pull request may close these issues.

rm2k - Game shutdown after switch skill in a battle
3 participants