jwdj / EasyABC

EasyABC
GNU General Public License v2.0
90 stars 36 forks source link

Segmentation fault #28

Open PigeonOnTheGate opened 3 years ago

PigeonOnTheGate commented 3 years ago

Thank you for fixing the my last issue. However, after I finally got around to updating easyabc to the latest version, the program no longer starts. It instead gives an error:

fluidsynth: warning: SDL2 not initialized, SDL2 audio driver won't be usable /usr/bin/easyabc: line 2: 9134 Segmentation fault (core dumped) python3 /usr/share/easyabc/easy_abc.py

Thank you very much for your help

jwdj commented 3 years ago

I am no Linux expert but are you using the latest version of libfluidsynth (2.1.5 I believe)? Have you installed jackd as described in using_EasyABC_in_Linux.txt: sudo apt install libfluidsynth2 fluid-soundfont-gm jackd

Hope this helps. Otherwise you will have to google for answers.

On 18-10-2020 4:28, PigeonOnTheGate wrote:

Thank you for fixing the my last issue. However, after I finally got around to updating easyabc to the latest version, the program no longer starts. It instead gives an error:

|fluidsynth: warning: SDL2 not initialized, SDL2 audio driver won't be usable /usr/bin/easyabc: line 2: 9134 Segmentation fault (core dumped) python3 /usr/share/easyabc/easy_abc.py|

Thank you very much for your help

— You are receiving this because you are subscribed to this thread. Reply to this email directly, view it on GitHub https://github.com/jwdj/EasyABC/issues/28, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC22EZFFN5PMMCYLUUX3U7TSLJHDNANCNFSM4SUYNMUA.

PigeonOnTheGate commented 3 years ago

Thanks so much for the advice! I do have all of the above installed. Since this is a warning rather than an error, is there a way to make the program run in spite of it? I've noticed easyABC does start if I remove fluidsynth entirely, so if I'm unable to solve this, I'll just remove fluidsynth and use an external midi player.

After googling, I found someone who had a similar problem due to a missing line of code. Do you think the solution from there might work?

jwdj commented 3 years ago

Yes I found that page too, but that was about another matter: the warning about SDL2 not found used to be reported as an error. That issue was resolved as nowadays a warning is given when SDL2 is not available. But SDL2 is not the only way for FluidSynth to produce sound, so it should not be a concern. When I tested with VirtualBox I got the same warning, but not the Segmentation fault. What version of FluidSynth are you using? Have you installed a package? Or did you build from source?

On 22-10-2020 20:57, PigeonOnTheGate wrote:

Thanks so much for the advice! I do have all of the above installed. Since this is a warning rather than an error, is there a way to make the program run in spite of it? I've noticed easyABC does start if I remove fluidsynth entirely, so if I'm unable to solve this, I'll just remove fluidsynth and use an external midi player.

After googling, I found someone who had a similar problem https://github.com/FluidSynth/fluidsynth/issues/622 due to a missing line of code. Do you think the solution from there might work?

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jwdj/EasyABC/issues/28#issuecomment-714695383, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC22EZCPBZFKSTCJZBWUJ33SMB6CXANCNFSM4SUYNMUA.

PigeonOnTheGate commented 3 years ago

I'm using FluidSynth 2.1.5, which I installed from a package. I have also tried setting FluidSynth's driver to JACK and ALSA, but strangely enough, the same warning and segmentation fault occur. I checked dependencies, and a number of packages depend on SDL2, including fluidsynth, python3-wxpython, and easyabc itself. Here are my fluidsynth settings, maybe I need to change something here for things to work?

