C++ app unexpectedly crashing before int main(), Access reading violation


As the title suggests. Ive tried debugging and an exception is thrown when done declaring my struct.
The exact error: Exception thrown at 0x6455FF80 (ucrtbased.dll) in MyProject.exe: 0xC0000005: Access violation reading location 0x00000000.

This is the code:

struct MyOffsets {
uintptr_t T6Client = NULL;
DWORD ProcessId = NULL;

DWORD T6RZMPName = 0x2347CD4;
std::string LocalName = 0;

DWORD T6RZMPHealth = 0x21C1568;
int LocalHealth = 0;

DWORD T6RZMPZombieCount = 0x2330388;
int ZombieCount = 0;

DWORD T6RZMPWeapon1 = 0x2342BCC;
int LocalWeapon1 = 0;

DWORD T6RZMPWeapon2 = 0x2342BD4;
int LocalWeapon2 = 0;

DWORD T6RZMPWeapon3 = 0x2342BD8;
int LocalWeapon3 = 0;

DWORD T6RZMPGrenades = 0x2342BD0;
int LocalGrenades = 0;

DWORD T6RZMPPoints = 0x2347D68;
int LocalPoints = 0;

} sOffsets;

In my main.cpp I do my includes, I defined this struct, then I go into my int main. But on the very last line of the struct I get the exception I showed above. Any solutions?

asked on Stack Overflow Aug 22, 2020 by Coristat • edited Aug 22, 2020 by Blastfurnace

1 Answer


std::string LocalName = 0; attempts to pass null pointer to std::string constructor. This exhibits undefined behavior.

answered on Stack Overflow Aug 22, 2020 by Igor Tandetnik

User contributions licensed under CC BY-SA 3.0