From 56933914fa45ff41b7b573c656f07f424000c719 Mon Sep 17 00:00:00 2001 From: Anton Tarasenko Date: Mon, 6 Mar 2023 03:26:03 +0700 Subject: [PATCH] Fix some bugs with dynamic array allocation --- sources/Data/Collections/ArrayList.uc | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/sources/Data/Collections/ArrayList.uc b/sources/Data/Collections/ArrayList.uc index b52bfb7..18d5821 100644 --- a/sources/Data/Collections/ArrayList.uc +++ b/sources/Data/Collections/ArrayList.uc @@ -96,12 +96,15 @@ public final function ArrayList SetLength(int newLength) { local int i; - if (newLength < 0) { - return self; - } + if (newLength < 0) return self; + if (storedObjects.length == newLength) return self; + for (i = newLength; i < storedObjects.length; i += 1) { FreeItem(i); } + if (storedObjects.length <= 0) { + storedObjects[0] = none; + } storedObjects.length = newLength; return self; }