attempt to fix event_queue bugs

This commit is contained in:
David Griswold 2026-07-04 13:41:18 -05:00 committed by PabloMK7
parent a6b3c3236f
commit 303ba4fb4e
4 changed files with 16 additions and 0 deletions

View File

@ -28,6 +28,7 @@ ControllerSequenceDialog::ControllerSequenceDialog(QWidget* parent)
connect(buttons, &QDialogButtonBox::accepted, this, &QDialog::accept);
connect(buttons, &QDialogButtonBox::rejected, this, &QDialog::reject);
connect(this, &QDialog::finished, this, [this](int) { StopPolling(); });
LaunchPollers();
}
@ -90,4 +91,11 @@ void ControllerSequenceDialog::LaunchPollers() {
}
});
poll_timer->start(100);
}
void ControllerSequenceDialog::StopPolling() {
poll_timer->stop();
for (auto& poller : device_pollers) {
poller->Stop();
}
}

View File

@ -22,6 +22,7 @@ public:
private:
void LaunchPollers();
void StopPolling();
QLabel* textBox;
QString key_sequence;
Common::ParamPackage params1, params2;

View File

@ -141,6 +141,10 @@ static int SDLEventWatcher(void* userdata, SDL_Event* event) {
}
// deal
if (sdl_state->polling) {
if (sdl_state->event_queue.Size() >= sdl_state->MAX_EVENT_QUEUE_SIZE) {
// safety - before pushing, clear if it has somehow ballooned in size
sdl_state->event_queue.Clear();
}
sdl_state->event_queue.Push(*event);
} else {
sdl_state->HandleGameControllerEvent(*event);
@ -938,6 +942,7 @@ public:
}
void Stop() override {
state.event_queue.Clear();
state.polling = false;
}

View File

@ -47,6 +47,7 @@ public:
/// Used by the Pollers during config
std::atomic<bool> polling = false;
Common::SPSCQueue<SDL_Event> event_queue;
static constexpr size_t MAX_EVENT_QUEUE_SIZE = 10000;
private:
void InitJoystick(int joystick_index);
@ -72,5 +73,6 @@ private:
std::atomic<bool> initialized = false;
std::thread poll_thread;
// maximum events allowed in the queue - if more than this are there, something is wrong
};
} // namespace InputCommon::SDL