focus-creative-games / hybridclr

HybridCLR是一个特性完整、零成本、高性能、低内存的Unity全平台原生c#热更新解决方案。 HybridCLR is a fully featured, zero-cost, high-performance, low-memory solution for Unity's all-platform native c# hotupdate.
https://code-philosophy.com/
MIT License
6.6k stars 670 forks source link

Span<T>在自定义结构体上报错NotSupportedException #123

Closed Weiged closed 9 months ago

Weiged commented 9 months ago

Describe the bug | 描述问题 A clear and concise description of what the bug is. 热更dll中无法使用Span传非基础结构体类型作为泛型参数,运行后报错NotSupportedException

Enviroment | 环境

To Reproduce | 复制步骤 替换demo工程中的Entry.cs内容为以下内容: `using System; using System.Collections; using System.Collections.Generic; using System.Linq; using System.Reflection; using UnityEngine;

public static class Entry { public static void Start() { Debug.Log("[Entry::Start] 看到这个日志表示你成功运行了热更新代码"); Run_InstantiateByAddComponent(); Run_AOTGeneric(); Run_SpanCustomStruct(); }

private static void Run_InstantiateByAddComponent()
{
    // 代码中动态挂载脚本
    GameObject cube = new GameObject("");
    cube.AddComponent<InstantiateByAddComponent>();
}

struct MyVec3
{
    public int x;
    public int y;
    public int z;
}

private static void Run_AOTGeneric()
{
    // 泛型实例化
    var arr = new List<MyVec3>();
    arr.Add(new MyVec3 { x = 1 });
    Debug.Log("[Demos.Run_AOTGeneric] 成功运行泛型代码");
}

private static void Run_SpanCustomStruct()
{
    var array = new MyStruct[] { new(1), new(2), new(3) };
    var sum = 0;
    foreach (ref readonly var s in array.AsSpan())
    {
        sum += s.Value;
    }
    Debug.Log("[Demos.Run_SpanCustomStruct 成功运行Span<结构体> sum:" + sum);
}

private struct MyStruct
{
    public readonly int Value;

    public MyStruct(int value)
    {
        Value = value;
    }
}

}`

截屏2024-02-21 10 45 18

pirunxi commented 9 months ago

Unity 2021不支持这种用法,升级到Unity 2022就可以正常工作了。 你反馈bug前请先验证这段代码在aot中能正常运行。

Weiged commented 9 months ago

Unity 2021不支持这种用法,升级到Unity 2022就可以正常工作了。 你反馈bug前请先验证这段代码在aot中能正常运行。

我就是试过了才提issue的,把我当弱智了?

pirunxi commented 9 months ago

就你这种大爷态度,建议还是用其他方案,让你省心一点

Weiged commented 9 months ago

就你这种大爷态度,建议还是用其他方案,让你省心一点

你这个回复态度很好哦?你试过aot中验证这个代码吗?

pirunxi commented 9 months ago

下个版本会包含这个修复。