chexiongsheng / puerts_unity_demo

unity demo for puerts
Other
198 stars 80 forks source link

有个崩溃 #8

Closed littlesome closed 4 years ago

littlesome commented 4 years ago

这个代码跑几秒后Unity会crash

using UnityEngine;
using Puerts;
using System;
using System.Collections;

namespace PuertsTest
{
    public class MyRunner : MonoBehaviour
    {
        static MyRunner instance;
        JsEnv jsEnv;

        void Start()
        {
            instance = this;
            jsEnv = new JsEnv();

            jsEnv.Eval(@"
                const CS = require('csharp');

                function toPromise(op) {
                    return new Promise(function(resolve, reject) {
                        CS.PuertsTest.MyRunner.Yield(op, function() {
                            resolve();
                        });
                    });
                }

                async function httpGet() {
                    var www = CS.UnityEngine.Networking.UnityWebRequest.Get('http://www.baidu.com');
                    www.timeout = 1;
                    var op = www.SendWebRequest(); 
                    await toPromise(op);
                    console.log(www.responseCode);
                }

                setInterval(function() {
                    for (var i = 0; i < 10; i++) {
                        httpGet();
                    }
                }, 0);
            ");
        }

        void OnDestroy()
        {
            jsEnv.Dispose();
        }

        void Update()
        {
            jsEnv.Tick();
        }

        private IEnumerator CoroutineYield(object to_yield, Action callback)
        {
            if (to_yield is IEnumerator)
                yield return StartCoroutine((IEnumerator)to_yield);
            else
                yield return to_yield;

            callback();
        }

        public static void Yield(object to_yield, Action callback)
        {
            instance.StartCoroutine(instance.CoroutineYield(to_yield, callback));
        }
    }
}
littlesome commented 4 years ago

编了个带调试信息的v8,开了dcheck_always_on=true,崩溃栈如下

global-handles.cc 462行这里

  Node* next_free() {
    DCHECK_EQ(FREE, state());
    return data_.next_free;
  }

断言信息: Debug check failed: FREE == state() (0 vs. 2).

感觉可能是哪里Handle使用有问题,或者是内存损坏

崩溃栈: image