Skip to content
This repository has been archived by the owner on Jul 1, 2024. It is now read-only.

NullReferenceException when iterating through IEnumrable<XrefInstance> #85

Open
GoldenretriverYT opened this issue Feb 27, 2022 · 1 comment

Comments

@GoldenretriverYT
Copy link

Hello,
I am getting a NullReferenceException when iterating through the IEnumerable object that is returned by XrefScanner.XrefScan - I have already looked at the generated IL code, and it seems like it happens when it moves onto the next entry in the IEnumerable.

Exception:

[11:39:18.482] [Arcadius_Mod] [ERROR] System.NullReferenceException: Object reference not set to an instance of an object
  at System.Buffer.memcpy1 (System.Byte* dest, System.Byte* src, System.Int32 size) [0x00002] in <e1319b7195c343e79b385cd3aa43f5dc>:0
  at System.Buffer.Memcpy (System.Byte* dest, System.Byte* src, System.Int32 size) [0x00058] in <e1319b7195c343e79b385cd3aa43f5dc>:0
  at System.Runtime.InteropServices.Marshal.ReadInt64 (System.IntPtr ptr) [0x00015] in <e1319b7195c343e79b385cd3aa43f5dc>:0
  at UnhollowerRuntimeLib.XrefScans.XrefScanner.XrefGlobalClassFilter (System.IntPtr movTarget) [0x0001d] in <8eb030b38f51415daeb459bae49fe0fc>:0
  at UnhollowerRuntimeLib.XrefScans.XrefScanner+<>c.<XrefScan>b__0_0 (UnhollowerRuntimeLib.XrefScans.XrefInstance it) [0x00009] in <8eb030b38f51415daeb459bae49fe0fc>:0
  at System.Linq.Enumerable+WhereEnumerableIterator`1[TSource].MoveNext () [0x00037] in <fbb5ed17eb6e46c680000f8910ebb50c>:0
  at MyMod.Class1.OnApplicationLateStart () [0x000a0] in <6cd357c9270946a7aa332220af7ac4ad>:0
  at MelonLoader.MelonHandler+<>c.<OnApplicationLateStart_Mods>b__31_0 (MelonLoader.MelonMod x) [0x00010] in <239dd078bb4e49c8a1ff8200d76f2e32>:0
  at MelonLoader.MelonHandler.InvokeMelonMethod[T] (System.Collections.Generic.List`1[T]& melons, MelonLoader.MelonHandler+InvokeMelonMethodDelegate`1[T] method, System.Boolean remove_failed) [0x00032] in <239dd078bb4e49c8a1ff8200d76f2e32>:0

Code:

public override void OnApplicationLateStart()
{
    logger = LoggerInstance;

    MethodBase mb = typeof(Menu_Blacksmith).GetMethod("RepairTool");

    if (mb == null)
    {
        LoggerInstance.Error("Unable to find RepairTool for some god damn reason");
    }
    else
    {
        var instances = XrefScanner.XrefScan(mb);

        if (instances == null)
        {
            LoggerInstance.Error("Instances is null");
        }
        else
        {
            foreach (XrefInstance instance in instances)
            {
                MethodBase calledMethod = instance.TryResolve();
                LoggerInstance.Msg(calledMethod?.Name);
            }
        }
    }

    UniverseLib.Universe.Init(OnUniverseLibInit);
}
@knah
Copy link
Owner

knah commented Mar 28, 2022

More information is needed here - which game is it, and is it 32-bit or 64-bit one?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants