Skip to content

Preset search window: fix shuffle, Ctrl+M, empty playlist crash and stale key input - #8

Closed
gwebb417 wants to merge 4 commits into
kblaschke:add-preset-search-windowfrom
gwebb417:fix/preset-search-window
Closed

gwebb417 wants to merge 4 commits into
kblaschke:add-preset-search-windowfrom
gwebb417:fix/preset-search-window

Conversation

@gwebb417

@gwebb417 gwebb417 commented Nov 7, 2026

Copy link
Copy Markdown

Hi! I've been using the preset search window from projectM-visualizer#139 in my own build and ran into a few issues, including the key buffer problem mentioned in the PR description. These are small fixes on top of your branch, one commit each, in case they're useful. Feel free to cherry-pick, change or ignore any of them.

Fixes

  1. Shuffle turns off after pressing N, P or R: PresetPlaylist::ShuffleEnabled(bool) never updated _shuffle, but Next(), Previous() and Random() restore the projectM playlist's shuffle flag from it. The setter now keeps _shuffle in sync (and is no longer const).
  2. Ctrl+M also opened the preset search: the chooser now only opens on M without a modifier.
  3. Crash on M with an empty playlist: PresetPlaylist::CurrentIndex() throws PlaylistEmptyException, so a "No presets loaded" toast is shown instead.
  4. Stale key presses when opening the search window: while no UI is visible, ProjectMGUI::Draw() returns before ImGui::NewFrame(), but SDL events are still passed to ImGui. They pile up in ImGui's input queue and are replayed (trickled over several frames) once the UI becomes active. Old letters end up in the search field, and an earlier ESC or Enter closes the chooser right after it opens. The fix clears the event queue and key/mouse state (ClearEventsQueue(), ClearInputKeys(), ClearInputMouse()) when the UI becomes active after being idle.

Tested on Windows 11 (MSVC, Release build).

🤖 Generated with Claude Code

ShuffleEnabled(bool) only set the flag on the projectM playlist, but
Next(), Previous() and Random() restore the flag from _shuffle after
temporarily changing it. _shuffle was never set, so shuffle got turned
off after the first N, P or R key press.
Ctrl/Cmd+M (move to next display) also opened the preset chooser.
PresetPlaylist::CurrentIndex() throws PlaylistEmptyException if the
playlist is empty, so pressing M without any presets loaded crashed the
application. Show a toast instead.
While no UI is shown, ProjectMGUI::Draw() returns before ImGui::NewFrame(),
but SDL events are still forwarded to ImGui via ProcessInput(). They pile
up in ImGui's input queue and are replayed (trickled over several frames)
once the UI becomes active again, e.g. when opening the preset chooser:

- Letters typed earlier (r for random preset etc.) end up in the search field.
- An earlier ESC or Enter press closes the chooser right after opening it,
  so M seems to do nothing.

Clear the event queue and the key/mouse state when the UI becomes active
after an idle period.
@gwebb417 gwebb417 changed the title Preset search window: fix shuffle, Ctrl+M, empty playlist crash and stale key input Preset search window: fix shuffle, Ctrl+M, empty playlist crash and stale key input Nov 7, 2026
@gwebb417 gwebb417 closed this Nov 7, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant