Background:
I want the max level attainable from XP to be set according to flags. I use a global_player event_connect to set a qglobal CharMaxLevel to 50, however when I set Character:PerCharacterQglobalMaxLevel = true, logging a character in, regardless of qglobal values, causes a zone crash.
After some digging, the crash is coming from a call to QGlobalCache->GetBucket(), but this call works fine in other sections of code which seem identical. Here's a breakdown of troubleshooting I've done so far.
Troubleshooting
First I used a return value to see which line was causing the crash (should have just turned logs on, but hey)
Code:
uint32 Client::GetCharMaxLevelFromQGlobal() {
return 50; <- this works
QGlobalCache *char_c = nullptr;
char_c = this->GetQGlobals();
return 50; <- this works
std::list<QGlobal> globalMap;
uint32 ntype = 0;
return 50; <- this works
if(char_c) {
QGlobalCache::Combine(globalMap, char_c->GetBucket(), ntype, this->CharacterID(), zone->GetZoneID()); <-- this is causing an error
}
return 50; <- this doesn't work
...
This gave me the orange line
So I checked command_globalview, which is a similar function to see if there were differences. Syntax and parameters appear the same. I then tried using the command in game to see if it crashed the zone, and it didn't.
Code:
void command_globalview(Client *c, const Seperator *sep)
{
NPC * npcmob = nullptr;
if(c->GetTarget() && c->GetTarget()->IsNPC())
{...
}
else
{
QGlobalCache *char_c = nullptr;
QGlobalCache *zone_c = nullptr;
char_c = c->GetQGlobals();
zone_c = zone->GetQGlobals();
std::list<QGlobal> globalMap;
uint32 ntype = 0;
if(char_c)
{
QGlobalCache::Combine(globalMap, char_c->GetBucket(), ntype, c->CharacterID(), zone->GetZoneID()); <-- This works fine
}
...
Then I started looking at logs for more detail and saw that the crash appears to be happening after the QGlobalCache::GetBucket() call.
Code:
[Tue Jan 28 23:25:29 2020] [Crash] x:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\list (1022): std::list<QGlobal,std::allocator<QGlobal> >::end
[Tue Jan 28 23:25:29 2020] [Crash] x:\program files (x86)\microsoft visual studio\2017\community\vc\tools\msvc\14.16.27023\include\list (800): std::list<QGlobal,std::allocator<QGlobal> >::list<QGlobal,std::allocator<QGlobal> >
[Tue Jan 28 23:25:29 2020] [Crash] x:\emuserver\zone\qglobals.h (29): QGlobalCache::GetBucket
[Tue Jan 28 23:25:29 2020] [Crash] x:\emuserver\zone\exp.cpp (1119): Client::GetCharMaxLevelFromQGlobal
[Tue Jan 28 23:25:29 2020] [Crash] x:\emuserver\zone\client.cpp (272): Client::Client
I'm not familiar enough with c to go much further at this point, any advice would be much appreciated!