cocos2d / cocos2d-x

Cocos2d-x is a suite of open-source, cross-platform, game-development tools utilized by millions of developers across the globe. Its core has evolved to serve as the foundation for Cocos Creator 1.x & 2.x.
https://www.cocos.com/en/cocos2d-x
18.22k stars 7.06k forks source link

luajit syntax error during pre-compilation. #20517

Open semgilo opened 4 years ago

semgilo commented 4 years ago

Steps to Reproduce:

  1. Create a new lua project
  2. Compile 64bit lua files on Android Studio
  3. Run [LUA ERROR] load "assets/src/64bit/main.luac", error: syntax error during pre-compilation.
semgilo commented 4 years ago

@minggo

Glidos commented 4 years ago

I was just about to open a new issue, but this one may be the cause of what I'm seeing. I have a lua-based app that works when I run Android debug builds. It also works if I run 32bit release builds, but when I include arm64-v8a, I get just a black unresponsive screen. Disabling lua compilation makes it work. Please let me know if my problem is unrelated and I will open a new issue.

semgilo commented 4 years ago

@Glidos Yes, but I don't know how to fix it.

Glidos commented 4 years ago

I know very little about the inner workings of Lua, but I read of this error message being caused by mixing Lua versions. Could it be that we are compiling during the build with one version and then running on the device using another? (Mad wild guess - likely a daft suggestion)

Glidos commented 4 years ago

proj.android/app/build.gradle has lines that look specifically designed to handle this case, and presumably it worked when those lines were added. Perhaps git bisect from the commit that introduced that would find it.

Glidos commented 4 years ago

v3.17.1 also looks to show the problem

Glidos commented 4 years ago

Some possibly useful information. I unpacked my broken APK and discovered that main.luac and 64bit/main.luac are identical. And I can see in the debugger that it is that, first-loaded file that produces the syntax error. Somehow, the use of the 64bit compiler during the build isn't producing anything different from the 32bit version.

Glidos commented 4 years ago

I'm pretty sure I've found the problem and it's easily fixable. In luajit 2.1.0-beta3, the default 64it builds, other than arm, use a 32bit compatible bytecode. One has to set 64bit compatility explicitly in when building. (The default has changed since in later git versions).

Mike Pall explained a test to apply to executables to find out which bytecode they are using, and the test shows ours in cocos2d-x are wrong. (Not surprising given that was the default at the time).

Later I will try to build the correct ones.

Glidos commented 4 years ago

FIxed it, for Windows at least. I recompiled luajit 2.1.0-beta3 for 64bits with the gc64 option and substituted that within cocos2d-x and now it produces working release builds.

I can look at making the appropriate changes for all of the platforms within the plugin repository, unless someone else has that in hand. Please let me know the status of this.

semgilo commented 4 years ago

@Glidos Did you recompile luajit for android arm64 platform? or luajit.exe compiler?

Glidos commented 4 years ago

I recompiled the Window 64bit executable used in cocos2d-x's luacompile plugin for the cocos2d-console. Our release APKs were wrong only in the compiled lua that they included. The arm lua executables are fine. My change will fix the build process only under Windows. Similar recompilation may be needed for Mac and Linux.

Glidos commented 4 years ago

Strange! The problem doesn't seem to exist in git at the v4.0 tag. I checked the submodule sha at that point and it links to the end of the metal branch in cocos2d-console and lua51.dll is fine at that point., but the one in the downloadable v4.0 zip release is broken (or was when I downloaded it).

Glidos commented 4 years ago

Sorry, I got that wrong: it is broken at the end of cocos2d-console:metal-support. It was 96768f3371cff6545daed79b0c6d4a9ee5cc4b8e that broke it.

zhangxiansheng commented 2 years ago

@Glidos Hi, is this bug fixed? I download cocos2d-x 4.0 from https://www.cocos.com/cocos2dx But I have the same "Lua Error" when I use LuaJit for "arm64-v8a" Android 11

[LUA ERROR] load "assets/src/64bit/main.luac", error: syntax error during pre-compilation.

I am using Lua 5.1.4, LuaJIT 2.1.0-beta3

You are my saviour. Could you tell me what should I do?

Glidos commented 2 years ago

I can't remember much about this, but try running luajit -e "print(require('ffi').abi('gc64'))" with the two versions of luajit that you can find at cocos2d-x\tools\cocos2d-console\plugins\plugin_luacompile\bin\32bit\luajit-win32.exe and cocos2d-x\tools\cocos2d-console\plugins\plugin_luacompile\bin\64bit\luajit-win32.exe They should differ. If they don't then I'll see if I can remember what I did.

Codeboy-cn commented 2 years ago

@zhangxiansheng

  1. get file : https://github.com/LuaJIT/LuaJIT/releases/tag/v2.1.0-beta3
  2. execute "msvcbuild.bat gc64" compile LuaJIT
  3. copy the compiled lua51.dll to cocos2d-x-4.0\tools\cocos2d-console\plugins\plugin_luacompile\bin\64bit\lua51.dll
  4. bug has been fixed