Bug report #14217

Segfault on QgsMapCanvas() creation

Added by D. Hiepler about 5 years ago. Updated over 4 years ago.

Category:Python plugins
Affected QGIS version:master Regression?:No
Operating System: Easy fix?:No
Pull Request or Patch supplied:No Resolution:invalid
Crashes QGIS or corrupts data:Yes Copied to github as #:22218


I modified the example code from http://docs.qgis.org/testing/en/docs/pyqgis_developer_cookbook/canvas.html#writing-custom-map-canvas-items
and ended up with

import sys
from qgis.core import QgsApplication, QgsProject
from qgis.gui import QgsMapCanvas

# install prefix - optional, if QGIS_PREFIX_PATH is set
QgsApplication.setPrefixPath('/usr', True)  
# where the auth database is - optional, if QGIS_AUTH_DB_DIR_PATH is set 

# init application context
app = QgsApplication(sys.argv, False)

# Map canvas
canvas = QgsMapCanvas()    # <- segfault



But with current master, it crashes (i suppose there's some Qt initialization missing):

Program received signal SIGSEGV, Segmentation fault.
0x00007ffff2e9c88c in QCursor::pos() () from /usr/lib64/qt4/libQtGui.so.4
(gdb) bt
#0  0x00007ffff2e9c88c in QCursor::pos() () from /usr/lib64/qt4/libQtGui.so.4
#1  0x00007ffff2e2fd57 in QMouseEvent::QMouseEvent(QEvent::Type, QPoint const&, Qt::MouseButton, QFlags<Qt::MouseButton>, QFlags<Qt::KeyboardModifier>) () from /usr/lib64/qt4/libQtGui.so.4
#2  0x00007ffff340bbaa in QGraphicsViewPrivate::QGraphicsViewPrivate() () from /usr/lib64/qt4/libQtGui.so.4
#3  0x00007ffff340bedf in QGraphicsView::QGraphicsView(QWidget*) () from /usr/lib64/qt4/libQtGui.so.4
#4  0x00007fffe328fa0b in QgsMapCanvas::QgsMapCanvas(QWidget*, char const*) () from /usr/lib64/libqgis_gui.so.2.13.0
#5  0x00007fffe3c7ce63 in sipQgsMapCanvas::sipQgsMapCanvas(QWidget*, char const*) ()
   from /usr/lib64/python2.7/site-packages/qgis/_gui.so
#6  0x00007fffe3c8addf in init_type_QgsMapCanvas () from /usr/lib64/python2.7/site-packages/qgis/_gui.so
#7  0x00007ffff6684733 in sipSimpleWrapper_init () from /usr/lib64/python2.7/site-packages/sip.so
#8  0x00007ffff7aae8ef in type_call () from /usr/lib64/libpython2.7.so.1.0
#9  0x00007ffff7a5b533 in PyObject_Call () from /usr/lib64/libpython2.7.so.1.0
#10 0x00007ffff7aedb8a in PyEval_EvalFrameEx () from /usr/lib64/libpython2.7.so.1.0
#11 0x00007ffff7af0ac0 in PyEval_EvalCodeEx () from /usr/lib64/libpython2.7.so.1.0
#12 0x00007ffff7af0bb9 in PyEval_EvalCode () from /usr/lib64/libpython2.7.so.1.0
#13 0x00007ffff7b0961f in run_mod () from /usr/lib64/libpython2.7.so.1.0
#14 0x00007ffff7b0a772 in PyRun_FileExFlags () from /usr/lib64/libpython2.7.so.1.0
#15 0x00007ffff7b0b877 in PyRun_SimpleFileExFlags () from /usr/lib64/libpython2.7.so.1.0
#16 0x00007ffff7b1c6da in Py_Main () from /usr/lib64/libpython2.7.so.1.0
#17 0x00007ffff747a7b0 in __libc_start_main () from /lib64/libc.so.6
#18 0x0000000000400759 in _start ()


#1 Updated by D. Hiepler about 5 years ago

PS: I forgot to mention, that I modified the example code to work around #13494

#2 Updated by Giovanni Manghi about 5 years ago

  • Target version set to Future Release - High Priority
  • Priority changed from Normal to High

#3 Updated by Matthias Kuhn over 4 years ago

  • Resolution set to invalid
  • Status changed from Open to Closed

Make it a gui application and it will work:

app = QgsApplication(sys.argv, True)

Also available in: Atom PDF