Skip to content

Commit

Permalink
Check for null pointer returned by getLastBitmapImageAtFrame where re…
Browse files Browse the repository at this point in the history
…levant

See commit message of f61b6ad. This is the same thing execpt for
bitmaps.
  • Loading branch information
scribblemaniac authored and chchwy committed Jun 19, 2020
1 parent d4c7bc6 commit 75d6cc5
Show file tree
Hide file tree
Showing 7 changed files with 29 additions and 15 deletions.
3 changes: 2 additions & 1 deletion core_lib/src/canvaspainter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -464,7 +464,8 @@ void CanvasPainter::paintTransformedSelection(QPainter& painter)
if (layer->type() == Layer::BITMAP)
{
// Get the transformed image
BitmapImage* bitmapImage = dynamic_cast<LayerBitmap*>(layer)->getLastBitmapImageAtFrame(mFrameNumber, 0);
BitmapImage* bitmapImage = static_cast<LayerBitmap*>(layer)->getLastBitmapImageAtFrame(mFrameNumber, 0);
if (bitmapImage == nullptr) { return; };
BitmapImage transformedImage = bitmapImage->transformed(mSelection, mSelectionTransform, mOptions.bAntiAlias);

// Paint the transformation output
Expand Down
16 changes: 9 additions & 7 deletions core_lib/src/interface/editor.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -541,13 +541,15 @@ void Editor::copy()
if (layer->type() == Layer::BITMAP)
{
LayerBitmap* layerBitmap = static_cast<LayerBitmap*>(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)
Expand All @@ -557,10 +559,8 @@ void Editor::copy()
{
clipboardVectorOk = true;
VectorImage *vectorImage = static_cast<LayerVector*>(layer)->getLastVectorImageAtFrame(currentFrame(), 0);
if (vectorImage != nullptr)
{
g_clipboardVectorImage = *vectorImage; // copy the image
}
if (vectorImage == nullptr) { return; }
g_clipboardVectorImage = *vectorImage; // copy the image
}
}

Expand Down Expand Up @@ -589,7 +589,9 @@ void Editor::paste()
}
auto pLayerBitmap = static_cast<LayerBitmap*>(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)
{
Expand Down
10 changes: 8 additions & 2 deletions core_lib/src/interface/scribblearea.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down Expand Up @@ -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();
}
Expand All @@ -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
{
Expand Down
4 changes: 3 additions & 1 deletion core_lib/src/structure/object.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -659,8 +659,10 @@ void Object::paintImage(QPainter& painter,int frameNumber,
LayerBitmap* layerBitmap = static_cast<LayerBitmap*>(layer);

BitmapImage* bitmap = layerBitmap->getLastBitmapImageAtFrame(frameNumber);
if (bitmap)
if (bitmap != nullptr)
{
bitmap->paintImage(painter);
}

}
// paints the vector images
Expand Down
3 changes: 2 additions & 1 deletion core_lib/src/tool/buckettool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LayerBitmap*>(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();
Expand Down
3 changes: 2 additions & 1 deletion core_lib/src/tool/polylinetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -265,7 +265,8 @@ void PolylineTool::endPolyline(QList<QPointF> points)
if (layer->type() == Layer::BITMAP)
{
drawPolyline(points, points.last());
BitmapImage *bitmapImage = ((LayerBitmap *)layer)->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0);
BitmapImage *bitmapImage = static_cast<LayerBitmap*>(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());
Expand Down
5 changes: 3 additions & 2 deletions core_lib/src/tool/smudgetool.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<LayerBitmap*>(layer)->getLastBitmapImageAtFrame(mEditor->currentFrame(), 0);
if (targetImage == nullptr) { return; } // Can happen if the first frame is deleted while drawing
StrokeTool::drawStroke();
QList<QPointF> p = strokeManager()->interpolateStroke();

Expand Down

0 comments on commit 75d6cc5

Please sign in to comment.