fix segfault when bottoming card in deck view (#5508)

This commit is contained in:
RickyRister
2025-01-20 19:06:00 -08:00
committed by GitHub
parent 090cc8c144
commit b004e91aa4

View File

@@ -282,7 +282,8 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
{
if (!isReversed) {
// if x is negative set it to add at end
if (x < 0) {
// if x is out-of-bounds then also set it to add at the end
if (x < 0 || x >= cards.size()) {
x = cards.size();
}
cards.insert(x, card);
@@ -292,7 +293,8 @@ void ZoneViewZone::addCardImpl(CardItem *card, int x, int /*y*/)
int insertionIndex = x - firstId;
if (insertionIndex >= 0) {
// card was put into a portion of the deck that's in the view
cards.insert(insertionIndex, card);
// qMin to prevent out-of-bounds error when bottoming a card that is already in the view
cards.insert(qMin(insertionIndex, cards.size()), card);
} else {
// card was put into a portion of the deck that's not in the view
updateCardIds(ADD_CARD);