[Qgis-developer] Avoid segmentation fault on selection when commit

Tim Sutton tim at linfiniti.com
Sat Jul 12 03:35:34 EDT 2008


Hi Adrien

I suggest to attach this as a patch to the bug tracking system. Marco
probably would have a better idea of which solution you propose is
better.

Regards

Tim

2008/7/11 Adrien Gruson <agruson at archivideo.com>:
> Hi all,
> I develop Qgis plugin and I have a little problem with selections and
> commit.
> _
> Steps :_
>
>  1. You select added features (they have negative id).
>  2. You commit change (commit attribute positive id to added features)
>    but your mSelectedFeatureIds haven't updated and have always
>    negative Id in mSelectedFeatureIds.
>  3. If the user doesn't reselect features, you have a segmentation
>    fault because if you do a iteration on mSelectedFeatures there are
>    wrong id.
>
>
> _A possible solution :
>
> _
>
>  * Erase all negative ids in commitChanges
>
>  <http://doc.qgis.org/classQgsVectorLayer.html#fab34baf331320a8c3212993f5fccfa1>
>    ()
>
> Advantage : easy to do
> Disadvantage: user's selection change when he commit
>
>  * Provider return new id of added feature and replace in
>    mSelectedFeatureIds.
>
> Advantage :  no change for user when he commit.
> Disadvantage : more change to do in code.
>
> Ps: I attach patch of first solution.
>
> Index: /raid/homes/agruson/workspace/SVN_Src_Qgis/core/qgsvectorlayer.cpp
> ===================================================================
> --- /raid/homes/agruson/workspace/SVN_Src_Qgis/core/qgsvectorlayer.cpp
>  (revision 8751)
> +++ /raid/homes/agruson/workspace/SVN_Src_Qgis/core/qgsvectorlayer.cpp
>  (working copy)
> @@ -2476,6 +2476,14 @@
>     }
>     else
>     {
> +         //Remove all negative Id in selected features
> +         if(mSelectedFeatureIds.size() > 0)
> +         {
> +           for(QgsFeatureList::iterator it = mAddedFeatures.begin(); it !=
> mAddedFeatures.end(); ++it)
> +           {
> +               mSelectedFeatureIds.remove(it->featureId());
> +           }
> +         }
>       // done, remove features from the list
>       mAddedFeatures.clear();
>       addedFeaturesOk = TRUE;
>
> _______________________________________________
> Qgis-developer mailing list
> Qgis-developer at lists.osgeo.org
> http://lists.osgeo.org/mailman/listinfo/qgis-developer
>
>



-- 
Tim Sutton
QGIS Project Steering Committee Member - Release Manager
Visit http://qgis.org for a great open source GIS
openModeller Desktop Developer
Visit http://openModeller.sf.net for a great open source ecological
niche modelling tool
Home Page: http://tim.linfiniti.com
Skype: timlinux
Irc: timlinux on #qgis at freenode.net


More information about the Qgis-developer mailing list