From 0678b6bac2486dfd6d68082604464e66b04e2944 Mon Sep 17 00:00:00 2001 From: Pavel Shevaev Date: Wed, 27 Mar 2024 12:51:20 +0300 Subject: [PATCH] Fixing thread safety possible issue when reading an array of enums and fixing related bug when the target enum array property wouldn't be cleared before reading data --- src/codegen.inc.php | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/codegen.inc.php b/src/codegen.inc.php index 0002dc3..0e53152 100644 --- a/src/codegen.inc.php +++ b/src/codegen.inc.php @@ -450,9 +450,11 @@ function var_sync($fname, \mtgType $type, $buf, array $tokens, $opts) { if($type->getValue() instanceof \mtgMetaEnum) { - $str .= "MetaIO.tmp_enums_list.Clear(); if(!{$buf}.is_read) { foreach(var _enum_tmp in {$fname}) MetaIO.tmp_enums_list.Add((int)_enum_tmp); }\n"; - $str .= "MetaIO.Sync({$buf}, MetaIO.tmp_enums_list, \"{$key_name}\", {$opts});\n"; - $str .= "if({$buf}.is_read) foreach(var _int_tmp in MetaIO.tmp_enums_list) { {$fname}.Add(({$type->getValue()->getName()}) _int_tmp); }\n"; + $str .= "{\n"; + $str .= "var tmp_enums_list = new List(); if(!{$buf}.is_read) { foreach(var _enum_tmp in {$fname}) tmp_enums_list.Add((int)_enum_tmp); }\n"; + $str .= "MetaIO.Sync({$buf}, tmp_enums_list, \"{$key_name}\", {$opts});\n"; + $str .= "if({$buf}.is_read) { {$fname}.Clear(); foreach(var _int_tmp in MetaIO.tmp_enums_list) {$fname}.Add(({$type->getValue()->getName()}) _int_tmp); }\n"; + $str .= "}\n"; } else $str .= "MetaIO.Sync({$buf}, {$fname}, \"{$key_name}\", {$opts});\n";