Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash after rendering when using soundio #2638

Closed
grejppi opened this issue Mar 5, 2016 · 11 comments
Closed

Crash after rendering when using soundio #2638

grejppi opened this issue Mar 5, 2016 · 11 comments

Comments

@grejppi
Copy link
Contributor

grejppi commented Mar 5, 2016

cc @andrewrk

Steps to reproduce:

  1. Select the soundio audio device.
  2. Have something to export.
  3. Export. LMMS will crash.
Program received signal SIGSEGV, Segmentation fault.
[Switching to Thread 0x7fff71efc700 (LWP 7227)]
0x00007ffff5dbc959 in soundio_outstream_start (outstream=0x0)
    at ../src/soundio.c:536
536     struct SoundIo *soundio = outstream->device->soundio;
(gdb) bt
#0  0x00007ffff5dbc959 in soundio_outstream_start (outstream=0x0) at ../src/soundio.c:536
#1  0x000000000052284c in AudioSoundIo::startProcessing() ()
#2  0x00000000004fb003 in ProjectRenderer::run() ()
#3  0x00007ffff680cd1c in  () at /usr/lib/x86_64-linux-gnu/libQtCore.so.4
#4  0x00007ffff7bc26aa in start_thread (arg=0x7fff71efc700) at pthread_create.c:333
#5  0x00007ffff40f6e9d in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:109

So what's happening here? LMMS pauses the audio device to temporarily replace it with the renderer. AudioSoundIo::stopProcessing() however destroys m_outstream which would be needed again in AudioSoundIo::startProcessing() and after that.

@Fastigium
Copy link
Contributor

If @andrewrk doesn't respond or is short on time I might fix this as part of my efforts on #2457. If I'm working on these parts of the code anyway...

@Fastigium
Copy link
Contributor

Been reading AudioSoundIo.cpp and libsoundio documentation, and I see two possible approaches to fix this:

  1. As there is no soundio_outstream_stop() or soundio_outstream_close(), stick with soundio_outstream_destroy(). Take the whole outstream initialization code out of the constructor and make it a separate method, to be called again in startProcessing() when needed.
  2. Use soundio_outstream_pause() to stop/start processing. This function may or may not work with the selected audio backend and may or may not report an error when it doesn't work. Solve that eventuality by making the write callback write zeros as long as there is no processing.

My choice would be approach 2, as this avoids the problem I discovered while working on #2457, namely that stopping and restarting the audio thread may make PulseAudio choke.

However, I only just discovered @andrewrk that you wrote libsoundio (woops 😅), so maybe you know a nicer way to fix this? I hope you don't mind if I mess around with your audio interface code. Please feel free to chime in at any moment.

@andrewrk
Copy link
Member

Fastigium has it right. 👍

@firewall1110
Copy link
Contributor

Line in AudioSoundIo.cpp:
void AudioSoundIo::stopProcessing()
{
m_stopped = true;
if (m_outstream)
{
soundio_outstream_destroy(m_outstream);
// line 228 :: after this we can not simply soundio_outstream_start(m_outstream)) - Segmantation Fault!
m_outstream = NULL; // Segmantation Fault in every conditions
}

if (m_outBuf)
{
	delete[] m_outBuf;
	m_outBuf = NULL;
}

}

@firewall1110
Copy link
Contributor

Using recommendation "Use soundio_outstream_pause() to stop/start processing. This function may or may not work with the selected audio backend and may or may not report an error when it doesn't work. " it seems that I solved problem, but I have not tested this in not modified Mixer code.

In modified code no Segmentation Fault in any combination, and no soundio_outstream_pause() errors.

@firewall1110
Copy link
Contributor

It work in unmodified code too ...
Before I made test with master and make some diff file
result here.

Using lmms_1.2.2.tar.xz (stable release, downloadable in LMMS GitHub):

File AudioSoundIo.h : Replace in: include/
File AudioSoundIo.cpp: Replace in: src/core/audio/

/* - - - - - - - - - */

Changes in AudioSoundIo.h:

[after line 112:]
bool m_started;

Changes in AudioSoundIo.cpp:

Partial rewrite of:

AudioSoundIo::~AudioSoundIo()
void AudioSoundIo::startProcessing()
void AudioSoundIo::stopProcessing()

Only this changes in file impl_changes.txt.

All files are in files.zip .
files.zip

@firewall1110
Copy link
Contributor

And some .patch.gz file against stable 1.2.2 branch :

lmms_soundio_Naur_patch.patch.gz

@PhysSong
Copy link
Member

@firewall1110 Could you consider opening a pull request? That will make reviewing and testing much easier.
Note that stable-1.2 is not likely to be updated, so I recommend you can make PR against master.

@firewall1110
Copy link
Contributor

The same patch could be applied against master.

I tested exportation twice using soundio with Dummy , JACK , ALSA, PulseAudio (all using default outputs, exporting to mp3 320 bit-rate).

PR is the next planned step (following LMMS GitHub default recommendations) ...

@firewall1110
Copy link
Contributor

It seems, that LMMS Bot compiled lmms-1.2.3-707+g4f5cc75-linux-x86_64.AppImage without soundio ...

@DomClark
Copy link
Member

Fixed in #5681.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

7 participants