Fix segfault when game is closed while card view window is open (#5507)

This commit is contained in:
RickyRister 2025-01-20 19:06:55 -08:00 committed by GitHub
parent b004e91aa4
commit aeb1b9fb4f
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
9 changed files with 26 additions and 40 deletions

View file

@ -40,17 +40,6 @@ CardZone::CardZone(Player *_p,
&CardZone::refreshCardInfos);
}
CardZone::~CardZone()
{
qCDebug(CardZoneLog) << "CardZone destructor: " << name;
for (auto *view : views) {
if (view != nullptr) {
view->deleteLater();
}
}
clearContents();
}
void CardZone::retranslateUi()
{
for (int i = 0; i < cards.size(); ++i)

View file

@ -67,7 +67,6 @@ public:
bool _contentsKnown,
QGraphicsItem *parent = nullptr,
bool _isView = false);
~CardZone();
void retranslateUi();
void clearContents();
bool getHasCardAttr() const

View file

@ -40,13 +40,17 @@ ZoneViewZone::ZoneViewZone(Player *_p,
}
}
ZoneViewZone::~ZoneViewZone()
/**
* Deletes this ZoneView and removes it from the origZone's views.
* You should normally call this method instead of deleteLater()
*/
void ZoneViewZone::close()
{
emit beingDeleted();
qDebug("ZoneViewZone destructor");
emit closed();
if (!(revealZone && !writeableRevealZone)) {
origZone->getViews().removeOne(this);
}
deleteLater();
}
QRectF ZoneViewZone::boundingRect() const

View file

@ -65,7 +65,6 @@ public:
bool _writeableRevealZone = false,
QGraphicsItem *parent = nullptr,
bool _isReversed = false);
~ZoneViewZone();
QRectF boundingRect() const;
void paint(QPainter *painter, const QStyleOptionGraphicsItem *option, QWidget *widget);
void reorganizeCards();
@ -94,13 +93,14 @@ public:
return isReversed;
}
public slots:
void close();
void setGroupBy(CardList::SortOption _groupBy);
void setSortBy(CardList::SortOption _sortBy);
void setPileView(int _pileView);
private slots:
void zoneDumpReceived(const Response &r);
signals:
void beingDeleted();
void closed();
void optimumRectChanged();
void wheelEventReceived(QGraphicsSceneWheelEvent *event);

View file

@ -133,7 +133,7 @@ ZoneViewWidget::ZoneViewWidget(Player *_player,
setLayout(vbox);
connect(zone, &ZoneViewZone::optimumRectChanged, this, &ZoneViewWidget::resizeToZoneContents);
connect(zone, &ZoneViewZone::beingDeleted, this, &ZoneViewWidget::zoneDeleted);
connect(zone, &ZoneViewZone::closed, this, &ZoneViewWidget::zoneDeleted);
zone->initializeCards(cardList);
// QLabel sizes aren't taken into account until the widget is rendered.
@ -314,11 +314,12 @@ void ZoneViewWidget::handleScrollBarChange(int value)
void ZoneViewWidget::closeEvent(QCloseEvent *event)
{
disconnect(zone, &ZoneViewZone::beingDeleted, this, 0);
disconnect(zone, &ZoneViewZone::closed, this, 0);
// manually call zone->close in order to remove it from the origZones views
zone->close();
if (shuffleCheckBox.isChecked())
player->sendGameCommand(Command_Shuffle());
emit closePressed(this);
deleteLater();
zoneDeleted();
event->accept();
}