Fix crash clicking in the PaletteView area with an empty tileset

This commit is contained in:
David Capello 2020-10-23 16:07:54 -03:00
parent f416d0c356
commit 3e55928d41

View File

@ -620,13 +620,15 @@ bool PaletteView::onProcessMessage(Message* msg)
if (m_state == State::SELECTING_COLOR &&
m_hot.part == Hit::COLOR) {
int idx = m_hot.color;
idx = base::clamp(idx, 0, m_adapter->size()-1);
idx = base::clamp(idx, 0, std::max(0, m_adapter->size()-1));
const MouseButton button = mouseMsg->button();
if (hasCapture() && ((idx != m_currentEntry) ||
(msg->type() == kMouseDownMessage) ||
(button == kButtonMiddle))) {
if (hasCapture() &&
(idx >= 0 && idx < m_adapter->size()) &&
((idx != m_currentEntry) ||
(msg->type() == kMouseDownMessage) ||
(button == kButtonMiddle))) {
if (button != kButtonMiddle) {
if (!msg->ctrlPressed() && !msg->shiftPressed())
deselect();