membraneframework / membrane_core

The core of the Membrane Framework, advanced multimedia processing framework
https://membrane.stream
Apache License 2.0
1.22k stars 34 forks source link

Issue packaging module with port #823

Open johns10 opened 2 weeks ago

johns10 commented 2 weeks ago

Thank you for this excellent framework. I've been having a great time playing with it. I'm working on shipping an ASR pipeline in Elixir Desktop, and I've run in to an issue including the membrane_portaudio_plugin in my Elixir desktop application.

I've created a minimal repo that reproduces the issue on my local (I have not tried other machines).

This commit works (it's the bog standard elixir desktop sample app)

https://github.com/johns10/desktop-example-app-fails-with-membraneportaudio/commit/33be7e4901183508e006839030db25380c13c74f

This one fails

https://github.com/johns10/desktop-example-app-fails-with-membraneportaudio/commit/980e8a1d9bd1ae509fb1629260a69255644bdc7f

In order to reproduce the issue, go to the initial commit, then:

MIX_ENV=prod mix release

This will generate a .app file in /_build/prod. You can run the app, and the window opens and everything is fine.

If you go to the second commit, you can try to run the .app file and it will not put an icon in the dock. It will run the app, which sits in the background and restarts if you try to kill it in activity monitor.

If you run the app from the command line, you get the following error.

heart_beat_kill_pid = 5824
[1]    5824 killed     ./run
heart: Sat Jun 15 16:06:12 2024: Erlang has closed.                         
heart: Sat Jun 15 16:06:12 2024: Wait 5 seconds for Erlang to terminate nicely
➜  MacOS git:(master) ✗ heart: Sat Jun 15 16:06:14 2024: Executed "open -a TodoApp -W" -> 0. Terminating.

It is worth mentioning that Elixir Desktop does have facilities for including NIF's in the build, and several of the included libraries (most notably sqlite) have nifs.

My theory is that unifex and elixir desktop are not playing nicely together, and causing some collision between wx and unifex, which doesn't allow the wxwebview to open.

mat-hek commented 2 weeks ago

👋 can you try replacing PortAudio with one of these:

johns10 commented 2 weeks ago

I absolutely can.

johns10 commented 1 week ago

That was a fairly interesting exercise.

Mind checking my commit to make sure I implemented it correctly?

https://github.com/johns10/desktop-example-app-fails-with-membraneportaudio/commit/4c99550819e60ff94bcb41bf88f0346321c38e5b

I hope this got you what you were looking for.

Now it builds the app. When I try to run it, I get:

heart_beat_kill_pid = 82702
=CRASH REPORT==== 19-Jun-2024::21:24:51.543830 ===
  crasher:
    initial call: kernel:init/1
    pid: <0.2308.0>
    registered_name: []
    exception exit: {on_load_function_failed,
                        'Elixir.BundlexSimpleNif.Example.Nif',abort}
      in function  init:run_on_load_handlers/0 
      in call from kernel:init/1 (kernel.erl, line 227)
    ancestors: [kernel_sup,<0.2301.0>]
    message_queue_len: 0
    messages: []
    links: [<0.2303.0>]
    dictionary: []
    trap_exit: false
    status: running
    heap_size: 376
    stack_size: 28
    reductions: 141
  neighbours:

=SUPERVISOR REPORT==== 19-Jun-2024::21:24:51.543853 ===
    supervisor: {local,kernel_sup}
    errorContext: start_error
    reason: {on_load_function_failed,'Elixir.BundlexSimpleNif.Example.Nif',
                                     abort}
    offender: [{pid,undefined},
               {id,on_load},
               {mfargs,{proc_lib,start_link,[kernel,init,[on_load]]}},
               {restart_type,transient},
               {significant,false},
               {shutdown,2000},
               {child_type,worker}]

=CRASH REPORT==== 19-Jun-2024::21:24:51.544625 ===
  crasher:
    initial call: application_master:init/4
    pid: <0.2300.0>
    registered_name: []
    exception exit: {{shutdown,
                         {failed_to_start_child,on_load,
                             {on_load_function_failed,
                                 'Elixir.BundlexSimpleNif.Example.Nif',
                                 abort}}},
                     {kernel,start,[normal,[]]}}
      in function  application_master:init/4 (application_master.erl, line 142)
    ancestors: [<0.2299.0>]
    message_queue_len: 1
    messages: [{'EXIT',<0.2301.0>,normal}]
    links: [<0.2299.0>,<0.2298.0>]
    dictionary: []
    trap_exit: true
    status: running
    heap_size: 233
    stack_size: 28
    reductions: 166
  neighbours:

=INFO REPORT==== 19-Jun-2024::21:24:51.544835 ===
    application: kernel
    exited: {{shutdown,
                 {failed_to_start_child,on_load,
                     {on_load_function_failed,
                         'Elixir.BundlexSimpleNif.Example.Nif',abort}}},
             {kernel,start,[normal,[]]}}
    type: permanent

Kernel pid terminated (application_controller) ("{application_start_failure,kernel,{{shutdown,{failed_to_start_child,on_load,{on_load_function_failed,'Elixir.BundlexSimpleNif.Example.Nif',abort}}},{kernel,start,[normal,[]]}}}")
heart: Wed Jun 19 21:24:52 2024: Erlang is crashing .. (waiting for crash dump file)

Which is more descriptive than what I got when I tried to run it with PortAudio.

mat-hek commented 1 week ago

It's indeed more descriptive, but I'm still unsure what's wrong. I'll look into that next week.

mat-hek commented 1 week ago

Well, so I meant to just add the example to deps, just like you did with PortAudio ;) Anyway, the version with PortAudio in deps runs for me without problems... What system are you using exactly? Are you using Erlang and Elixir versions from .tools-versions?

johns10 commented 1 week ago

Wow, that's crazy. Yes, I'm using .tool-versions.