GSdx: Improve robustness of ComboBoxInit()

Previously, the combobox will reach an indeterminate state whenever it's passed with a value out of range via ComboBoxInit(). To avoid such cases, let's initialize the current selection of the combobox with the front element of the settings vector whenever we detect an out of range value which is not declared in the vector.

To reproduce the issue, set "Renderer" to some sort of crazy value like 50 in the GSdx.ini file and it'll mess up the whole GSdx plugin dialog really bad. This patch prevents such undesirable behavior by simply selecting the front element in the vector when we read an unsupported value.
This commit is contained in:
Akash 2017-01-30 21:56:21 +05:30 committed by Jonathan Li
parent c56ac2cf3e
commit eda22c241d
1 changed files with 7 additions and 0 deletions

View File

@ -166,10 +166,17 @@ void GSDialog::SetTextAsInt(UINT id, int i)
void GSDialog::ComboBoxInit(UINT id, const vector<GSSetting>& settings, int32_t selectionValue, int32_t maxValue) void GSDialog::ComboBoxInit(UINT id, const vector<GSSetting>& settings, int32_t selectionValue, int32_t maxValue)
{ {
if (settings.empty())
return;
HWND hWnd = GetDlgItem(m_hWnd, id); HWND hWnd = GetDlgItem(m_hWnd, id);
SendMessage(hWnd, CB_RESETCONTENT, 0, 0); SendMessage(hWnd, CB_RESETCONTENT, 0, 0);
const auto is_present = [=](const GSSetting& x) { return selectionValue == x.value; };
if (std::none_of(settings.begin(), settings.end(), is_present))
selectionValue = settings.front().value;
for(size_t i = 0; i < settings.size(); i++) for(size_t i = 0; i < settings.size(); i++)
{ {
const GSSetting& s = settings[i]; const GSSetting& s = settings[i];