[Qgis-developer] segmentation fault in plugin using zoom tool

Martin Dobias wonder.sk at gmail.com
Thu Oct 5 09:19:30 EDT 2006


On 10/5/06, Tim Sutton <tim at linfiniti.com> wrote:
> > if I recall correctly, you shouldn't store map tool because the tool
> > is owned by map canvas and the old tool gets always deleted in
> > QgsMapCanvas::setMapTool.
>
> Oh? So my tutorial is wrong?
>
> http://blog.qgis.org/?q=node/14
>
> I created the tools in the ctor and store them as class members. My
> tutorial app works - is this just because by luck the memory used by
> the pointer hasnt been overwritten? I thought delete will clear the
> memory used too?

Hi Tim,

now I took another look on your tutorial and the map canvas sources
and - yes, that tutorial doesn't fit exactly into my original thoughts
of how should it work. Why does it work? I've found out that it's
because of a bug in QgsMapCanvas::setMapTool that prevents deletion of
old tool when changing from zoom tool to another zoom tool (since also
tool for panning is considered as zoom tool). This also means that a
memory leak is happening in QGIS when switching between memory tools.

So, the question is - how to solve this. I would say that the way how
you use map tools in the tutorial is more straightforward. I guess the
best way is to modify the setMapTool function (and some others calling
it) not to take ownership and not to delete the map tools. I'll
investigate it and will alter that if I won't find any great problems.
This will result in policy that caller will create the map tool and
will have to delete it afterwards - and the tutorial can be left
unmodified :-)

What do you think about that?

Martin



More information about the Qgis-developer mailing list