Skip to content

Commit

Permalink
Solitaire: Make sure to not add card twice to m_focused_cards
Browse files Browse the repository at this point in the history
There is a possibility that the same card gets added twice to
m_focused_cards when first mousedown_event fires and then
doubleclick_event, without the cards redrawing first. This would cause
mouseup_event to try to pop too many cards from the stack, causing an
assertion to fail.

When the system is laggy there is also a high possibility that
mousedown_event would fire twice without redrawing the cards first,
causing another assertion to fail. Addditional mousedown_events will
just be ignored now.
  • Loading branch information
tlmrgvf authored and awesomekling committed Mar 11, 2020
1 parent cb39327 commit 629036e
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions Games/Solitaire/SolitaireWidget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -212,7 +212,7 @@ void SolitaireWidget::mousedown_event(GUI::MouseEvent& event)
update_score(5);
m_has_to_repaint = true;
}
} else {
} else if (m_focused_cards.is_empty()) {
to_check.add_all_grabbed_cards(click_location, m_focused_cards);
m_mouse_down_location = click_location;
to_check.set_focused(true);
Expand Down Expand Up @@ -313,8 +313,10 @@ void SolitaireWidget::doubleclick_event(GUI::MouseEvent& event)
return;
}

auto click_location = event.position();
if (!m_focused_cards.is_empty())
return;

auto click_location = event.position();
for (auto& to_check : m_stacks) {
if (to_check.type() == CardStack::Type::Foundation)
continue;
Expand Down

0 comments on commit 629036e

Please sign in to comment.