[Qgis-developer] Memory Error

Carson Farmer carson.farmer at gmail.com
Thu Jan 8 09:36:41 EST 2009


Martin,
> On Thu, Jan 8, 2009 at 1:22 PM, Carson Farmer <carson.farmer at gmail.com> wrote:
>   
>> Hi list,
>>
>> Does anyone have any idea why the following python error might pop up:
>>
>> An error has occured while executing Python code:
>>
>> Traceback (most recent call last):
>>   File
>> "/home/_user_name_/.qgis/python/plugins/fTools/tools/doGeoprocessing.py",
>> line 58, in outFile
>>     ( self.shapefileName, self.encoding ) =
>> ftools_utils.saveDialog( self )
>>   File
>> "/home/_user_name_/.qgis/python/plugins/fTools/tools/ftools_utils.py", line
>> 292, in saveDialog
>>     shapefileName = unicode(fileDialog.selectedFiles().first())
>> MemoryError
>>
>> The associated code is essentially as follows:
>>
>> fileDialog = QgsEncodingFileDialog()
>>
>> fileDialog.setDefaultSuffix(QString("shp"))
>>
>> fileDialog.setFileMode(QFileDialog.AnyFile)
>>
>> fileDialog.setAcceptMode(QFileDialog.AcceptSave)
>>
>> fileDialog.exec_()
>>
>> shapefileName = unicode(fileDialog.selectedFiles().first())
>>
>> I can't actually seem to get this behaviour myself, but many others do.
>>
>> Any thoughts?
>>     
>
> Hi Carson,
>
> I suspect there is something wrong with handling of the returned
> string list. first() method returns only a reference so imagine this
> scenario:
> 1. a new temporary list is created as a result of calling
> fileDialog.selectedFiles()
> 2. first() is called which returns reference to first item in the temporary list
> 3. now the list is not needed anymore, so it gets deleted (!), the
> reference is left broken
> 4. conversion of broken reference raises MemoryError
>
> That's what I think. This also explains why it works sometimes and
> sometimes not. A similar problem is this (ticket #777):
> feat = QgsFeature ( .... )
> geom = feat.geometry()
> del feat
>
> This time feature is deleted but geom contains invalid pointer. I've
> been adviced to use virtual destructor on QgsFeature that would notify
> geometry object that the pointer is invalid, however I had no success.
>
> I would recommend you to ask also on PyQt/PyKDE mailing list to be
> sure. And how to work this around? Just store the reference to string
> list while it's needed:
> files = fileDialog.selectedFiles()
> shapefileName = unicode(files.first())
>   
Great advice Martin, I'll implement this right away, and fire off an 
email to PyQt mailing list to find out more!

Thanks!

Carson


More information about the Qgis-developer mailing list