1
0
forked from 0ad/0ad

Fix rare crash on Linux when opening dropdowns.

Patch by: @wraitii
Accepted by: @Angen
Fixes #5598
Fixes #6225

Differential Revision: https://code.wildfiregames.com/D4183
This was SVN commit r25830.
This commit is contained in:
Stan 2021-07-20 20:59:45 +00:00
parent 5eec8039b4
commit 72a20be1df
2 changed files with 11 additions and 4 deletions

View File

@ -20,17 +20,21 @@ PlayerSettingControls.PlayerColor = class PlayerColor extends GameSettingControl
if (g_GameSettings.playerCount.nbPlayers < this.playerIndex + 1)
return;
let hidden = !g_IsController || g_GameSettings.map.type == "scenario";
const hidden = !g_IsController || g_GameSettings.map.type == "scenario";
this.dropdown.hidden = hidden;
this.playerColorHeading.hidden = hidden;
let value = g_GameSettings.playerColor.get(this.playerIndex);
this.setSelectedValue(value);
const value = g_GameSettings.playerColor.get(this.playerIndex);
this.playerBackgroundColor.sprite = "color:" + rgbToGuiColor(value, 100);
this.values = g_GameSettings.playerColor.available;
this.dropdown.list = this.values.map(color => coloredText(this.ColorIcon, rgbToGuiColor(color)));
this.dropdown.list_data = this.values.map((color, i) => i);
this.setSelectedValue(this.values.map((color, i) => {
if (color.r === value.r && color.g === value.g && color.b === value.b)
return i;
return undefined;
}).filter(x => x !== undefined)?.[0] ?? -1);
}
onSelectionChange(itemIdx)

View File

@ -169,7 +169,10 @@ void CDropDown::HandleMessage(SGUIMessage& Message)
m_ElementHighlight = m_Selected;
// Start at the position of the selected item, if possible.
GetScrollBar(0).SetPos(m_ItemsYPositions.empty() ? 0 : m_ItemsYPositions[m_ElementHighlight] - 60);
if (m_ItemsYPositions.empty() || m_ElementHighlight < 0 || static_cast<size_t>(m_ElementHighlight) >= m_ItemsYPositions.size())
GetScrollBar(0).SetPos(0);
else
GetScrollBar(0).SetPos(m_ItemsYPositions[m_ElementHighlight] - 60);
PlaySound(m_SoundOpened);
return; // overshadow