diff --git a/src/Aardvark.Base.IO/BinaryReadingCoder.cs b/src/Aardvark.Base.IO/BinaryReadingCoder.cs index f3def99d..2406d1a5 100644 --- a/src/Aardvark.Base.IO/BinaryReadingCoder.cs +++ b/src/Aardvark.Base.IO/BinaryReadingCoder.cs @@ -105,7 +105,7 @@ internal bool TryGetTypeInfo(string name, out TypeInfo ti) return TypeInfo.TryGetOfFullName(name, out ti); } - private void AddRef(object obj) + private int AddRef(object obj) { int count = m_refs.Count; m_refs.Add(obj); @@ -113,6 +113,7 @@ private void AddRef(object obj) { Report.Line("{0,32} 0x{1:x}", count, obj.GetHashCode()); } + return count; } private object UseRef(int refNum) @@ -138,6 +139,7 @@ public void Code(ref object obj) var typeName = m_reader.ReadString(); TypeInfo newTypeInfo = null; TypeInfo typeInfo; + int objRef = -1; if (TryGetTypeInfo(typeName, out typeInfo)) { @@ -223,7 +225,7 @@ public void Code(ref object obj) Report.Line("{0,-34} 0x{1:x}", typeName, obj.GetHashCode()); } - if (m_doRefs) AddRef(obj); + if (m_doRefs) objRef = AddRef(obj); #region code fields based on supported interface @@ -234,6 +236,7 @@ public void Code(ref object obj) if (typeInfo.ProxyType != null) { obj = typeInfo.Proxy2ObjectFun(fcobj); + if (m_doRefs) m_refs[objRef] = obj; // fix reference after proxy conversion -> Issue when sub-object (in CodeFields) codes this object! (see #77) } else { @@ -290,6 +293,7 @@ public void Code(ref object obj) var target = new Convertible(newTypeInfo.Name, null); source.ConvertInto(target); obj = target.Data; + if (m_doRefs) m_refs[objRef] = obj; // fix reference after conversion -> Issue when sub-object (in CodeFields) codes this object! (see #77) } } }