Skip to content

Commit

Permalink
- better USER clearing.
Browse files Browse the repository at this point in the history
  • Loading branch information
coelckers committed Apr 21, 2021
1 parent 8fee2b3 commit 9bae229
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 6 deletions.
13 changes: 8 additions & 5 deletions source/games/sw/src/game.h
Expand Up @@ -1134,14 +1134,17 @@ using ROTATORp = ROTATOR*;

struct USER
{
// These are for easy zero-init of USERs without having to be on the lookout for non-trivial members.
void* operator new(size_t alloc)
// C++'s default init rules suck, so we have to help it out a bit to do what we need (i.e. setting all POD members to 0.
USER()
{
return M_Calloc(alloc, 1);
memset(&WallP, 0, sizeof(USER) - myoffsetof(USER, WallP));
}
void operator delete (void* mem)

void Clear()
{
M_Free(mem);
rotator.Clear();
WallShade.Clear();
memset(&WallP, 0, sizeof(USER) - myoffsetof(USER, WallP));
}

//
Expand Down
2 changes: 1 addition & 1 deletion source/games/sw/src/save.cpp
Expand Up @@ -284,7 +284,7 @@ FSerializer& Serialize(FSerializer& arc, const char* keyname, USER& w, USER* def
if (!def)
{
def = &nuluser;
if (arc.isReading()) w = {};
if (arc.isReading()) w.Clear();
}
if (arc.BeginObject(keyname))
{
Expand Down

0 comments on commit 9bae229

Please sign in to comment.