-
Notifications
You must be signed in to change notification settings - Fork 1.1k
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 scheduler leaks #4882
base: master
Are you sure you want to change the base?
Fix scheduler leaks #4882
Changes from 5 commits
c419a21
4e0fd25
ba5a525
abdf6c5
32d01a9
3f23308
8699451
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
|
@@ -1508,26 +1508,25 @@ void Player::checkTradeState(const Item* item) | |||||
} | ||||||
} | ||||||
|
||||||
void Player::setNextWalkActionTask(SchedulerTask* task) | ||||||
void Player::setNextWalkActionTask(SchedulerTask_ptr task) | ||||||
{ | ||||||
if (walkTaskEvent != 0) { | ||||||
g_scheduler.stopEvent(walkTaskEvent); | ||||||
walkTaskEvent = 0; | ||||||
} | ||||||
|
||||||
delete walkTask; | ||||||
walkTask = task; | ||||||
walkTask = std::move(task); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I believe if you use
Suggested change
You may skip one deletion. This is absolutely minor, change it only if you touch this code again 😆 There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. why? deletion will be moved to end of the scope |
||||||
} | ||||||
|
||||||
void Player::setNextActionTask(SchedulerTask* task, bool resetIdleTime /*= true */) | ||||||
void Player::setNextActionTask(SchedulerTask_ptr task, bool resetIdleTime /*= true */) | ||||||
{ | ||||||
if (actionTaskEvent != 0) { | ||||||
g_scheduler.stopEvent(actionTaskEvent); | ||||||
actionTaskEvent = 0; | ||||||
} | ||||||
|
||||||
if (task) { | ||||||
actionTaskEvent = g_scheduler.addEvent(task); | ||||||
actionTaskEvent = g_scheduler.addEvent(std::move(task)); | ||||||
if (resetIdleTime) { | ||||||
this->resetIdleTime(); | ||||||
} | ||||||
|
@@ -3407,13 +3406,13 @@ void Player::doAttacking(uint32_t) | |||||
result = Weapon::useFist(this, attackedCreature); | ||||||
} | ||||||
|
||||||
SchedulerTask* task = createSchedulerTask(std::max<uint32_t>(SCHEDULER_MINTICKS, delay), | ||||||
[id = getID()]() { g_game.checkCreatureAttack(id); }); | ||||||
SchedulerTask_ptr task = createSchedulerTask(std::max<uint32_t>(SCHEDULER_MINTICKS, delay), | ||||||
[id = getID()]() { g_game.checkCreatureAttack(id); }); | ||||||
if (!classicSpeed) { | ||||||
setNextActionTask(task, false); | ||||||
setNextActionTask(std::move(task), false); | ||||||
} else { | ||||||
g_scheduler.stopEvent(classicAttackEvent); | ||||||
classicAttackEvent = g_scheduler.addEvent(task); | ||||||
classicAttackEvent = g_scheduler.addEvent(std::move(task)); | ||||||
} | ||||||
|
||||||
if (result) { | ||||||
|
@@ -3469,8 +3468,7 @@ void Player::onWalkAborted() | |||||
void Player::onWalkComplete() | ||||||
{ | ||||||
if (walkTask) { | ||||||
walkTaskEvent = g_scheduler.addEvent(walkTask); | ||||||
walkTask = nullptr; | ||||||
walkTaskEvent = g_scheduler.addEvent(std::move(walkTask)); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Prone to use-after-move, you still need There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think your suggestion is good, good capture, I was thinking about this: walkTaskEvent = g_scheduler.addEvent(SchedulerTask_ptr(walkTask.release())); However, I am not convinced about having to build a new unique_ptr, although it should be free, I don't know how profitable it is. The option to assign nullptr is correct and I like it |
||||||
} | ||||||
} | ||||||
|
||||||
|
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.
I believe in these situations we should use
auto
, because it doesn't even matter what the type is here, we just pass it along. Wdyt?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.
or just move the creation directly to method call, then we can let the compiler do its best thing
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.
it's looks like some abomination
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.
std::move shouldnt be needed there, but yeah, might be true, it doesnt look the best