diff --git a/src/dobjtype.cpp b/src/dobjtype.cpp index 76330867e7..313ee7389c 100644 --- a/src/dobjtype.cpp +++ b/src/dobjtype.cpp @@ -3194,34 +3194,37 @@ void PClass::Derive(PClass *newclass, FName name) void PClass::InitializeDefaults() { - assert(Defaults == NULL); - Defaults = (BYTE *)M_Malloc(Size); - - // run the constructor on the defaults to set the vtbl pointer which is needed to run class-aware functions on them. - // Temporarily setting bSerialOverride prevents linking into the thinker chains. - auto s = DThinker::bSerialOverride; - DThinker::bSerialOverride = true; - ConstructNative(Defaults); - DThinker::bSerialOverride = s; - // We must unlink the defaults from the class list because it's just a static block of data to the engine. - DObject *optr = (DObject*)Defaults; - GC::Root = optr->ObjNext; - optr->ObjNext = nullptr; - optr->SetClass(this); - - - // Copy the defaults from the parent but leave the DObject part alone because it contains important data. - if (ParentClass->Defaults != NULL) + if (IsKindOf(RUNTIME_CLASS(PClassActor))) { - memcpy(Defaults + sizeof(DObject), ParentClass->Defaults + sizeof(DObject), ParentClass->Size - sizeof(DObject)); - if (Size > ParentClass->Size) + assert(Defaults == NULL); + Defaults = (BYTE *)M_Malloc(Size); + + // run the constructor on the defaults to set the vtbl pointer which is needed to run class-aware functions on them. + // Temporarily setting bSerialOverride prevents linking into the thinker chains. + auto s = DThinker::bSerialOverride; + DThinker::bSerialOverride = true; + ConstructNative(Defaults); + DThinker::bSerialOverride = s; + // We must unlink the defaults from the class list because it's just a static block of data to the engine. + DObject *optr = (DObject*)Defaults; + GC::Root = optr->ObjNext; + optr->ObjNext = nullptr; + optr->SetClass(this); + + + // Copy the defaults from the parent but leave the DObject part alone because it contains important data. + if (ParentClass->Defaults != NULL) { - memset(Defaults + ParentClass->Size, 0, Size - ParentClass->Size); + memcpy(Defaults + sizeof(DObject), ParentClass->Defaults + sizeof(DObject), ParentClass->Size - sizeof(DObject)); + if (Size > ParentClass->Size) + { + memset(Defaults + ParentClass->Size, 0, Size - ParentClass->Size); + } + } + else + { + memset(Defaults + sizeof(DObject), 0, Size - sizeof(DObject)); } - } - else - { - memset(Defaults + sizeof(DObject), 0, Size - sizeof(DObject)); } if (bRuntimeClass) diff --git a/src/dthinker.cpp b/src/dthinker.cpp index ac0abf3c57..7b63d2635a 100644 --- a/src/dthinker.cpp +++ b/src/dthinker.cpp @@ -710,8 +710,12 @@ class DThinkerIterator : public DObject, public FThinkerIterator { DECLARE_CLASS(DThinkerIterator, DObject) + DThinkerIterator() + { + } + public: - DThinkerIterator(PClass *cls = nullptr, int statnum = MAX_STATNUM + 1) + DThinkerIterator(PClass *cls, int statnum = MAX_STATNUM + 1) : FThinkerIterator(cls, statnum) { } diff --git a/src/dthinker.h b/src/dthinker.h index fce3e4f7af..e0dcb607f8 100644 --- a/src/dthinker.h +++ b/src/dthinker.h @@ -125,6 +125,9 @@ public: FThinkerIterator (const PClass *type, int statnum, DThinker *prev); DThinker *Next (bool exact = false); void Reinit (); + +protected: + FThinkerIterator() {} }; template class TThinkerIterator : public FThinkerIterator diff --git a/src/p_maputl.cpp b/src/p_maputl.cpp index ea2434b255..5771461bb1 100644 --- a/src/p_maputl.cpp +++ b/src/p_maputl.cpp @@ -1177,6 +1177,11 @@ class DBlockThingsIterator : public DObject, public FMultiBlockThingsIterator { DECLARE_CLASS(DBlockThingsIterator, DObject); FPortalGroupArray check; +protected: + DBlockThingsIterator() + :FMultiBlockThingsIterator(check) + { + } public: FMultiBlockThingsIterator::CheckResult cres; @@ -1186,7 +1191,7 @@ public: return FMultiBlockThingsIterator::Next(&cres); } - DBlockThingsIterator(AActor *origin = nullptr, double checkradius = -1, bool ignorerestricted = false) + DBlockThingsIterator(AActor *origin, double checkradius = -1, bool ignorerestricted = false) : FMultiBlockThingsIterator(check, origin, checkradius, ignorerestricted) { cres.thing = nullptr; diff --git a/src/p_maputl.h b/src/p_maputl.h index 81d3c9d133..5e869c4e6c 100644 --- a/src/p_maputl.h +++ b/src/p_maputl.h @@ -327,6 +327,8 @@ class FMultiBlockThingsIterator void startIteratorForGroup(int group); +protected: + FMultiBlockThingsIterator(FPortalGroupArray &check) : checklist(check) {} public: struct CheckResult diff --git a/src/scripting/zscript/zcc_compile.cpp b/src/scripting/zscript/zcc_compile.cpp index 43f5b6774e..610e7554d0 100644 --- a/src/scripting/zscript/zcc_compile.cpp +++ b/src/scripting/zscript/zcc_compile.cpp @@ -1874,7 +1874,14 @@ void ZCCCompiler::InitDefaults() if (!c->Type()->IsDescendantOf(RUNTIME_CLASS(AActor))) { if (c->Defaults.Size()) Error(c->cls, "%s: Non-actor classes may not have defaults", c->Type()->TypeName.GetChars()); - if (c->Type()->ParentClass) c->Type()->ParentClass->DeriveData(c->Type()); + if (c->Type()->ParentClass) + { + auto ti = static_cast(c->Type()); + FString mename = ti->TypeName.GetChars(); + + ti->InitializeDefaults(); + ti->ParentClass->DeriveData(ti); + } } else {