audio.alsa.device default audio.driver jack audio.file.endian auto audio.file.format s16 audio.file.name fluidsynth.wav audio.file.type auto audio.jack.autoconnect False audio.jack.id fluidsynth audio.jack.multi False audio.jack.server
audio.oss.device /dev/dsp audio.period-size 64 audio.periods 16 audio.pulseaudio.adjust-latency True audio.pulseaudio.device default audio.pulseaudio.media-role music audio.pulseaudio.server default audio.realtime-prio 60 audio.sample-format 16bits audio.sdl2.device default midi.alsa.device default midi.alsa_seq.device default midi.alsa_seq.id pid midi.autoconnect False midi.driver alsa_seq midi.jack.id fluidsynth-midi midi.jack.server
midi.oss.device /dev/midi midi.portname
midi.realtime-prio 50 player.reset-synth True player.timing-source sample shell.port 9800 shell.prompt > synth.audio-channels 1 synth.audio-groups 1 synth.chorus.active True synth.chorus.depth 8.000 synth.chorus.level 2.000 synth.chorus.nr 3 synth.chorus.speed 0.300 synth.cpu-cores 1 synth.default-soundfont /usr/share/soundfonts/default.sf2 synth.device-id 0 synth.dynamic-sample-loading False synth.effects-channels 2 synth.effects-groups 1 synth.gain 0.200 synth.ladspa.active False synth.lock-memory True synth.midi-bank-select gs synth.midi-channels 16 synth.min-note-length 10 synth.overflow.age 1000.000 synth.overflow.important 5000.000 synth.overflow.important-channels
synth.overflow.percussion 4000.000 synth.overflow.released -2000.000 synth.overflow.sustained -1000.000 synth.overflow.volume 500.000 synth.polyphony 256 synth.reverb.active True synth.reverb.damp 0.000 synth.reverb.level 0.900 synth.reverb.room-size 0.200 synth.reverb.width 0.500 synth.sample-rate 44100.000 synth.threadsafe-api True synth.verbose False

PigeonOnTheGate commented 3 years ago

I have just noticed that if I run fluidsynth in the terminal, a number of errors are shown, if I run it from the root, however, these errors do not occur. Could these be the cause of the segmentation fault?

When I run fluidsynth from the terminal, it shows:

FluidSynth runtime version 2.1.5 Copyright (C) 2000-2020 Peter Hanappe and others. Distributed under the LGPL license. SoundFont(R) is a registered trademark of E-mu Systems, Inc.

Cannot connect to server socket err = No such file or directory Cannot connect to server request channel fluidsynth: warning: Failed to set thread to high priority jackdmp 1.9.14 Copyright 2001-2005 Paul Davis and others. Copyright 2004-2016 Grame. Copyright 2016-2019 Filipe Coelho. jackdmp comes with ABSOLUTELY NO WARRANTY This is free software, and you are welcome to redistribute it under certain conditions; see the file COPYING for details Cannot create RT messagebuffer thread: Operation not permitted (1) Retrying messagebuffer thread without RT scheduling Messagebuffer not realtime; consider enabling RT scheduling for user no message buffer overruns Cannot create RT messagebuffer thread: Operation not permitted (1) Retrying messagebuffer thread without RT scheduling Messagebuffer not realtime; consider enabling RT scheduling for user no message buffer overruns Cannot create RT messagebuffer thread: Operation not permitted (1) Retrying messagebuffer thread without RT scheduling Messagebuffer not realtime; consider enabling RT scheduling for user no message buffer overruns JACK server starting in realtime mode with priority 10 self-connect-mode is "Don't restrict self connect requests" Cannot lock down 86611866 byte memory area (Cannot allocate memory) audio_reservation_init Acquire audio card Audio0 creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit configuring for 48000Hz, period = 1024 frames (21.3 ms), buffer = 2 periods ALSA: final selected sample format for capture: 32bit integer little-endian ALSA: use 2 periods for capture ALSA: final selected sample format for playback: 32bit integer little-endian ALSA: use 2 periods for playback Cannot use real-time scheduling (RR/10) (1: Operation not permitted) AcquireSelfRealTime error Cannot lock down 86611866 byte memory area (Cannot allocate memory) fluidsynth: Jack sample rate mismatch, adjusting. (synth.sample-rate=44100, jackd=48000) Cannot use real-time scheduling (RR/5) (1: Operation not permitted) JackClient::AcquireSelfRealTime error

