From e9041c0697fefbb3a4bae44b74e707130c54d2aa Mon Sep 17 00:00:00 2001 From: "alexey.lysiuk" Date: Fri, 27 Jul 2018 18:16:48 +0300 Subject: [PATCH] - fixed potential garbage collection of still referenced objects Objects from dynamic array stored in items of array of structures were incorrectly treated as unreachable https://forum.zdoom.org/viewtopic.php?t=61354 --- src/scripting/types.cpp | 17 +++++++++++++++++ src/scripting/types.h | 1 + 2 files changed, 18 insertions(+) diff --git a/src/scripting/types.cpp b/src/scripting/types.cpp index d683e62d6..7aed2850c 100644 --- a/src/scripting/types.cpp +++ b/src/scripting/types.cpp @@ -1748,6 +1748,23 @@ void PArray::SetPointer(void *base, unsigned offset, TArray *special) } } +//========================================================================== +// +// PArray :: SetPointerArray +// +//========================================================================== + +void PArray::SetPointerArray(void *base, unsigned offset, TArray *special) +{ + if (ElementType->isStruct()) + { + for (unsigned int i = 0; i < ElementCount; ++i) + { + ElementType->SetPointerArray(base, offset + ElementSize * i, special); + } + } +} + //========================================================================== // // NewArray diff --git a/src/scripting/types.h b/src/scripting/types.h index 5c55db6c1..0817aa99d 100644 --- a/src/scripting/types.h +++ b/src/scripting/types.h @@ -485,6 +485,7 @@ public: void SetDefaultValue(void *base, unsigned offset, TArray *special) override; void SetPointer(void *base, unsigned offset, TArray *special) override; + void SetPointerArray(void *base, unsigned offset, TArray *ptrofs = NULL) override; }; class PStaticArray : public PArray