Skip to content

Commit

Permalink
jngl::updateInput() calls Audio::step() so that play/stop don't deadl…
Browse files Browse the repository at this point in the history
…ock when using audio::engine::Impl::DummyImpl
  • Loading branch information
jhasse committed Dec 16, 2024
1 parent 3e3d8cc commit 3829ecd
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 5 deletions.
3 changes: 1 addition & 2 deletions src/audio/sdl/engine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@
// https://lisyarus.github.io/blog/programming/2022/10/15/audio-mixing.html
#include "../engine.hpp"

#include "../../jngl/debug.hpp"
#include "../../jngl/other.hpp"
#include "../../log.hpp"
#include "../Stream.hpp"
Expand All @@ -22,7 +21,7 @@ struct engine::Impl {
try {
backend = std::make_unique<SdlImpl>(output);
} catch (std::exception& e) {
debugLn(e.what());
internal::warn(e.what());
backend = std::make_unique<DummyImpl>(std::move(output));
}
}
Expand Down
10 changes: 7 additions & 3 deletions src/window.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -251,6 +251,13 @@ void Window::updateKeyStates() {
}
updateInputCallbacks.clear();
}

// this is done here, because Window::updateKeyStates() is called by jngl::updateInput() and if
// someone writes their own main loop, Audio::step() needs to be called. Maybe updateKeyStates()
// should be renamed to updateInput() and UpdateInput() moved to WindowImpl ...
if (auto audio = Audio::handleIfAlive()) {
audio->step();
}
}

double Window::getMouseWheel() const {
Expand Down Expand Up @@ -364,9 +371,6 @@ void Window::stepIfNeeded() {
#ifdef JNGL_PERFORMANCE_OVERLAY
auto start = std::chrono::steady_clock::now();
#endif
if (auto audio = Audio::handleIfAlive()) {
audio->step();
}
for (auto& job : jobs) {
job->step();
}
Expand Down

0 comments on commit 3829ecd

Please sign in to comment.