Fix Ricky Crash (#5609)

This commit is contained in:
Zach H 2025-02-11 20:39:41 -05:00 committed by GitHub
parent 8916e049bd
commit 356b00e8c7
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
3 changed files with 24 additions and 8 deletions

View file

@ -46,6 +46,8 @@
# cockatrice_xml.xml_4_parser = false # cockatrice_xml.xml_4_parser = false
# card_list = false # card_list = false
# stack_zone = false
flow_layout.debug = false flow_layout.debug = false
flow_widget.debug = false flow_widget.debug = false
flow_widget.size.debug = false flow_widget.size.debug = false

View file

@ -28,7 +28,7 @@ void StackZone::addCardImpl(CardItem *card, int x, int /*y*/)
{ {
// if x is negative set it to add at end // if x is negative set it to add at end
if (x < 0 || x >= cards.size()) { if (x < 0 || x >= cards.size()) {
x = cards.size(); x = static_cast<int>(cards.size());
} }
cards.insert(x, card); cards.insert(x, card);
@ -44,7 +44,7 @@ void StackZone::addCardImpl(CardItem *card, int x, int /*y*/)
QRectF StackZone::boundingRect() const QRectF StackZone::boundingRect() const
{ {
return QRectF(0, 0, 100, zoneHeight); return {0, 0, 100, zoneHeight};
} }
void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/) void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*option*/, QWidget * /*widget*/)
@ -60,7 +60,7 @@ void StackZone::paint(QPainter *painter, const QStyleOptionGraphicsItem * /*opti
void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint) void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone *startZone, const QPoint &dropPoint)
{ {
if (!startZone) { if (startZone == nullptr || startZone->getPlayer() == nullptr) {
return; return;
} }
@ -69,19 +69,31 @@ void StackZone::handleDropEvent(const QList<CardDragItem *> &dragItems, CardZone
cmd.set_start_zone(startZone->getName().toStdString()); cmd.set_start_zone(startZone->getName().toStdString());
cmd.set_target_player_id(player->getId()); cmd.set_target_player_id(player->getId());
cmd.set_target_zone(getName().toStdString()); cmd.set_target_zone(getName().toStdString());
int index;
int index = 0;
if (cards.isEmpty()) { if (cards.isEmpty()) {
index = 0; index = 0;
} else { } else {
const int cardCount = cards.size(); const auto cardCount = static_cast<int>(cards.size());
const auto &card = cards.at(0);
if (card == nullptr) {
qCWarning(StackZoneLog) << "Attempted to move card from" << startZone->getName() << ", but was null";
return;
}
index = qRound(divideCardSpaceInZone(dropPoint.y(), cardCount, boundingRect().height(), index = qRound(divideCardSpaceInZone(dropPoint.y(), cardCount, boundingRect().height(),
cards.at(0)->boundingRect().height(), true)); card->boundingRect().height(), true));
} }
if (startZone == this) { if (startZone == this) {
if (dragItems.at(0) != nullptr && cards.at(index)->getId() == dragItems.at(0)->getId()) { const auto &dragItem = dragItems.at(0);
const auto &card = cards.at(index);
if (card != nullptr && dragItem != nullptr && card->getId() == dragItem->getId()) {
return; return;
} }
} }
cmd.set_x(index); cmd.set_x(index);
cmd.set_y(0); cmd.set_y(0);
@ -99,7 +111,7 @@ void StackZone::reorganizeCards()
if (!cards.isEmpty()) { if (!cards.isEmpty()) {
QSet<ArrowItem *> arrowsToUpdate; QSet<ArrowItem *> arrowsToUpdate;
const int cardCount = cards.size(); const auto cardCount = static_cast<int>(cards.size());
qreal totalWidth = boundingRect().width(); qreal totalWidth = boundingRect().width();
qreal cardWidth = cards.at(0)->boundingRect().width(); qreal cardWidth = cards.at(0)->boundingRect().width();
qreal xspace = 5; qreal xspace = 5;

View file

@ -3,6 +3,8 @@
#include "select_zone.h" #include "select_zone.h"
inline Q_LOGGING_CATEGORY(StackZoneLog, "stack_zone");
class StackZone : public SelectZone class StackZone : public SelectZone
{ {
Q_OBJECT Q_OBJECT