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

luajit syntax error during pre-compilation. #20517

Open
semgilo opened this issue May 14, 2020 · 16 comments
Open

luajit syntax error during pre-compilation. #20517

semgilo opened this issue May 14, 2020 · 16 comments

Comments

@semgilo
Copy link

semgilo commented May 14, 2020

  • cocos2d-x version:4.0
  • devices test on:三星Galaxy S9+
  • developing environments
    • NDK version:
    • Xcode version:
    • VS version:
    • browser type and version:

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
Copy link
Author

semgilo commented May 18, 2020

@minggo

@Glidos
Copy link
Contributor

Glidos commented May 30, 2020

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
Copy link
Author

semgilo commented May 31, 2020

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

@Glidos
Copy link
Contributor

Glidos commented May 31, 2020

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
Copy link
Contributor

Glidos commented Jun 1, 2020

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
Copy link
Contributor

Glidos commented Jun 1, 2020

v3.17.1 also looks to show the problem

@Glidos
Copy link
Contributor

Glidos commented Jun 2, 2020

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
Copy link
Contributor

Glidos commented Jun 3, 2020

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
Copy link
Contributor

Glidos commented Jun 4, 2020

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
Copy link
Author

semgilo commented Jun 4, 2020

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

@Glidos
Copy link
Contributor

Glidos commented Jun 4, 2020

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
Copy link
Contributor

Glidos commented Jun 4, 2020

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
Copy link
Contributor

Glidos commented Jun 6, 2020

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

@zhangxiansheng
Copy link

@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
Copy link
Contributor

Glidos commented May 3, 2022

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
Copy link

@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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants