[Qgis-developer] QgsRubberBand RuntimeError: underlying C/C++ object has been deleted

Radim Blazek radim.blazek at gmail.com
Wed Feb 12 23:39:26 PST 2014


On Thu, Feb 13, 2014 at 8:35 AM, Radim Blazek <radim.blazek at gmail.com> wrote:
> On Thu, Feb 13, 2014 at 7:13 AM, Denis Rouzaud <denis.rouzaud at gmail.com> wrote:
>> Hi Radim,
>>
>> Can you show us the whole code?
>
> https://github.com/blazek/spline/blob/master/spline/spline.py

And traceback:

Traceback (most recent call last):
  File "C:\Users\user1/.qgis2/python/plugins\spline\spline.py", line
174, in canvasMoveEvent
    self.setRubberBandPoints(points )
  File "C:\Users\user1/.qgis2/python/plugins\spline\spline.py", line
207, in setRubberBandPoints
    self.rb.addPoint( point, update )
RuntimeError: underlying C/C++ object has been deleted

Radim

> Radim
>
>> Cheers,
>>
>> Denis
>>
>>
>> On 12. 02. 14 19:17, Radim Blazek wrote:
>>>
>>> On Wed, Feb 12, 2014 at 2:50 PM, Martin Dobias <wonder.sk at gmail.com>
>>> wrote:
>>>>
>>>> Hi Radim
>>>>
>>>> On Wed, Feb 12, 2014 at 8:03 PM, Radim Blazek <radim.blazek at gmail.com>
>>>> wrote:
>>>>>
>>>>> On Wed, Feb 12, 2014 at 1:45 PM, Radim Blazek <radim.blazek at gmail.com>
>>>>> wrote:
>>>>>>
>>>>>> I am using rubber band in Python plugin:
>>>>>>    self.rb = QgsRubberBand(self.canvas,  QGis.Polygon)
>>>>>> and on mouse move
>>>>>>    self.rb.addPoint( point, update )
>>>>>>
>>>>>> It works well on most systems only for Win7/32bit (QGIS 2.0.1, Python
>>>>>> 2.7.4) it was reported that it fails with "RuntimeError: underlying
>>>>>> C/C++ object has been deleted"
>>>>
>>>> When does it report the error - when closing QGIS?
>>>
>>> I don't know but I presume when map tool is used, it is called from
>>> QgsMapTool::canvasMoveEvent().
>>>
>>> Radim
>>>
>>>>>> I see that ownership of rubber band is passed to map canvas
>>>>>>
>>>>>>     QgsRubberBand( QgsMapCanvas* mapCanvas /TransferThis/,
>>>>>> QGis::GeometryType geometryType = QGis::Line );
>>>>>>
>>>>>> that is OK, but QgsMapCanvas should not delete QGraphicsItem until it
>>>>>> is destructed.
>>>>>>
>>>>>> So how can the QgsRubberBand be deleted before QGIS is closed?
>>>>>
>>>>> BTW, because true owner of QGraphicsItem is QGraphicsScene, should not
>>>>> we first mScene->removeItem() (which returns ownership) before item is
>>>>> deleted in QgsMapCanvas destructor?
>>>>
>>>> That's the correct approach in Python (IIRC). You can remove the item
>>>> in your map tool's deactivate() method.
>>>>
>>>> Regards
>>>> Martin
>>>
>>> _______________________________________________
>>> Qgis-developer mailing list
>>> Qgis-developer at lists.osgeo.org
>>> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>>
>>


More information about the Qgis-developer mailing list