When I run it from the terminal as root, it shows:

Warning: Unable to initialize SDL2 Audio: Could not setup connection to PulseAudiofluidsynth: warning: SDL2 not initialized, SDL2 audio driver won't be usable FluidSynth runtime version 2.1.5 Copyright (C) 2000-2020 Peter Hanappe and others. Distributed under the LGPL license. SoundFont(R) is a registered trademark of E-mu Systems, Inc.

Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jackdmp 1.9.14 Copyright 2001-2005 Paul Davis and others. Copyright 2004-2016 Grame. Copyright 2016-2019 Filipe Coelho. jackdmp comes with ABSOLUTELY NO WARRANTY This is free software, and you are welcome to redistribute it under certain conditions; see the file COPYING for details no message buffer overruns no message buffer overruns no message buffer overruns JACK server starting in realtime mode with priority 10 self-connect-mode is "Don't restrict self connect requests" audio_reservation_init Acquire audio card Audio0 creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit configuring for 48000Hz, period = 1024 frames (21.3 ms), buffer = 2 periods ALSA: final selected sample format for capture: 32bit integer little-endian ALSA: use 2 periods for capture ALSA: final selected sample format for playback: 32bit integer little-endian ALSA: use 2 periods for playback fluidsynth: Jack sample rate mismatch, adjusting. (synth.sample-rate=44100, jackd=48000)

PigeonOnTheGate commented 3 years ago

The errors that fluidsynth was giving me were related to JACK, and I was able to fix them with this method , unfortunately, this did nothing to fix the segmentation fault with easyABC, so this is another dead end. In any case, running fluidsynth now gives this output

FluidSynth runtime version 2.1.5 Copyright (C) 2000-2020 Peter Hanappe and others. Distributed under the LGPL license. SoundFont(R) is a registered trademark of E-mu Systems, Inc.

Cannot connect to server socket err = No such file or directory Cannot connect to server request channel jackdmp 1.9.14 Copyright 2001-2005 Paul Davis and others. Copyright 2004-2016 Grame. Copyright 2016-2019 Filipe Coelho. jackdmp comes with ABSOLUTELY NO WARRANTY This is free software, and you are welcome to redistribute it under certain conditions; see the file COPYING for details no message buffer overruns no message buffer overruns no message buffer overruns JACK server starting in realtime mode with priority 10 self-connect-mode is "Don't restrict self connect requests" audio_reservation_init Acquire audio card Audio0 creating alsa driver ... hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit configuring for 48000Hz, period = 1024 frames (21.3 ms), buffer = 2 periods ALSA: final selected sample format for capture: 32bit integer little-endian ALSA: use 2 periods for capture ALSA: final selected sample format for playback: 32bit integer little-endian ALSA: use 2 periods for playback fluidsynth: Jack sample rate mismatch, adjusting. (synth.sample-rate=44100, jackd=48000) Type 'help' for help topics.

jwdj commented 3 years ago

If you edit easy_abc.py you can find some commented code. If you remove the 6 # (see code below) it might give you some clues.

try:     import faulthandler  # pip install faulthandler     faulthandler.enable() except ImportError:     print('faulthandler not installed. Try: pip install faulthandler')     pass

But first you need to install a python-package named faulthandler. For python 2: pip install faulthandler For Python 3 pip3 install faulthandler

Then start EasyABC with: python3 easy_abc.py

On 28-10-2020 02:51, PigeonOnTheGate wrote:

The errors that fluidsynth was giving me were related to JACK, and I was able to fix them with this method , unfortunately, this did nothing to fix the segmentation fault with easyABC, so this is another dead end. In any case, running fluidsynth now gives this output

FluidSynth runtime version 2.1.5
Copyright (C) 2000-2020 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of E-mu Systems, Inc.

