• Announcement:
    In order to download VIP files, you need to UPGRADE your account.

Core crash when cancelling server timers

Metin2Hub Bot
M2Hub Bot
Feb
Threads
65
1,091
1
412
83
HubMoney
770
When cancelling server timers a core will crash as it is removing a timer from the map and increasing the iterator twice by calling erase() function and afterwards increasing it once again when entering a new cycle of loop. One way of solving this issue is to first collect the timers which must be removed and clean them up at the end. You can also add a simple counter which is increased at each end of the loop's cycle and remove the timer directly from the first loop by specifying the position with the counter itself.



Note that seems to appear after upgrading code to C++11 or higher.



Replace the following function inside questmanager.cpp:


void CQuestManager::CancelServerTimers(DWORD arg)
{
vector<pair<string, DWORD>> ServerTimersToDelete;

for (const auto& kv : m_mapServerTimer) {
if (kv.first.second == arg) {
LPEVENT event = kv.second;
event_cancel(&event);
ServerTimersToDelete.push_back(kv.first);
}
}

// Delete all the required server timers
for (const auto &timer : ServerTimersToDelete)
m_mapServerTimer.erase(timer);

// Clean up
ServerTimersToDelete.clear();
}
 
Metin2Hub Bot
M2Hub Bot
Feb
Threads
65
1,091
1
412
83
HubMoney
770
When cancelling server timers a core will crash as it is removing a timer from the map and increasing the iterator twice by calling erase() function and afterwards increasing it once again when entering a new cycle of loop. One way of solving this issue is to first collect the timers which must be removed and clean them up at the end. You can also add a simple counter which is increased at each end of the loop's cycle and remove the timer directly from the first loop by specifying the position with the counter itself.



Note that seems to appear after upgrading code to C++11 or higher.



Replace the following function inside questmanager.cpp:


void CQuestManager::CancelServerTimers(DWORD arg)
{
vector<pair<string, DWORD>> ServerTimersToDelete;

for (const auto& kv : m_mapServerTimer) {
if (kv.first.second == arg) {
LPEVENT event = kv.second;
event_cancel(&event);
ServerTimersToDelete.push_back(kv.first);
}
}

// Delete all the required server timers
for (const auto &timer : ServerTimersToDelete)
m_mapServerTimer.erase(timer);

// Clean up
ServerTimersToDelete.clear();
}

Hello dear user,

Your post will be under surveillance by bots for the next few hours.

Forum description : Metin2 private server, Metin2 download, Metin2 support, Metin2 Forum, Metin2 Pvp Servers, Errors, Bugs, Requests, Metin2 Pvp Forum, Everything About Metin2.
 
Top
AdBlock Detected

We get it, advertisements are annoying!

Sure, ad-blocking software does a great job at blocking ads, but it also blocks useful features of our website. For the best site experience please disable your AdBlocker.

I've Disabled AdBlock