Author Topic: Which version of LuaJIT for Solarus?  (Read 1668 times)

stewart

  • Newbie
  • *
  • Posts: 6
    • View Profile
Which version of LuaJIT for Solarus?
« on: May 27, 2015, 02:21:03 am »
Hi,

I'm trying to build the quest editor for Mac OS.

Solarus library runs fine and ZSDX is playable, but when loading a quest I get a segfault in the lua code called from Solarus::LuaData::import_from_file:

Code: [Select]
Crashed Thread:  0  Dispatch queue: com.apple.main-thread

Exception Type:  EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: KERN_INVALID_ADDRESS at 0x0000000000000008

VM Regions Near 0x8:
-->
    __TEXT                 000000010656f000-00000001067e7000 [ 2528K] r-x/rwx SM=COW  /Users/USER/*

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   libluajit-5.1.2.dylib          0x000000010b49cf69 lua_pushfstring + 89
1   libluajit-5.1.2.dylib          0x000000010b4ab2dd luaL_loadfilex + 77
2   libsolarus.dylib              0x000000010705f0a2 Solarus::LuaData::import_from_file(std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > const&) + 50
3   solarus-quest-editor          0x00000001066be57d QuestProperties::reload() + 141
4   solarus-quest-editor          0x000000010670d31f QuestProperties::qt_static_metacall(QObject*, QMetaObject::Call, int, void**) + 223
5   org.qt-project.QtCore          0x000000010be58ad8 QMetaObject::activate(QObject*, int, int, void**) + 2840
6   solarus-quest-editor          0x000000010670cb9d Quest::root_path_changed(QString const&) + 77
7   solarus-quest-editor          0x00000001066ab18f Quest::set_root_path(QString const&) + 223
8   solarus-quest-editor          0x00000001065c3668 MainWindow::open_quest(QString const&) + 88
9   solarus-quest-editor          0x0000000106694fc6 main + 822
10  libdyld.dylib                  0x00007fff9187f7e1 start + 1

Which version of LuaJIT is required for Solarus?

I'm using the git version of Solarus, and solarus-quest-editor, and release version 2.0.4 of LuaJIT.

Cheers,
  Stewart

Christopho

  • Administrator
  • Hero Member
  • *****
  • Posts: 1182
    • View Profile
Re: Which version of LuaJIT for Solarus?
« Reply #1 on: May 27, 2015, 08:43:21 am »
Strange. I am using LuaJIT 2.0.2 but this should not be a problem with a more recent version.
Can you also try to compile Solarus with normal Lua instead of LuaJIT? And see if you still have this crash?
To do so, remove your cmake cache and reconfigure cmake with -DSOLARUS_USE_LUAJIT=OFF

stewart

  • Newbie
  • *
  • Posts: 6
    • View Profile
Re: Which version of LuaJIT for Solarus?
« Reply #2 on: May 27, 2015, 04:48:56 pm »
OK, it looks like LuaJIT is the problem. Using standard Lua works fine. I have 5.3.0 installed.

I reduced the offending code to the following standalone program which works under Lua but crashes under LuaJIT, so I don't think the problem is related to Solarus.

Code: [Select]
#include <lua.h>
#include <lauxlib.h>

int import_from_file(char * file_name) {
printf("import_from_file %s\n", file_name);

lua_State* l = luaL_newstate();
if (luaL_loadfile(l, file_name) != 0) {
fprintf(stderr, "Failed to load file %s: %s\n", file_name, lua_tostring(l, -1));
    lua_pop(l, 1);
return 0;
}

printf("result: %s\n", lua_tostring(l,0));
lua_close(l);
return 1;
}

int main(int argc, char ** argv) {
import_from_file("/Users/stewart/local/git/solarus-quest-editor/build/test/data/quest.dat");
}

With a few small tweaks I managed to build the quest editor, and tested it by loading ZSDX (screenshot attached). The main issue is that the math functions such as floor() are not in the std:: namespace.

One small problem is that when running a quest from the editor, the game window does not appear to receive keyboard events. For example, ZSDX gets stuck at the "press the space bar" stage. It works fine when using solarus_run.