- better USER clearing.

This commit is contained in:
Christoph Oelckers 2021-04-02 12:00:38 +02:00
parent 8fee2b3ed7
commit 9bae2295cc
2 changed files with 9 additions and 6 deletions

View file

@ -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));
}
//

View file

@ -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))
{