diff --git a/shared/src/main/scala/io/kaitai/struct/ClassCompiler.scala b/shared/src/main/scala/io/kaitai/struct/ClassCompiler.scala index a73e289fa..b3ac0d9e9 100644 --- a/shared/src/main/scala/io/kaitai/struct/ClassCompiler.scala +++ b/shared/src/main/scala/io/kaitai/struct/ClassCompiler.scala @@ -140,9 +140,9 @@ class ClassCompiler( curClass.params ) compileInit(curClass) + curClass.instances.foreach { case (instName, _) => lang.instanceClear(instName) } if (config.readWrite) { curClass.instances.foreach { case (instName, instSpec) => - lang.instanceClear(instName) instSpec match { case _: ParseInstanceSpec => lang.instanceWriteFlagInit(instName)