part-cw / lambdanative

LambdaNative is a cross-platform development environment written in Scheme, supporting Android, iOS, BlackBerry 10, OS X, Linux, Windows, OpenBSD, NetBSD, FreeBSD and OpenWrt.
http://www.lambdanative.org
Other
1.4k stars 86 forks source link

Calling (rtaudio-stop) from rtaudio module causes segmentation fault #407

Closed goober99 closed 3 years ago

goober99 commented 3 years ago

I'm using rtaudio to generate a tone. I want to be able to stop the tone after a specified amount of time, but whenever I call (rtaudio-stop), the app dies with a segmentation fault.

I'm using Lambda Native 1.1.1 (but also tested with 1.0.13 and had the same issue) on Debian Sid. To make sure it wasn't something else in my code, I added a button to the DemoRTAudio that all it does is call (rtaudio-stop), and it segfaults too:

(glgui-button-string gui (/ w 4) (/ h 3) (/ w 2) 32 "Stop" ascii_18.fnt
        (lambda (g w t x y) (rtaudio-stop)))

When you click the Stop button, it segfaults. And here's the GDB backtrace of the segmentation fault with the demo compiled for debug:

#0  0x000055555614ba01 in ___lbltbl ()
#1  0x0000555555ef4910 in rtaudio_stop ()
    at /home/matthew/.cache/lambdanative/linux/build/862140480.c:543
#2  0x0000555555ef4dce in ___H__20_862140480_23_1 (
    ___ps=0x555556bdfea0 <___gstate0>) at 862140480.c:417
#3  0x0000555555b84da0 in ___call ()
#4  0x0000555555a1b79d in scm_event (___arg1=4, ___arg2=139, ___arg3=178)
    at /home/matthew/.cache/lambdanative/linux/build/3322581205.c:10913
#5  0x0000555555ef7fee in lambdanative_payload_event (t=4, x=139, y=178)
    at /home/matthew/.cache/lambdanative/linux/build/scm_hook.c:66
#6  0x0000555555a272f6 in ffi_event (t=4, x=139, y=178)
    at /home/matthew/.cache/lambdanative/linux/build/1853435516.c:66
#7  0x0000555555a1b4f3 in microgl_hook (t=4, x=139, y=178) at main.c:101
#8  0x0000555555a1a785 in microgl_pollevents () at x11_microgl.c:229
#9  0x0000555555a1b61a in main (argc=1, argv=0x7fffffffe1b8) at main.c:172
mgorges commented 3 years ago

Thanks for bringing this to out attention. - I can reproduce the segfault on MacOS too, so it is a broader problem. The segfault itself is in if (rtaudio_closecb) rtaudio_closecb();, which is set in rtaudio_register but I haven't figured out yet, why. I believe it has to do with the definition in modules/rtaudio/rtaudio.scm#L93 being a four-argument function, but the call in apps/DemoRTAudio/main.scm#L82 only calling it with three arguments?

mgorges commented 3 years ago

Unless we want to add a three-argument initialization function, the rtaudio_closecb needs to be set. Updated example code and Wiki to do so.