Cannot connect to server socket err = No such file or directory
Cannot connect to server request channel
jackdmp 1.9.14
Copyright 2001-2005 Paul Davis and others.
Copyright 2004-2016 Grame.
Copyright 2016-2019 Filipe Coelho.
jackdmp comes with ABSOLUTELY NO WARRANTY
This is free software, and you are welcome to redistribute it
under certain conditions; see the file COPYING for details
no message buffer overruns
no message buffer overruns
no message buffer overruns
JACK server starting in realtime mode with priority 10
self-connect-mode is "Don't restrict self connect requests"
audio_reservation_init
Acquire audio card Audio0
creating alsa driver ...
hw:0|hw:0|1024|2|48000|0|0|nomon|swmeter|-|32bit
configuring for 48000Hz, period = 1024 frames (21.3 ms), buffer =
2 periods
ALSA: final selected sample format for capture: 32bit integer
little-endian
ALSA: use 2 periods for capture
ALSA: final selected sample format for playback: 32bit integer
little-endian
ALSA: use 2 periods for playback
fluidsynth: Jack sample rate mismatch, adjusting.
(synth.sample-rate=44100, jackd=48000)
Type 'help' for help topics.

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jwdj/EasyABC/issues/28#issuecomment-717644038, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC22EZDWBT5GZKDW3MVMO5LSM52KNANCNFSM4SUYNMUA.

PigeonOnTheGate commented 3 years ago

Thank you. Running this gave some interesting output:

fluidsynth: warning: SDL2 not initialized, SDL2 audio driver won't be usable
Fatal Python error: Segmentation fault

Current thread 0x00007fadab4d2740 (most recent call first):
  File "/usr/share/easyabc/fluidsynth.py", line 65 in setting_setnum
  File "/usr/share/easyabc/fluidsynth.py", line 51 in __init__
  File "/usr/share/easyabc/fluidsynthplayer.py", line 15 in __init__
  File "/usr/share/easyabc/easy_abc.py", line 3698 in __init__
  File "/usr/share/easyabc/easy_abc.py", line 8336 in NewMainFrame
  File "/usr/share/easyabc/easy_abc.py", line 8377 in OnInit
  File "/usr/lib64/python3.8/site-packages/wx/core.py", line 2194 in __init__
  File "/usr/share/easyabc/easy_abc.py", line 8314 in __init__
  File "/usr/share/easyabc/easy_abc.py", line 8385 in <module>
/usr/bin/easyabc: line 2: 28220 Segmentation fault      (core dumped) python3 /usr/share/easyabc/easy_abc.py
jwdj commented 3 years ago

