diff --git a/core_lib/src/canvaspainter.cpp b/core_lib/src/canvaspainter.cpp index 0cb9b7935..f412cdaa1 100644 --- a/core_lib/src/canvaspainter.cpp +++ b/core_lib/src/canvaspainter.cpp @@ -464,7 +464,8 @@ void CanvasPainter::paintTransformedSelection(QPainter& painter) if (layer->type() == Layer::BITMAP) { // Get the transformed image - BitmapImage* bitmapImage = dynamic_cast(layer)->getLastBitmapImageAtFrame(mFrameNumber, 0); + BitmapImage* bitmapImage = static_cast(layer)->getLastBitmapImageAtFrame(mFrameNumber, 0); + if (bitmapImage == nullptr) { return; }; BitmapImage transformedImage = bitmapImage->transformed(mSelection, mSelectionTransform, mOptions.bAntiAlias); // Paint the transformation output diff --git a/core_lib/src/interface/editor.cpp b/core_lib/src/interface/editor.cpp index 7189f1dda..ccf78cc89 100644 --- a/core_lib/src/interface/editor.cpp +++ b/core_lib/src/interface/editor.cpp @@ -541,13 +541,15 @@ void Editor::copy() if (layer->type() == Layer::BITMAP) { LayerBitmap* layerBitmap = static_cast(layer); + BitmapImage* bitmapImage = layerBitmap->getLastBitmapImageAtFrame(currentFrame(), 0); + if (bitmapImage == nullptr) { return; } if (select()->somethingSelected()) { - g_clipboardBitmapImage = layerBitmap->getLastBitmapImageAtFrame(currentFrame(), 0)->copy(select()->mySelectionRect().toRect()); // copy part of the image + g_clipboardBitmapImage = bitmapImage->copy(select()->mySelectionRect().toRect()); // copy part of the image } else { - g_clipboardBitmapImage = layerBitmap->getLastBitmapImageAtFrame(currentFrame(), 0)->copy(); // copy the whole image + g_clipboardBitmapImage = bitmapImage->copy(); // copy the whole image } clipboardBitmapOk = true; if (g_clipboardBitmapImage.image() != nullptr) @@ -557,10 +559,8 @@ void Editor::copy() { clipboardVectorOk = true; VectorImage *vectorImage = static_cast(layer)->getLastVectorImageAtFrame(currentFrame(), 0); - if (vectorImage != nullptr) - { - g_clipboardVectorImage = *vectorImage; // copy the image - } + if (vectorImage == nullptr) { return; } + g_clipboardVectorImage = *vectorImage; // copy the image } } @@ -589,7 +589,9 @@ void Editor::paste() } auto pLayerBitmap = static_cast(layer); mScribbleArea->handleDrawingOnEmptyFrame(); - pLayerBitmap->getLastBitmapImageAtFrame(currentFrame(), 0)->paste(&tobePasted); // paste the clipboard + BitmapImage *bitmapImage = pLayerBitmap->getLastBitmapImageAtFrame(currentFrame(), 0); + Q_CHECK_PTR(bitmapImage); + bitmapImage->paste(&tobePasted); // paste the clipboard } else if (layer->type() == Layer::VECTOR && clipboardVectorOk) { diff --git a/core_lib/src/interface/scribblearea.cpp b/core_lib/src/interface/scribblearea.cpp index 7fca72154..be5a498f2 100644 --- a/core_lib/src/interface/scribblearea.cpp +++ b/core_lib/src/interface/scribblearea.cpp @@ -1391,6 +1391,7 @@ void ScribbleArea::applyTransformedSelection() { handleDrawingOnEmptyFrame(); BitmapImage* bitmapImage = currentBitmapImage(layer); + if (bitmapImage == nullptr) { return; } BitmapImage transformedImage = bitmapImage->transformed(selectMan->mySelectionRect().toRect(), selectMan->selectionTransform(), true); bitmapImage->clear(selectMan->mySelectionRect()); @@ -1577,7 +1578,9 @@ void ScribbleArea::deleteSelection() } else if (layer->type() == Layer::BITMAP) { - currentBitmapImage(layer)->clear(selectMan->mySelectionRect()); + BitmapImage* bitmapImage = currentBitmapImage(layer); + Q_CHECK_PTR(bitmapImage); + bitmapImage->clear(selectMan->mySelectionRect()); } updateAllFrames(); } @@ -1603,7 +1606,10 @@ void ScribbleArea::clearImage() else if (layer->type() == Layer::BITMAP) { mEditor->backup(tr("Clear Image", "Undo step text")); - currentBitmapImage(layer)->clear(); + + BitmapImage* bitmapImage = currentBitmapImage(layer); + if (bitmapImage == nullptr) return; + bitmapImage->clear(); } else { diff --git a/core_lib/src/structure/object.cpp b/core_lib/src/structure/object.cpp index 52ae492bb..761eaf409 100644 --- a/core_lib/src/structure/object.cpp +++ b/core_lib/src/structure/object.cpp @@ -659,8 +659,10 @@ void Object::paintImage(QPainter& painter,int frameNumber, LayerBitmap* layerBitmap = static_cast(layer); BitmapImage* bitmap = layerBitmap->getLastBitmapImageAtFrame(frameNumber); - if (bitmap) + if (bitmap != nullptr) + { bitmap->paintImage(painter); + } } // paints the vector images diff --git a/core_lib/src/tool/buckettool.cpp b/core_lib/src/tool/buckettool.cpp index 523c848e5..bfeb3724d 100644 --- a/core_lib/src/tool/buckettool.cpp +++ b/core_lib/src/tool/buckettool.cpp @@ -166,7 +166,8 @@ void BucketTool::paintBitmap(Layer* layer) Layer* targetLayer = layer; // by default int layerNumber = editor()->layers()->currentLayerIndex(); // by default - BitmapImage* targetImage = ((LayerBitmap*)targetLayer)->getLastBitmapImageAtFrame(editor()->currentFrame(), 0); + BitmapImage* targetImage = static_cast(targetLayer)->getLastBitmapImageAtFrame(editor()->currentFrame(), 0); + if (targetImage == nullptr) { return; } // Can happen if the first frame is deleted while drawing QPoint point = QPoint(qFloor(getLastPoint().x()), qFloor(getLastPoint().y())); QRect cameraRect = mScribbleArea->getCameraRect().toRect(); diff --git a/core_lib/src/tool/polylinetool.cpp b/core_lib/src/tool/polylinetool.cpp index 20e073c2c..fe1ef33d6 100644 --- a/core_lib/src/tool/polylinetool.cpp +++ b/core_lib/src/tool/polylinetool.cpp @@ -265,7 +265,8 @@ void PolylineTool::endPolyline(QList points) if (layer->type() == Layer::BITMAP) { drawPolyline(points, points.last()); - BitmapImage *bitmapImage = ((LayerBitmap *)layer)->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0); + BitmapImage *bitmapImage = static_cast(layer)->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0); + if (bitmapImage == nullptr) { return; } // Can happen if the first frame is deleted while drawing bitmapImage->paste(mScribbleArea->mBufferImg); } mScribbleArea->setModified(mEditor->layers()->currentLayerIndex(), mEditor->currentFrame()); diff --git a/core_lib/src/tool/smudgetool.cpp b/core_lib/src/tool/smudgetool.cpp index dcde43f08..9407ba1a6 100644 --- a/core_lib/src/tool/smudgetool.cpp +++ b/core_lib/src/tool/smudgetool.cpp @@ -269,9 +269,10 @@ void SmudgeTool::drawStroke() if (!mScribbleArea->isLayerPaintable()) return; Layer* layer = mEditor->layers()->currentLayer(); - if (layer == NULL) { return; } + if (layer == nullptr) { return; } - BitmapImage *targetImage = ((LayerBitmap *)layer)->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0); + BitmapImage *targetImage = static_cast(layer)->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0); + if (targetImage == nullptr) { return; } // Can happen if the first frame is deleted while drawing StrokeTool::drawStroke(); QList p = strokeManager()->interpolateStroke();