Informations
Jump to content

Lorem Ipsum...

Click to Dismiss this Notification
Ładowanie danych...

Addressing Core Crashes When Canceling Server Timers in C++


Recommended Posts

An issue often encountered in server management is the occurrence of core crashes when attempting to cancel timers. This situation arises because of the improper handling of iterators when removing timers from a map. Specifically, the iterator may increase two times due to the call to the erase() function and subsequently increase again upon entering a new loop iteration. This guide outlines a solution to effectively tackle this problem by collecting the timers to be removed and processing them after the completion of the loop.

Understanding the Issue

The issue tends to manifest after upgrading to C++11 or a newer version. The symptoms include instability when attempting to manage server timers, necessitating a careful approach to how timers are deleted and managed within the code.

Steps to Resolve the Timer Cancellation Issue

To fix the core crash in the CancelServerTimers function, follow these steps to update the questmanager.cpp file.

  1. Locate the Function
    Open questmanager.cpp and find the following function:
 
This is the hidden content, please
  1. Modify the Function
    Now, enhance the function by collecting the timers to be removed and ensuring that you manage the iterators correctly without causing a crash. Here is a suggested update to the function:
 
This is the hidden content, please

Explanation of Changes

  • Iterator Management: The function now utilizes an iterator to traverse the m_mapServerTimer, removing entries as needed while ensuring that the iterator remains valid and does not advance incorrectly after an erase().
  • Immediate Deletion: By deleting the timer immediately inside the loop, the code avoids the need for additional cleanup steps afterward, thus reducing potential errors related to managing temporary storage.

Conclusion

This update should greatly reduce the chance of core crashes when canceling server timers. By addressing the management of iterators and the proper timing of deletions, stability increases significantly. As always, after implementing code changes, thorough testing is essential to ensure everything operates smoothly.

Link to comment
Share on other sites


Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.

spacer.png

Disable AdBlock
The popup will be closed in 5 seconds...