Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Unity] Bug:Crash C#中执行ExecuteModule时如果被加载模块有语法错误Unity会崩溃 #1670

Closed
6 tasks done
daijunli opened this issue Mar 6, 2024 · 2 comments
Closed
6 tasks done
Assignees
Labels
bug Something isn't working Unity

Comments

@daijunli
Copy link

daijunli commented Mar 6, 2024

前置阅读 | Pre-reading

Puer的版本 | Puer Version

2.0.4

Unity的版本 | Unity Version

2021.3.6f1

发生在哪个平台 | Platform

Editor(win)

错误信息 | Error Message

using System;
using System.Collections;
using System.Collections.Generic;
using Puerts;
using UnityEngine;
using System.IO;
using System.Runtime.InteropServices;

public class JSLoader : DefaultLoader // ILoader,IModuleChecker
{
public bool FileExists(string filepath)
{
if (base.FileExists(filepath))
return true;
return File.Exists(filepath);
}

public string ReadFile(string filepath, out string debugpath)
{
    if (base.FileExists(filepath))
        return base.ReadFile(filepath, out debugpath);
    
    var fileContent = File.ReadAllText(filepath);
    debugpath = filepath;
    return fileContent;
}

}

//在场景中创建多个GameObject 挂载该文件,
public class TestCrash : MonoBehaviour
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int CBCreateObject();

public JsEnv env;

public static TestCrash instance;
void Awake()
{
    if (instance == null)
    {
        instance = this;
        env = new JsEnv(new JSLoader(), 9229);
    }
    IntPtr pCallback = Marshal.GetFunctionPointerForDelegate<CBCreateObject>(CBCreateTest);
    TestCBCrash(pCallback);
}

static int CBCreateTest()
{
    Debug.Log("=======CBCreateTest=====");
    instance.env.Eval($@"

console.log('============test js env==');
");

    // AModule.mjs 的import路径上有语法错误,会崩溃
    instance.env.ExecuteModule("Assets/Resources/AModule.mjs");
    return 0;

}
[DllImport("forTest", CallingConvention = CallingConvention.Cdecl)]
public static extern void TestCBCrash(IntPtr callback);

}

C++ forTest.dll 的测试代码

![@fv{J2L 82EX3J### 前置阅读 | Pre-reading

Puer的版本 | Puer Version

2.0.4

Unity的版本 | Unity Version

2021.3.6f1

发生在哪个平台 | Platform

Editor(win)

错误信息 | Error Message

using System;
using System.Collections;
using System.Collections.Generic;
using Puerts;
using UnityEngine;
using System.IO;
using System.Runtime.InteropServices;

public class JSLoader : DefaultLoader // ILoader,IModuleChecker
{
public bool FileExists(string filepath)
{
if (base.FileExists(filepath))
return true;
return File.Exists(filepath);
}

public string ReadFile(string filepath, out string debugpath)
{
    if (base.FileExists(filepath))
        return base.ReadFile(filepath, out debugpath);
    
    var fileContent = File.ReadAllText(filepath);
    debugpath = filepath;
    return fileContent;
}

}

//在场景中创建多个GameObject 挂载该文件,
public class TestCrash : MonoBehaviour
{
[UnmanagedFunctionPointer(CallingConvention.Cdecl)]
delegate int CBCreateObject();

public JsEnv env;

public static TestCrash instance;
void Awake()
{
    if (instance == null)
    {
        instance = this;
        env = new JsEnv(new JSLoader(), 9229);
    }
    IntPtr pCallback = Marshal.GetFunctionPointerForDelegate<CBCreateObject>(CBCreateTest);
    TestCBCrash(pCallback);
}

static int CBCreateTest()
{
    Debug.Log("=======CBCreateTest=====");
    instance.env.Eval($@"

console.log('============test js env==');
");

    // AModule.mjs 的import路径上有语法错误,会崩溃
    instance.env.ExecuteModule("Assets/Resources/AModule.mjs");
    return 0;

}
[DllImport("forTest", CallingConvention = CallingConvention.Cdecl)]
public static extern void TestCBCrash(IntPtr callback);

}

C++ forTest.dll 的测试代码

图片

问题重现 | Bug reproduce

TestPuertsCrash.zip
9A%ONSBIEEVP_}3V1Z5B~VW

@daijunli daijunli added bug Something isn't working Unity labels Mar 6, 2024
@daijunli daijunli changed the title [Unity] Bug:Crash 在C++回调函数到,C#中执行ExecuteModule时如果被加载模块有语法错误Unity会崩溃 [Unity] Bug:Crash C#中执行ExecuteModule时如果被加载模块有语法错误Unity会崩溃 Mar 6, 2024
@chexiongsheng
Copy link
Collaborator

你在QQ群上不是说要自行定位下吗?又没结果?

@chexiongsheng
Copy link
Collaborator

补充了UT用例,在 6d385b5 版本可以重现

活动的测试运行已中止。原因: 测试主机进程崩溃 : #
# Fatal error in , line 0
# Check failed: has_pending_exception().
#
#
#
#FailureMessage Object: 000000059F8FD380
==== C stack trace ===============================
        v8::base::debug::StackTrace::StackTrace [0x00007FF97B1F48AB+27]
        v8::platform::DefaultPlatform::PostJob [0x00007FF97AF36461+225]
        V8_Fatal [0x00007FF97AF45872+162]
        v8::internal::Isolate::PropagatePendingExceptionToExternalTryCatch [0x00007FF97B064404+292]
        v8::internal::Isolate::OptionalRescheduleException [0x00007FF97B06297D+29]
        v8::Module::InstantiateModule [0x00007FF97AF10B85+357]
        puerts::esmodule::ExecuteModule [0x00007FF97AE7AE6E+638] (F:\puerts\unity\native_src\Src\BackendEnv.cpp:572)
        v8::internal::FunctionCallbackArguments::Call [0x00007FF97B24FA5D+317]
        v8::internal::CustomArguments<v8::FunctionCallbackInfo<v8::Value> >::GetReturnValue<v8::internal::Object> [0x00007FF97B24ECF5+1573]
        v8::internal::Builtins::InvokeApiFunction [0x00007FF97B2501E4+644]
        v8::internal::Execution::CallWasm [0x00007FF97AF4AA05+1013]
        v8::internal::Execution::Call [0x00007FF97AF4A48F+191]
        v8::Function::Call [0x00007FF97AEF5A58+648]
        puerts::JSFunction::Invoke [0x00007FF97AE89D30+496] (F:\puerts\unity\native_src\Src\JSFunction.cpp:111)
        InvokeJSFunction [0x00007FF97AE754A3+19] (F:\puerts\unity\native_src\Src\Puerts.cpp:711)
        (No symbol) [0x00007FF93C09EF76]

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working Unity
Projects
None yet
Development

No branches or pull requests

3 participants