@@ -136,8 +136,9 @@ PolygonColorGraphicsItem::PolygonColorGraphicsItem(Layer::ptr mapping, bool outp
136136QPainterPath PolygonColorGraphicsItem::shape () const
137137{
138138 QPainterPath path;
139- Polygon* poly = static_cast <Polygon*>(_shape.toStrongRef ().data ());
140- Q_ASSERT (poly);
139+ auto strong = _shape.toStrongRef ();
140+ if (!strong) return path;
141+ Polygon* poly = static_cast <Polygon*>(strong.data ());
141142 path.addPolygon (poly->toPolygon ());
142143 return mapFromScene (path);
143144}
@@ -146,8 +147,9 @@ void PolygonColorGraphicsItem::_doPaint(QPainter *painter,
146147 const QStyleOptionGraphicsItem *option)
147148{
148149 Q_UNUSED (option);
149- Polygon* poly = static_cast <Polygon*>(_shape.toStrongRef ().data ());
150- Q_ASSERT (poly);
150+ auto strong = _shape.toStrongRef ();
151+ if (!strong) return ;
152+ Polygon* poly = static_cast <Polygon*>(strong.data ());
151153 painter->drawPolygon (mapFromScene (poly->toPolygon ()));
152154}
153155
@@ -162,7 +164,9 @@ void MeshColorGraphicsItem::_doPaint(QPainter *painter,
162164{
163165 Q_UNUSED (option);
164166
165- Mesh* mesh = static_cast <Mesh*>(_shape.toStrongRef ().data ());
167+ auto strong = _shape.toStrongRef ();
168+ if (!strong) return ;
169+ Mesh* mesh = static_cast <Mesh*>(strong.data ());
166170 QVector<QVector<Quad::ptr> > quads = mesh->getQuads2d ();
167171
168172 // Go through the mesh quad by quad.
@@ -186,8 +190,9 @@ QPainterPath EllipseColorGraphicsItem::shape() const
186190{
187191 // Create path for ellipse.
188192 QPainterPath path;
189- Ellipse* ellipse = static_cast <Ellipse*>(_shape.toStrongRef ().data ());
190- Q_ASSERT (ellipse);
193+ auto strong = _shape.toStrongRef ();
194+ if (!strong) return path;
195+ Ellipse* ellipse = static_cast <Ellipse*>(strong.data ());
191196 QTransform transform;
192197 transform.translate (ellipse->getCenter ().x (), ellipse->getCenter ().y ());
193198 transform.rotate (ellipse->getRotation ());
@@ -313,14 +318,17 @@ void TextureGraphicsItem::_postPaint(QPainter* painter,
313318
314319QSharedPointer<Texture> TextureGraphicsItem::_getTexture ()
315320{
316- return qSharedPointerCast<Texture>(_textureMapping.toStrongRef ()->getSource ());
321+ auto strong = _textureMapping.toStrongRef ();
322+ if (!strong) return QSharedPointer<Texture>();
323+ return qSharedPointerCast<Texture>(strong->getSource ());
317324}
318325
319326QPainterPath PolygonTextureGraphicsItem::shape () const
320327{
321328 QPainterPath path;
322- Polygon* poly = static_cast <Polygon*>(_shape.toStrongRef ().data ());
323- Q_ASSERT (poly);
329+ auto strong = _shape.toStrongRef ();
330+ if (!strong) return path;
331+ Polygon* poly = static_cast <Polygon*>(strong.data ());
324332 path.addPolygon (poly->toPolygon ());
325333 return mapFromScene (path);
326334}
@@ -335,6 +343,7 @@ void TriangleTextureGraphicsItem::_doDrawOutput(QPainter* painter)
335343 if (isOutput ())
336344 {
337345 MShape::ptr inputShape = _inputShape.toStrongRef ();
346+ if (!inputShape) return ;
338347 glBegin (GL_TRIANGLES );
339348 {
340349 for (int i=0 ; i<inputShape->nVertices (); i++)
@@ -563,8 +572,9 @@ QPainterPath EllipseTextureGraphicsItem::shape() const
563572{
564573 // Create path for ellipse.
565574 QPainterPath path;
566- Ellipse* ellipse = static_cast <Ellipse*>(_shape.toStrongRef ().data ());
567- Q_ASSERT (ellipse);
575+ auto strong = _shape.toStrongRef ();
576+ if (!strong) return path;
577+ Ellipse* ellipse = static_cast <Ellipse*>(strong.data ());
568578 QTransform transform;
569579 transform.translate (ellipse->getCenter ().x (), ellipse->getCenter ().y ());
570580 transform.rotate (ellipse->getRotation ());
0 commit comments