tag 763037 patch
thanks


Hi there!

I've fixed it myself. :-) Please find the patch in the attachment.

The cause of the segmentation fault was that the Render2D functions GetTextHeight, GetTextFullHeight, GetCharWidth, GetStringWidth and GetTextDimensions created their own local QPainter object on the shared QPaintDevice, which invalidated the shared and permanent QPainter that other functions of the same class use on the same QPaintDevice. Now all functions use the same QPainter object.

Cheers,
Martin

Description: Fix crash (segfault) after using text tool
 This patch fixes a segmentation fault that occurs whenever
 anything is rendered after one of the functions GetTextHeight,
 GetTextFullHeight, GetCharWidth, GetStringWidth or
 GetTextDimensions is called. They destroy the state of the
 shared QPainter by using a separate one on the same context.
Author: Martin Steghöfer <mar...@steghoefer.eu>
Bug-Debian: http://bugs.debian.org/763037

--- a/xdrawchem/render2d_text.cpp
+++ b/xdrawchem/render2d_text.cpp
@@ -554,40 +554,32 @@
 
 int Render2D::GetTextHeight( QFont fn )
 {
-    QPainter p( this );
-
-    p.setFont( fn );
-    QFontMetrics fm = p.fontMetrics();
+    painter->setFont( fn );
+    QFontMetrics fm = painter->fontMetrics();
 
     return fm.ascent();
 }
 
 int Render2D::GetTextFullHeight( QFont fn )
 {
-    QPainter p( this );
-
-    p.setFont( fn );
-    QFontMetrics fm = p.fontMetrics();
+    painter->setFont( fn );
+    QFontMetrics fm = painter->fontMetrics();
 
     return fm.height();
 }
 
 int Render2D::GetCharWidth( QChar ch, QFont fn )
 {
-    QPainter p( this );
-
-    p.setFont( fn );
-    QFontMetrics fm = p.fontMetrics();
+    painter->setFont( fn );
+    QFontMetrics fm = painter->fontMetrics();
 
     return fm.width( ch );
 }
 
 int Render2D::GetStringWidth( QString ch, QFont fn )
 {
-    QPainter p( this );
-
-    p.setFont( fn );
-    QFontMetrics fm = p.fontMetrics();
+    painter->setFont( fn );
+    QFontMetrics fm = painter->fontMetrics();
 
     return fm.width( ch );
 }
@@ -601,11 +593,9 @@
 
     }
 
-    QPainter p( this );
-
-    p.setFont( fn );
+    painter->setFont( fn );
     int maxwidth, lwidth, linecount, height;
-    QFontMetrics fm = p.fontMetrics();
+    QFontMetrics fm = painter->fontMetrics();
     QTextStream t( &txt, QIODevice::ReadOnly );
 
     linecount = 1;

Reply via email to