Only assign context and mainloop once we have connected successfully
If we fail to connect to the the pa server, we have an assigned context and mainloop that isn't connected. So, when PULSEAUDIO_pa_context_disconnect is called, pa asserts and crashes the application. Assertion 'pa_atomic_load(&(c)->_ref) >= 1' failed at pulse/context.c:1055, function pa_context_disconnect(). Aborting.main
parent
88cb4962cd
commit
a69c61fbfd
|
@ -295,32 +295,39 @@ ConnectToPulseServer_Internal(pa_mainloop **_mainloop, pa_context **_context)
|
||||||
return SDL_SetError("pa_mainloop_new() failed");
|
return SDL_SetError("pa_mainloop_new() failed");
|
||||||
}
|
}
|
||||||
|
|
||||||
*_mainloop = mainloop;
|
|
||||||
|
|
||||||
mainloop_api = PULSEAUDIO_pa_mainloop_get_api(mainloop);
|
mainloop_api = PULSEAUDIO_pa_mainloop_get_api(mainloop);
|
||||||
SDL_assert(mainloop_api); /* this never fails, right? */
|
SDL_assert(mainloop_api); /* this never fails, right? */
|
||||||
|
|
||||||
context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
|
context = PULSEAUDIO_pa_context_new(mainloop_api, getAppName());
|
||||||
if (!context) {
|
if (!context) {
|
||||||
|
PULSEAUDIO_pa_mainloop_free(mainloop);
|
||||||
return SDL_SetError("pa_context_new() failed");
|
return SDL_SetError("pa_context_new() failed");
|
||||||
}
|
}
|
||||||
*_context = context;
|
|
||||||
|
|
||||||
/* Connect to the PulseAudio server */
|
/* Connect to the PulseAudio server */
|
||||||
if (PULSEAUDIO_pa_context_connect(context, NULL, 0, NULL) < 0) {
|
if (PULSEAUDIO_pa_context_connect(context, NULL, 0, NULL) < 0) {
|
||||||
|
PULSEAUDIO_pa_context_unref(context);
|
||||||
|
PULSEAUDIO_pa_mainloop_free(mainloop);
|
||||||
return SDL_SetError("Could not setup connection to PulseAudio");
|
return SDL_SetError("Could not setup connection to PulseAudio");
|
||||||
}
|
}
|
||||||
|
|
||||||
do {
|
do {
|
||||||
if (PULSEAUDIO_pa_mainloop_iterate(mainloop, 1, NULL) < 0) {
|
if (PULSEAUDIO_pa_mainloop_iterate(mainloop, 1, NULL) < 0) {
|
||||||
|
PULSEAUDIO_pa_context_unref(context);
|
||||||
|
PULSEAUDIO_pa_mainloop_free(mainloop);
|
||||||
return SDL_SetError("pa_mainloop_iterate() failed");
|
return SDL_SetError("pa_mainloop_iterate() failed");
|
||||||
}
|
}
|
||||||
state = PULSEAUDIO_pa_context_get_state(context);
|
state = PULSEAUDIO_pa_context_get_state(context);
|
||||||
if (!PA_CONTEXT_IS_GOOD(state)) {
|
if (!PA_CONTEXT_IS_GOOD(state)) {
|
||||||
|
PULSEAUDIO_pa_context_unref(context);
|
||||||
|
PULSEAUDIO_pa_mainloop_free(mainloop);
|
||||||
return SDL_SetError("Could not connect to PulseAudio");
|
return SDL_SetError("Could not connect to PulseAudio");
|
||||||
}
|
}
|
||||||
} while (state != PA_CONTEXT_READY);
|
} while (state != PA_CONTEXT_READY);
|
||||||
|
|
||||||
|
*_context = context;
|
||||||
|
*_mainloop = mainloop;
|
||||||
|
|
||||||
return 0; /* connected and ready! */
|
return 0; /* connected and ready! */
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue