From 2d0da4fcfa4aafe80140818c0e90071c41eb5e9b Mon Sep 17 00:00:00 2001 From: Christoph Oelckers Date: Sat, 15 Apr 2017 13:20:58 +0200 Subject: [PATCH] - fixed: Dynamic arrays of objects in structs were not registered for garbage collection. --- src/scripting/types.cpp | 24 ++++++++++++++++++++++-- src/scripting/types.h | 5 +++-- 2 files changed, 25 insertions(+), 4 deletions(-) diff --git a/src/scripting/types.cpp b/src/scripting/types.cpp index 5a8581812f..82263dfcd4 100644 --- a/src/scripting/types.cpp +++ b/src/scripting/types.cpp @@ -183,7 +183,7 @@ void PType::SetPointer(void *base, unsigned offset, TArray *stroffs) { } -void PType::SetPointerArray(void *base, unsigned offset, TArray *stroffs) const +void PType::SetPointerArray(void *base, unsigned offset, TArray *stroffs) { } @@ -1951,7 +1951,7 @@ void PDynArray::SetDefaultValue(void *base, unsigned offset, TArray *special) const +void PDynArray::SetPointerArray(void *base, unsigned offset, TArray *special) { if (ElementType->isObjectPointer()) { @@ -2185,6 +2185,26 @@ void PStruct::SetPointer(void *base, unsigned offset, TArray *special) } } +//========================================================================== +// +// PStruct :: SetPointerArray +// +//========================================================================== + +void PStruct::SetPointerArray(void *base, unsigned offset, TArray *special) +{ + auto it = Symbols.GetIterator(); + PSymbolTable::MapType::Pair *pair; + while (it.NextPair(pair)) + { + auto field = dyn_cast(pair->Value); + if (field && !(field->Flags & VARF_Transient)) + { + field->Type->SetPointerArray(base, unsigned(offset + field->Offset), special); + } + } +} + //========================================================================== // // PStruct :: WriteValue diff --git a/src/scripting/types.h b/src/scripting/types.h index d4dc196f7a..5c55db6c1a 100644 --- a/src/scripting/types.h +++ b/src/scripting/types.h @@ -125,7 +125,7 @@ public: // object is destroyed. virtual void SetDefaultValue(void *base, unsigned offset, TArray *special=NULL); virtual void SetPointer(void *base, unsigned offset, TArray *ptrofs = NULL); - virtual void SetPointerArray(void *base, unsigned offset, TArray *ptrofs = NULL) const; + virtual void SetPointerArray(void *base, unsigned offset, TArray *ptrofs = NULL); // Initialize the value, if needed (e.g. strings) virtual void InitializeValue(void *addr, const void *def) const; @@ -512,7 +512,7 @@ public: void SetDefaultValue(void *base, unsigned offset, TArray *specials) override; void InitializeValue(void *addr, const void *def) const override; void DestroyValue(void *addr) const override; - void SetPointerArray(void *base, unsigned offset, TArray *ptrofs = NULL) const override; + void SetPointerArray(void *base, unsigned offset, TArray *ptrofs = NULL) override; }; class PMap : public PCompoundType @@ -544,6 +544,7 @@ public: bool ReadValue(FSerializer &ar, const char *key,void *addr) const override; void SetDefaultValue(void *base, unsigned offset, TArray *specials) override; void SetPointer(void *base, unsigned offset, TArray *specials) override; + void SetPointerArray(void *base, unsigned offset, TArray *special) override; }; class PPrototype : public PCompoundType