diff --git a/src/modules/audio/openal/Pool.cpp b/src/modules/audio/openal/Pool.cpp index 1c1df9cc0..667cf67b4 100644 --- a/src/modules/audio/openal/Pool.cpp +++ b/src/modules/audio/openal/Pool.cpp @@ -30,6 +30,16 @@ namespace audio namespace openal { +static Variant::SharedTable *putSourcesAsSharedTable(std::vector &sources) +{ + Variant::SharedTable *table = new Variant::SharedTable(); + + for (int i = 0; i < sources.size(); i++) + table->pairs.emplace_back((double) (i + 1), Variant(&Source::type, sources[i])); + + return table; +} + Pool::Pool(ALCdevice *device) : device(device) , sources() @@ -125,8 +135,17 @@ void Pool::update() disconnectNotified = false; else if (!disconnectNotified) { - StrongRef msg(new event::Message("audiodisconnected"), Acquire::NORETAIN); + // Get all sources in this Pool then stop it + // since they're all internally stopped. + std::vector sources = getPlayingSources(); + Source::stop(sources); + + std::vector vargs; + vargs.emplace_back(putSourcesAsSharedTable(sources)); + + StrongRef msg(new event::Message("audiodisconnected", vargs), Acquire::NORETAIN); eventModule->push(msg); + disconnectNotified = true; } } diff --git a/src/modules/love/callbacks.lua b/src/modules/love/callbacks.lua index a13cc33e8..872f21344 100644 --- a/src/modules/love/callbacks.lua +++ b/src/modules/love/callbacks.lua @@ -129,8 +129,8 @@ function love.createhandlers() localechanged = function () if love.localechanged then return love.localechanged() end end, - audiodisconnected = function () - if not love.audiodisconnected or not love.audiodisconnected() then + audiodisconnected = function (sources) + if not love.audiodisconnected or not love.audiodisconnected(sources) then love.audio.setOutputDevice() end end,