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

Task<T>崩溃的例子 #25

Closed wumiao1990 closed 2 years ago

wumiao1990 commented 2 years ago

首先在AOT定义AckMsg和IMessageTest接口,并添加泛型接口的引用

public struct AckMsg<T>
{
    public bool cancel;
    public T msg;

    public AckMsg(T msg, bool cancel)
    {
        this.msg = msg;
        this.cancel = cancel;
    }
}
public interface IMessageTest
{
    int CalculateSize();
}
public interface IMessageTest<T> : IMessageTest where T : IMessageTest<T>
{
    void MergeFrom(T message);
}
TaskAwaiter aw = default;
var c11 = new AsyncTaskMethodBuilder<AckMsg<IMessageTest>>();
c11.Start(ref stateMachine);
c11.AwaitUnsafeOnCompleted(ref aw, ref stateMachine);
c11.AwaitOnCompleted(ref aw, ref stateMachine);
c11.SetException(null);
c11.SetResult(default);
bl = aw.IsCompleted;

TaskAwaiter<AckMsg<IMessageTest>> awAckMsg = default;
var c12 = new AsyncVoidMethodBuilder();
var c12B = AsyncVoidMethodBuilder.Create();
c12.Start(ref stateMachine);
c12.AwaitUnsafeOnCompleted(ref awAckMsg, ref stateMachine);
c12.SetException(null);
c12.SetResult();

然后在热更层定义类VerifyACKTest继承IMessageTest

public class VerifyACKTest: IMessageTest<VerifyACKTest>
{
    public void MergeFrom(VerifyACKTest message)
    {
    }

    public int CalculateSize()
    {
        //throw new System.NotImplementedException();
        return 0;
    }
}

最后热更层调用Enter()方法就会崩溃

public static async void Enter()
{
    await Send<VerifyACKTest>();
}
public static async Task<AckMsg<T>> Send<T>()
{
    var tcs = new TaskCompletionSource<T>();
    Debug.Log("Send---b");
    return new AckMsg<T>(default, true);
}
pirunxi commented 2 years ago

感谢!我们很快会解决。

pirunxi commented 2 years ago

已解决