Permalink
Browse files

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.
  • Loading branch information...
1 parent c56ac2c commit eda22c241d64e50702fbdde95d53a3fcb244c426 @ssakash ssakash committed with turtleli Jan 30, 2017
Showing with 7 additions and 0 deletions.
  1. +7 −0 plugins/GSdx/GSDialog.cpp
@@ -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)
{
+ if (settings.empty())
+ return;
+
HWND hWnd = GetDlgItem(m_hWnd, id);
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++)
{
const GSSetting& s = settings[i];

0 comments on commit eda22c2

Please sign in to comment.