Skip to content

Commit ce72536

Browse files
committed
Fix a crash in the puzzle when not properly initialized
1 parent 1a515c9 commit ce72536

File tree

3 files changed

+14
-6
lines changed

3 files changed

+14
-6
lines changed

src/app/qgisapp.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1341,8 +1341,8 @@ QgisApp::QgisApp( QSplashScreen *splash, bool restorePlugins, bool skipVersionCh
13411341
mCentralContainer->insertWidget( 2, puzzleWidget );
13421342
connect( mCoordsEdit, &QgsStatusBarCoordinatesWidget::weAreBored, this, [ this, puzzleWidget ]
13431343
{
1344-
puzzleWidget->letsGetThePartyStarted();
1345-
mCentralContainer->setCurrentIndex( 2 );
1344+
if ( puzzleWidget->letsGetThePartyStarted() )
1345+
mCentralContainer->setCurrentIndex( 2 );
13461346
} );
13471347
connect( puzzleWidget, &QgsPuzzleWidget::done, this, [ this ]
13481348
{

src/app/qgspuzzlewidget.cpp

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,9 @@ QgsPuzzleWidget::QgsPuzzleWidget( QgsMapCanvas *canvas )
8080

8181
void QgsPuzzleWidget::mousePressEvent( QMouseEvent *event )
8282
{
83+
if ( mTileWidth == 0 || mTileHeight == 0 )
84+
return; // not initialized
85+
8386
int idxEmpty = findEmpty( mPositions );
8487
int rEmpty = idxEmpty / mSize;
8588
int cEmpty = idxEmpty % mSize;
@@ -107,12 +110,17 @@ void QgsPuzzleWidget::mousePressEvent( QMouseEvent *event )
107110
}
108111
}
109112

110-
void QgsPuzzleWidget::letsGetThePartyStarted()
113+
bool QgsPuzzleWidget::letsGetThePartyStarted()
111114
{
112115
mPositions.clear();
113116
delete mScene;
114117
mItems.clear();
115118
mTextItems.clear();
119+
mTileWidth = 0;
120+
mTileHeight = 0;
121+
122+
if ( !mCanvas->layerCount() )
123+
return false;
116124

117125
mScene = new QGraphicsScene;
118126

@@ -168,6 +176,7 @@ void QgsPuzzleWidget::letsGetThePartyStarted()
168176
updateTilePositions();
169177

170178
setScene( mScene );
179+
return true;
171180
}
172181

173182
void QgsPuzzleWidget::updateTilePositions()

src/app/qgspuzzlewidget.h

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -27,15 +27,14 @@ class QgsPuzzleWidget : public QGraphicsView
2727
public:
2828
explicit QgsPuzzleWidget( QgsMapCanvas *canvas = nullptr );
2929

30+
bool letsGetThePartyStarted();
31+
3032
protected:
3133
void mousePressEvent( QMouseEvent *event ) override;
3234

3335
signals:
3436
void done();
3537

36-
public slots:
37-
void letsGetThePartyStarted();
38-
3938
private:
4039
void updateTilePositions();
4140

0 commit comments

Comments
 (0)