Skip to content

Commit

Permalink
server-mfc: fix crash when selected endpoint is not in list #122
Browse files Browse the repository at this point in the history
  • Loading branch information
mkckr0 committed Jan 2, 2025
1 parent 75c7b6b commit 93b56d3
Showing 1 changed file with 16 additions and 2 deletions.
18 changes: 16 additions & 2 deletions server-mfc/audio-share-server/CServerTabPanel.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -103,8 +103,8 @@ void CServerTabPanel::OnBnClickedButtonReset()
}
m_comboBoxAudioEndpoint.ResetContent();

auto nIndex = m_comboBoxAudioEndpoint.AddString(L"Default");
m_comboBoxAudioEndpoint.SetItemDataPtr(nIndex, _wcsdup(L"default"));
auto nDefaultIndex = m_comboBoxAudioEndpoint.AddString(L"Default");
m_comboBoxAudioEndpoint.SetItemDataPtr(nDefaultIndex, _wcsdup(L"default"));

audio_manager::endpoint_list_t endpoint_list = m_audio_manager->get_endpoint_list();
for (auto&& [id, name] : endpoint_list) {
Expand All @@ -119,6 +119,11 @@ void CServerTabPanel::OnBnClickedButtonReset()
break;
}
}
if (m_comboBoxAudioEndpoint.GetCurSel() == CB_ERR) {
// selected endpoint is not in list, no selected
theApp.WriteProfileStringW(L"Capture", L"endpoint", L"default");
m_comboBoxAudioEndpoint.SetCurSel(nDefaultIndex);
}
}

// encoding list
Expand Down Expand Up @@ -146,6 +151,10 @@ void CServerTabPanel::OnBnClickedButtonReset()
break;
}
}
if (m_comboEncoding.GetCurSel() == CB_ERR) {
theApp.WriteProfileInt(L"Capture", L"endpoint", (int)encoding_t::encoding_default);
m_comboEncoding.SetCurSel(0);
}
}
}

Expand All @@ -165,6 +174,11 @@ void CServerTabPanel::OnBnClickedStartServer()
return;
}

if (m_comboBoxAudioEndpoint.GetCurSel() == CB_ERR) {
AfxMessageBox(L"No Selected Audio Endpoint", MB_OK | MB_ICONSTOP);
return;
}

// start
EnableInputControls(false);
m_buttonServer.EnableWindow(false);
Expand Down

0 comments on commit 93b56d3

Please sign in to comment.