fix crash when closing before search, make discard a function for consistency

This commit is contained in:
goeiecool9999 2024-10-20 12:04:09 +02:00
parent 7ac0ed97f2
commit 8fa37f738c
2 changed files with 15 additions and 6 deletions

View File

@ -116,8 +116,7 @@ InputAPIAddWindow::InputAPIAddWindow(wxWindow* parent, const wxPoint& position,
InputAPIAddWindow::~InputAPIAddWindow()
{
std::lock_guard lock{m_search_thread_data->mutex};
m_search_thread_data->discardResult = true;
discard_thread_result();
}
void InputAPIAddWindow::on_add_button(wxCommandEvent& event)
@ -165,13 +164,11 @@ std::unique_ptr<ControllerProviderSettings> InputAPIAddWindow::get_settings() co
void InputAPIAddWindow::on_api_selected(wxCommandEvent& event)
{
discard_thread_result();
if (m_input_api->GetSelection() == wxNOT_FOUND)
return;
m_search_running = false;
if(m_search_thread_data)
m_search_thread_data->discardResult = true;
m_controller_list->Enable();
m_controller_list->SetSelection(wxNOT_FOUND);
@ -317,3 +314,13 @@ void InputAPIAddWindow::on_controllers_refreshed(wxCommandEvent& event)
}
}
}
void InputAPIAddWindow::discard_thread_result()
{
m_search_running = false;
if(m_search_thread_data)
{
std::lock_guard lock{m_search_thread_data->mutex};
m_search_thread_data->discardResult = true;
}
}

View File

@ -39,6 +39,8 @@ private:
void on_controller_selected(wxCommandEvent& event);
void on_controllers_refreshed(wxCommandEvent& event);
void discard_thread_result();
wxChoice* m_input_api;
wxComboBox* m_controller_list;
wxButton* m_ok_button;