tuyoogame / huatuo

huatuo是一个特性完整、零成本、高性能、低内存的近乎完美的Unity全平台原生c#热更方案。 Huatuo is a fully featured, zero-cost, high-performance, low-memory solution for Unity's all-platform native c# hotfix
MIT License
2.31k stars 377 forks source link

release dll会出现的问题 #29

Closed tinygridlock closed 2 years ago

tinygridlock commented 2 years ago

using System; using System.Collections.Generic; using UnityEngine;

public class App { public static int Main() { Test3(); Test4(); Test6(); Test7(); return 0; }

public static void Test3()
{
    Debug.LogError("Test3");
    //release会崩 debug不崩
    var a1 = new A1();
    a1.Test<string>((a) => { });
    a1.Test<string>((a) => { });
}

public class A1
{
    public void Test<T>(Action<T> callback)
    {
        callback?.Invoke(default);
    }
}

public static void Test4()
{
    Debug.LogError("Test4");
    //release会崩 debug不崩
    var b = new B2();
    b.Dict = new Dictionary<string, string>();
    b.Dict.Add("123", "123");
    b.Dict["123"] = "456";
    Debug.LogError(b.Dict["123"]);
}

public class B2
{
    public Dictionary<string, string> Dict { get; set; }
}

public static void Test6()
{
    Debug.LogError("Test6");
    //release下输出错误
    var a = new[] {1, 2, 3};
    Debug.LogError(a[0]);
    Swap1(a, 0, 1);
    Debug.LogError(a[0]); //release输出1 debug输出2
    Swap2(a, 0, 2);
    Debug.LogError(a[0]); //release输出1 debug输出3
}

public static void Swap1(int[] arr, int idx1, int idx2)
{
    var temp = arr[idx1];
    arr[idx1] = arr[idx2];
    arr[idx2] = temp;
}

public static void Swap2<T>(T[] arr, int idx1, int idx2)
{
    var temp = arr[idx1];
    arr[idx1] = arr[idx2];
    arr[idx2] = temp;
}

public static void Test7()
{
    Debug.LogError("Test7");
    //release下输出错误
    var aa = new[,]
    {
        {1, 2, 3},
        {4, 5, 6}
    };
    Debug.LogError(aa[0, 0]);
    Debug.LogError(aa[0, 1]);
    Debug.LogError(aa[0, 2]);
    Debug.LogError(aa[1, 0]);
    Debug.LogError(aa[1, 1]);
    Debug.LogError(aa[1, 2]);
}

}

release下编译出的dll 附上dll的压缩包 HotFix.zip

pirunxi commented 2 years ago

确认bug。已修复提交。 dup指令的bug引起。