You could experiment with putting the line in comment (put an # at the beginning) and see how that goes. Setting the gain is not essential so you could give it a try. | /usr/share/easyabc/fluidsynth.py| classSynth: # interface for the FluidSynth synthesizer definit(self, gain=0.2, samplerate=44100.0, bsize=64): self.settings = F.new_fluid_settings()         # self.setting_setnum('synth.gain', gain)

On 30-10-2020 02:50, PigeonOnTheGate wrote:

Thank you. Running this gave some interesting output:

|fluidsynth: warning: SDL2 not initialized, SDL2 audio driver won't be usable Fatal Python error: Segmentation fault Current thread 0x00007fadab4d2740 (most recent call first): File "/usr/share/easyabc/fluidsynth.py", line 65 in setting_setnum File "/usr/share/easyabc/fluidsynth.py", line 51 in init File "/usr/share/easyabc/fluidsynthplayer.py", line 15 in init File "/usr/share/easyabc/easy_abc.py", line 3698 in init File "/usr/share/easyabc/easy_abc.py", line 8336 in NewMainFrame File "/usr/share/easyabc/easy_abc.py", line 8377 in OnInit File "/usr/lib64/python3.8/site-packages/wx/core.py", line 2194 in init File "/usr/share/easyabc/easy_abc.py", line 8314 in init File "/usr/share/easyabc/easy_abc.py", line 8385 in /usr/bin/easyabc: line 2: 28220 Segmentation fault (core dumped) python3 /usr/share/easyabc/easy_abc.py |

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/jwdj/EasyABC/issues/28#issuecomment-719120946, or unsubscribe https://github.com/notifications/unsubscribe-auth/AC22EZDUO2OP6FV3L7DPMKLSNILVDANCNFSM4SUYNMUA.

PigeonOnTheGate commented 3 years ago

Hi, I fiddled around with the code a bit, and tried commenting out the non-essential lines that would cause errors. Eventually I ended up with this:

class Synth: # interface for the FluidSynth synthesizer def init(self, gain=0.2, samplerate=44100.0, bsize=64): self.settings = F.new_fluid_settings()

self.setting_setnum('synth.gain', gain)

    # self.setting_setnum('synth.sample-rate', samplerate)
    # self.setting_setint('audio.period-size', bsize)
    # self.setting_setint('audio.periods', 2)
    self.synth = F.new_fluid_synth(self.settings)
    self.audio_driver = None

at this point, only essential lines were left, but these were still causing errors:

fluidsynth: warning: SDL2 not initialized, SDL2 audio driver won't be usable Fatal Python error: Segmentation fault

Current thread 0x00007f6616c44740 (most recent call first): File "/usr/share/easyabc/fluidsynth.py", line 55 in init File "/usr/share/easyabc/fluidsynthplayer.py", line 15 in init File "/usr/share/easyabc/easy_abc.py", line 3698 in init File "/usr/share/easyabc/easy_abc.py", line 8336 in NewMainFrame File "/usr/share/easyabc/easy_abc.py", line 8377 in OnInit File "/usr/lib64/python3.8/site-packages/wx/core.py", line 2194 in init File "/usr/share/easyabc/easy_abc.py", line 8314 in init File "/usr/share/easyabc/easy_abc.py", line 8385 in /usr/bin/easyabc: line 2: 12047 Segmentation fault (core dumped) python3 /usr/share/easyabc/easy_abc.py

What seems so strange to me here is that the code is able to import the library (there is no import error), but attempting to inintialize fluidsynth causes the program to crash. I haven't been able to find anyone else having similar issues with fluidsynth, and I can't really tell if this is an issue with fluidsynth, the easyabc code, or if something is wrong in my settings.

PigeonOnTheGate commented 3 years ago

I think I may have found something in the fluidsynth api http://www.fluidsynth.org/api/audio_8h.html

When creating a settings instance with new_fluid_settings(), all audio drivers are initialized once. In the past this has caused segfaults and application crashes due to buggy soundcard drivers.

This could explain why the program would cause a segfault on my computer and not on yours, as we might have different audio drivers installed.

PigeonOnTheGate commented 3 years ago

from what I can gather here and here, it seems that when fluidsynth is initialized with new_fluid_settings(), it initializes all audio drivers. One of these audio drivers may segfault, causing fluidsynth to crash. It seems that the solution to this is to identify which driver is the culprit and exclude it by using the fluid_audio_driver_register() command.

jwdj commented 2 years ago

On Linux EasyABC now uses pulseaudio as audio driver for FluidSynth. Does that solve this issue perhaps?

PigeonOnTheGate commented 2 years ago

Thanks so much - trying it out right now. Should I leave the "midi player" field blank or put fluidsynth?

jwdj commented 2 years ago

To be able to use FluidSynth as audio player you should indeed leave the midi player field blank and select a sound font. Some good SoundFonts are freely available.

PigeonOnTheGate commented 2 years ago

When I leave the midi player field blank and select a soundfont, I still get a gstreamer error and no playback. If I press play, I get two pop-ups: one says "media playback error: Internal data stream error." and the other says "Unable to load /home/username/.EasyABC/cache/temp.midi: unsupported format?" I tried the workaround with jackd from here, but it gives the same exact result. Oddly enough, if I select fluidsynth as an external player, it works. Is there a way to get more info on those errors and why the program isn't working?

Thanks so much

jwdj commented 2 years ago

Since your FluidSynth is working as an external player you probably have done: sudo apt install libfluidsynth2 fluid-soundfont-gm The SoundFont is not used straight away. It requires a restart. If the fluidsynth library is found and the soundfont exists at startup then it should work. (it shows a warning if FluidSynth can't be loaded/found)

PigeonOnTheGate commented 2 years ago

Could be a library issue. My fluidsynth library is now called libfluidsynth3 after an update a few months ago. I'll try to see if I can downgrade it to libfluidsynth2.

robertmuth commented 2 years ago

I am see a similar issue after upgrading from ubuntu 21.10 to 22.04 both using pipewire.

The segfault looks like

python3 ./easy_abc.py

Fatal Python error: Segmentation fault

Current thread 0x00007f962ae9f000 (most recent call first):
  File "/home/rm/EasyABC/fluidsynth.py", line 85 in setting_setnum
  File "/home/rm/EasyABC/fluidsynth.py", line 62 in __init__
  File "/home/rm/EasyABC/fluidsynthplayer.py", line 17 in __init__
  File "/home/rm/EasyABC/./easy_abc.py", line 3974 in __init__
  File "/home/rm/EasyABC/./easy_abc.py", line 8710 in NewMainFrame
  File "/home/rm/EasyABC/./easy_abc.py", line 8771 in OnInit
  File "/usr/lib/python3/dist-packages/wx/core.py", line 2137 in __init__
  File "/home/rm/EasyABC/./easy_abc.py", line 8688 in __init__
  File "/home/rm/EasyABC/./easy_abc.py", line 8787 in <module>

Extension modules: wx._core, wx._html, wx._stc (total: 3)
Segmentation fault (core dumped)

When I try to run fluidsynth standalone I get:

fluidsynth

FluidSynth runtime version 2.2.5
Copyright (C) 2000-2022 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of Creative Technology Ltd.

ALSA lib pcm_dmix.c:1032:(snd_pcm_dmix_open) unable to open slave
fluidsynth: error: Failed to open the "default" audio device
Failed to create the audio driver. Giving up.
fluidsynth: warning: Failed to set thread to high priority

This gets slightly better via:

fluidsynth -a pulseaudio OR fluidsynth -a jack

FluidSynth runtime version 2.2.5
Copyright (C) 2000-2022 Peter Hanappe and others.
Distributed under the LGPL license.
SoundFont(R) is a registered trademark of Creative Technology Ltd.

fluidsynth: warning: Failed to set thread to high priority
fluidsynth: Using PulseAudio driver
Type 'help' for help topics.
robertmuth commented 2 years ago

Looking into this some more it seems that under ubuntu 22.04 python3.10 and libfluidsynth3:amd64 any access to the settings object created by: self.settings = F.new_fluid_settings()

fails

robertmuth commented 2 years ago

inserting the stamza below got rid of the seg-fault

        # start of new code
        L = ["jack", "pulseaudio", None]
        arr = (c_char_p * len(L))()
        arr[:] = L
        F.fluid_audio_driver_register(arr)
        # end of new code
        self.settings = F.new_fluid_settings()

However, there is a new problem with Gstreamer that results in annoying alert-boxes:

12:22:05 PM: Media playback error: Resource not found.
12:22:05 PM: Media playback error: GStreamer error: state change failed and some element failed to post a proper error message with the reason for the failure.
robertmuth commented 2 years ago

My last problem could be solved by commenting out the lines like:

mc.Load('NONEXISTANT_FILE____.mid')

based on:

https://sourceforge.net/p/easyabc/discussion/general/thread/524f3f9c/?limit=25

Redmattski commented 1 year ago

inserting the stamza below got rid of the seg-fault

        # start of new code
        L = ["jack", "pulseaudio", None]
        arr = (c_char_p * len(L))()
        arr[:] = L
        F.fluid_audio_driver_register(arr)
        # end of new code
        self.settings = F.new_fluid_settings()

I can confirm this solution is working on Arch Linux and resolves the Seg Fault.