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

[Bug]: 对于有复合目录的插件,如果engine->loadFile失败,那么engine->eval返回错误 #38

Open
XY0797 opened this issue Feb 22, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@XY0797
Copy link
Contributor

XY0797 commented Feb 22, 2024

Describe the bug

比如说LLSE-FakePlayer插件,它除了LLSE-FakePlayer.js外,还有LangPack等文件夹
如果目录为英文,那么engine->loadFile可以成功,插件正常加载
如果目录为英文,那么engine->loadFile会失败,因为脚本引擎的文件读入未使用wchar
理论上engine->eval可以解决问题,但是engine->loadFile却是失败的

To Reproduce

LLSE-FakePlayer.zip

BDS放中文目录下,这个插件会无法正常加载

Expected behavior

正常加载

Screenshots

image
图片中我打上了调试信息,报错是 expecting '(',非常奇怪

Platform

Windows 11 22H2

BDS Version

1.20.62.02

LeviLamina Version

LeviLamina-0.8.3

LegacyScriptEngine Version

latest

Additional context

我调试过代码,错误出现在\src\legacy\main\PluginManager.cpp:156

engine->eval(*scripts, ENGINE_OWN_DATA()->pluginFileOrDirPath);

传入后js引擎无法正常加载,报错是 expecting '(',这非常奇怪

我一开始怀疑是上一次那个中文路径的issues修复的不彻底,但是很快我就发现不是这个的问题

因为我发现哪怕是在纯英语(这个文件名是纯英语)的目录环境下,如果我注释外面的engine->loadFile(realPath);,指定使用engine->eval的方法来加载,那么也会报同样的错误

于是我去看了脚本引擎的loadFile函数源代码
ScriptX\backend\JavaScriptCore\JscEngine.cc:181

Local<Value> JscEngine::loadFile(const Local<String>& scriptFile) {
  if(scriptFile.toString().empty())
    throw Exception("script file no found");
  Local<Value> content = internal::readAllFileContent(scriptFile);
  if(content.isNull())
    throw Exception("can't load script file");

  std::string sourceFilePath = scriptFile.toString();
  std::size_t pathSymbol = sourceFilePath.rfind("/");
  if(pathSymbol != std::string::npos)
    sourceFilePath = sourceFilePath.substr(pathSymbol + 1);
  else
  {
    pathSymbol = sourceFilePath.rfind("\\");
    if(pathSymbol != std::string::npos)
      sourceFilePath = sourceFilePath.substr(pathSymbol + 1);
  }
  Local<String> sourceFileName = String::newString(sourceFilePath);
  return eval(content.asString(), sourceFileName);
}

我发现这里有一个去除前缀只保留文件名的操作

于是我就写了个同样的取文件名函数,套上去,调试发现还是一样报错

我也尝试过显式转换数据类型为script::Local<script::String>,但是也是报一样的错误

显然这不是一个简单的错误,我已经无力解决,希望开发组从头排查一遍,看看到底是什么问题

@XY0797 XY0797 added the bug Something isn't working label Feb 22, 2024
@ShrBox
Copy link
Member

ShrBox commented Feb 23, 2024

develop分支已经重写了插件加载部分,应该能解决此问题

@XY0797
Copy link
Contributor Author

XY0797 commented Feb 24, 2024

develop分支已经重写了插件加载部分,应该能解决此问题

确实解决了问题,不过dev分支下无法正常使用插件了,似乎是功能对接还没写完
那等分支合并并且测试通过后再关闭issue

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

No branches or pull requests

3 participants
@ShrBox @XY0797 and others