[Solved] Löve segfaults on OS X when loading dylibs

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
Trebor
Prole
Posts: 2
Joined: Fri Jul 30, 2021 6:53 pm

[Solved] Löve segfaults on OS X when loading dylibs

Post by Trebor »

TL;DR: Pull the "Lua" file buried in

Code: Select all

love.app/Contents/Framework/Lua.framework/Versions/A/Lua
, use that to replace the "libluajit.a".

Or, if you don't want to recompile: First make sure that your dylib file loads fine with the standard luajit distribution. Then replace the "Lua" file buried in

Code: Select all

love.app/Contents/Framework/Lua.framework/Versions/A/Lua
with "libluajit.dylib" (but rename it to "Lua", without filename extension).

----------------------------------------------------------------------------------

After some work to pin down the problem, I made a minimal example for this.

I wrote a small C library, almost a direct copy of the example in the book Programming in Lua.

Code: Select all

#include "lauxlib.h"
#include "lua.h"
#include "lualib.h"
#include <math.h>

static int l_sin (lua_State *L) {
      double d = luaL_checknumber(L, 1);  /* get argument */
      lua_pushnumber(L, sin(d));  /* push result */
      return 1;  /* number of results */
}
static const struct luaL_reg mylib [] = {
      {"sin", l_sin},
      {NULL, NULL}  /* sentinel */
};

int luaopen_mylib (lua_State *L) {
      luaL_openlib(L, "mylib", mylib, 0);
      return 1;
}
I compiled this with "liblua.a" of version 5.1.4, generating the file "hw.dylib", as provided in the attachment.

Next, a miniature lua script ("main.lua") in the same directory:

Code: Select all

l = package.loadlib("hw.dylib", "luaopen_mylib")
a = l()
print(a.sin(1))
Run with the standard distribution of lua, it gives the correct result 0.8414709848079. However, starting love at this directory resulted in a Segmentation Fault. Below is a section of the crash report. I will post the full report if that is needed.

Code: Select all

Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0   hw.dylib                      	0x0000000008a36aa3 lua_pushvalue + 195
1   hw.dylib                      	0x0000000008a4f10c luaL_findtable + 28
2   hw.dylib                      	0x0000000008a4efcb luaL_openlib + 91
3   hw.dylib                      	0x0000000008a362c5 luaopen_mylib + 37
4   LuaJIT.LuaJIT                 	0x0000000101f8be56 0x101f89000 + 11862
I am using the newest version of Love, 11.3. I started Love using the commandline (PathToLoveApplication)/Contents/MacOS/love.

Can anyone provide a clue to why this is happening, and a pointer to some possible solutions? Any help is appreciated!

Although it works, I haven't yet investigated further. I think the answer lies in the makefile in https://github.com/slime73/love-apple-dependencies.
Attachments
attachment.zip
Contains four files mentioned in the post.
(167.1 KiB) Downloaded 70 times
Last edited by Trebor on Sat Jul 31, 2021 7:17 am, edited 2 times in total.
Trebor
Prole
Posts: 2
Joined: Fri Jul 30, 2021 6:53 pm

Re: Löve segfaults on OS X when loading dylibs

Post by Trebor »

I also tried using luajit. If the code is compiled with "luajit.a" as provided by luajit, and the script run with the luajit executable, it also goes fine. I'm looking at the lua component in love to find out the problem.
Post Reply

Who is online

Users browsing this forum: No registered users and 6 guests