Opened 8 years ago

Closed 8 years ago

#6585 closed defect (wontfix)

SegFault

Reported by: aFuerst Owned by: hobu
Priority: normal Milestone:
Component: PythonBindings Version: 2.1.0
Severity: normal Keywords:
Cc:

Description

I'm opening a geotif file in a function call and setting it's raster band to an instance variable in a class. Later when trying to access data from the raster in another function, it throws a segfault and kills the program

Attachments (1)

loader.py (3.7 KB ) - added by aFuerst 8 years ago.
Contains the code I'm working with and experiencing the error

Download all attachments as: .zip

Change History (2)

by aFuerst, 8 years ago

Attachment: loader.py added

Contains the code I'm working with and experiencing the error

comment:1 by Even Rouault, 8 years ago

Resolution: wontfix
Status: newclosed

You're running into one of the gotchas explained in https://trac.osgeo.org/gdal/wiki/PythonGotchas

The issue is in

  def _openFile(self):
        f = gdal.Open(self.file_name)
        self.open_file = f.GetRasterBand(1)

Basically as soon as this function returns the dataset is closed because no Python object retains a reference to it, so the self.open_file points to a defunct C++ object. Workaround: maintain the reference to f alive while you work on the band object

Note: See TracTickets for help on using tickets.