Skip to content

Commit

Permalink
[IO] BinaryReadingCoder: patch object reference after converter/proxy…
Browse files Browse the repository at this point in the history
… conversion (#77)
  • Loading branch information
luithefirst committed Jun 10, 2022
1 parent 4eb7b47 commit 7abc796
Showing 1 changed file with 6 additions and 2 deletions.
8 changes: 6 additions & 2 deletions src/Aardvark.Base.IO/BinaryReadingCoder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,14 +105,15 @@ 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);
if ((m_debugMode & CoderDebugMode.ReportReferences) != 0)
{
Report.Line("{0,32} 0x{1:x}", count, obj.GetHashCode());
}
return count;
}

private object UseRef(int refNum)
Expand All @@ -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))
{
Expand Down Expand Up @@ -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

Expand All @@ -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
{
Expand Down Expand Up @@ -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)
}
}
}
Expand Down

0 comments on commit 7abc796

Please sign in to comment.