#FFI seg faults when not used with a debugger

1 messages · Page 1 of 1 (latest)

rugged ermine
#

I'm trying to use Raylib inside of Bun but when I'm running my program, it works the first time but after that it crashes
And when I tried to see what's going on with a debugger, the program didn't crash
I tried with every version of bun from 1.0 to 1.0.20 and it still segfault

Here's the code

import * as raylibImport from "./index";

const cStr = (str: string) => Buffer.from(str + "\0");

const raylib = raylibImport.loadRaylib("libraylib.so");

raylib.symbols.InitWindow(800, 450, cStr("Hello World"));
while(!raylib.symbols.WindowShouldClose()) {
  raylib.symbols.BeginDrawing();
  raylib.symbols.ClearBackground(-1);
  raylib.symbols.EndDrawing();
}

raylib.symbols.CloseWindow();
raylib.close();

The function loadRaylib is an auto-generated function which contains every functions of raylib (I didn't format the code, and it's pretty long: https://paste.rs/SmfZp)

uneven olive
#

@rugged ermine it only crashes when you don't attach a debugger?

rugged ermine
#

Yes

#

I couldn't try with gcc because I don't know how to use it

uneven olive
#

is the debugger catching anything

rugged ermine
#

I don't think
It doesn't show any log apart from Raylib's logs

uneven olive
#

@rugged ermine does it crash if you remove the DISPLAY part

#

before the command

rugged ermine
#

No, I only needed it because I was using Sway inside of WSL

uneven olive
#

so it ONLY crashes when the display is set?

rugged ermine
rugged ermine
#

Just tried with gdb and it works
I also tried with Bun 1.0.21 and it still crashes

uneven olive
#

I don't have any ideas

#

It sounds like it's throwing something or has a check if you're using a debugger

#

@rugged ermine is your library built in debug mode?

#

the .so file

#

I didn't think of that lol

#

that's probably the problem

rugged ermine
#

Somehow the first time in ran it after stripping it, it worked but running it a second time made it segfault

uneven olive
#

@rugged ermine try building it again

#

and see if it works the first time you build it

#

it might be caching it somehow

rugged ermine
#

It's still crashing

#

Ok I think I found the problem
I removed most functions in the functions.ts file and it works
Probably an issue with Bun's parsing

#

I'll try to find how many functions it can handle

#

It somewhat works with around 130 functions but it crashes at 150

#

It exactly crashes when there's 147 FFI functions

uneven olive
#

This is the second time someone has reported this issue

#

You should make a GitHub issue about it