-
-
Notifications
You must be signed in to change notification settings - Fork 678
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: check null pointer from master on no-pvp combat. #3355
Conversation
That way, you'll end up ruining the fun for people who enjoy crashing the rival's OT lol. |
src/creatures/combat/combat.cpp
Outdated
@@ -427,14 +427,15 @@ ReturnValue Combat::canDoCombat(const std::shared_ptr<Creature> &attacker, const | |||
} | |||
} | |||
|
|||
if (target && target->isSummon() && target->getMaster()->getPlayer()) { | |||
if (target && target->isSummon() && target->getMaster() && target->getMaster()->getPlayer()) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can move this for the begin of function:
const auto &targetMaster = target ? target->getMaster() : nullptr;
After from here:
canary/src/creatures/combat/combat.cpp
Line 346 in 8b0b0ef
const auto &attackerPlayer = attacker->getPlayer(); |
This will avoid increasing the reference count (as this function is called a lot, it will increase the reference every time it is called).
And you can check this: too:
canary/src/creatures/combat/combat.cpp
Line 406 in 8b0b0ef
if (target->isSummon() && target->getMaster()->getPlayer() && target->getZoneType() == ZONE_NOPVP) { |
And remove this:
canary/src/creatures/combat/combat.cpp
Line 410 in 8b0b0ef
const auto &targetMaster = target->getMaster(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The code has been refactored.
Can test again?
Thanks dude 👯
|
Now:
Reduces redundancy by consolidating checks.
Improves readability and maintainability by organizing conditions in a more logical and grouped manner.
Makes it easier to understand the flow of the function and how different entity types are handled (players, summons, monsters, NPC's).