<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <meta content="text/html; charset=UTF-8" http-equiv="Content-Type">
  </head>
  <body bgcolor="#ffffff" text="#000000">
    <tt>Ivan,<br>
      <br>
      in my experience it is often enough to keep a ref to the dataset
      to avoid these segfaults. However, my experience is more with gdal
      (raster) than with ogr (vector), so ymmv, and some experimenting
      might be required. Just start with keeping a ds reference, if that
      doesn't work, go further up the chain and also keep a ref to the
      layer, and so on.<br>
      <br>
      Vincent Schut.<br>
    </tt><br>
    On 10/26/2010 04:54 PM, Ivan Willig wrote:
    <blockquote
      cite="mid:AANLkTi=Ca-qJu=zadTwwfNvbdNsnN1S=QQFNhBZAbHfW@mail.gmail.com"
      type="cite">Thanks Frank. That seems to be the issue. Whats the
      rule about this how long you should keep a reference. For example
      this causes the same issue. 
      <div><br>
        <div>ds.GetLayer().GetFeature(0).GetGeometryRef().GetEnvelope()</div>
        <div><br>
        </div>
        <div>Which I am going to guess is because I should keep a
          reference to the geometry. Correct? </div>
        <div><br clear="all">
          <div>Ivan Willig</div>
          <br>
          <br>
          <br>
          <br>
          <div class="gmail_quote">On Tue, Oct 26, 2010 at 10:44 AM,
            Frank Warmerdam <span dir="ltr">&lt;<a
                moz-do-not-send="true" href="mailto:warmerdam@pobox.com">warmerdam@pobox.com</a>&gt;</span>
            wrote:<br>
            <blockquote class="gmail_quote" style="margin: 0pt 0pt 0pt
              0.8ex; border-left: 1px solid rgb(204, 204, 204);
              padding-left: 1ex;">
              <div>
                <div class="h5">Ivan Willig wrote:<br>
                  <blockquote class="gmail_quote" style="margin: 0pt 0pt
                    0pt 0.8ex; border-left: 1px solid rgb(204, 204,
                    204); padding-left: 1ex;">
                    Hi list,<br>
                    I am having an issues with using the python swig
                    based bindings. I am on Fedora 13 using the default
                    gdal rpm, which is at version 1.6.2. My issue is
                    when i stack method calls.  For example when I do
                    the following: <br>
ogr.Open("/home/ivan/dev/bigapps/data/nyco.shp").GetLayer().GetFeature(0)<br>
                    <br>
                    <br>
                    I get a Segmentation fault. Here are the results of
                    strace <a moz-do-not-send="true"
                      href="http://paste.pocoo.org/show/281682/"
                      target="_blank">http://paste.pocoo.org/show/281682/</a>.
                    What am I doing wrong? Should I just hand compile a
                    new version of gdal? Or is this not an advised usage
                    of the python bindings? A limitation in swig? Thanks
                    for your help.<br>
                  </blockquote>
                  <br>
                </div>
              </div>
              Ivan,<br>
              <br>
              I believe the problem is object lifetimes.  Keep a
              reference to the<br>
              datasource around until you are done with the feature(s).<br>
              <br>
              ds = ogr.Open("/home/ivan/dev/bigapps/data/nyco.shp")<br>
              feat = ds.GetLayer().GetFeature(0)<br>
              ...<br>
              feat = None<br>
              ds = None<br>
              <br>
              Best regards,<br>
              <font color="#888888">
                -- <br>
---------------------------------------+--------------------------------------<br>
                I set the clouds in motion - turn up   | Frank
                Warmerdam, <a moz-do-not-send="true"
                  href="mailto:warmerdam@pobox.com" target="_blank">warmerdam@pobox.com</a><br>
                light and sound - activate the windows | <a
                  moz-do-not-send="true"
                  href="http://pobox.com/%7Ewarmerdam" target="_blank">http://pobox.com/~warmerdam</a><br>
                and watch the world go round - Rush    | Geospatial
                Programmer for Rent<br>
                <br>
              </font></blockquote>
          </div>
          <br>
        </div>
      </div>
      <pre wrap="">
<fieldset class="mimeAttachmentHeader"></fieldset>
_______________________________________________
gdal-dev mailing list
<a class="moz-txt-link-abbreviated" href="mailto:gdal-dev@lists.osgeo.org">gdal-dev@lists.osgeo.org</a>
<a class="moz-txt-link-freetext" href="http://lists.osgeo.org/mailman/listinfo/gdal-dev">http://lists.osgeo.org/mailman/listinfo/gdal-dev</a></pre>
    </blockquote>
  </body>
</html>