Added check to avoid storing nullpointers in the pointers map. Updated comments.
This commit is contained in:
@@ -139,7 +139,7 @@ public class Reader {
|
||||
/// <param name="fieldMetadata">Array of <see cref="FieldInfo"/>s containing <see cref="DNAFieldAttribute"/> attributes</param>
|
||||
/// <param name="startOffset">offset in bytes from where structure starts in the block</param>
|
||||
private void FillObject(Kaitai.BlendFile.FileBlock block, ref object? obj, FieldInfo[] fieldMetadata, long startOffset = 0) {
|
||||
if(block.Code == "ENDB") return;
|
||||
if(block.Code == "ENDB") return;// ENDB is a special block that does not contain any data
|
||||
foreach (var field in fieldMetadata) {
|
||||
//Get the DNAFieldAttribute of the current field
|
||||
var attrib = field.GetCustomAttribute<DNAFieldAttribute>();
|
||||
@@ -166,7 +166,7 @@ public class Reader {
|
||||
//Get the information of the fields of the new object
|
||||
var fieldInfo = newObj.GetType().GetFields();
|
||||
|
||||
//If the field is a pointer, we need to dereference it
|
||||
//If the field is not a pointer, we need to dereference it
|
||||
if (!attrib.IsPointer) {
|
||||
long relAddr = block.MemAddr.ToMemAddr() + offset;
|
||||
if (objects.TryGetValue((relAddr, newObj.GetType()), out object? o)) {
|
||||
@@ -177,6 +177,8 @@ public class Reader {
|
||||
//Fill the object with the data from the block (this is recursive)
|
||||
FillObject(block, ref newObj, fieldInfo, offset);
|
||||
} else { // if is a pointer, make a pointer to the pointer
|
||||
long memAddr = data.ToMemAddr();
|
||||
if (memAddr == 0) continue; //nullPointer, no need to store the reference
|
||||
pointers.TryAdd(block.MemAddr.ToMemAddr() + offset, data.ToMemAddr());
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user