Core crash when cancelling server timers | C++ / C# / Python | Metin2Hub | Metin2 Forum Platform
  • 🎉 Hey there! I've just launched my brand new server voting platform — Metin2 P Servers 🚀

Core crash when cancelling server timers

Designer
Developer
Member
May
Threads
31
86
1,468
83
HubMoney
1,777

AD: Mt2009 - Mobile & PC - 30 January 2026 CHECK THE PRESENTATION!

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
66
2,355
2
1,284
113
HubMoney
1,669
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.