Opened 23 years ago

Closed 21 years ago

#64 closed defect (fixed)

Mapscript/Perl Segfaults on getShape()

Reported by: refractions Owned by: sdlime
Priority: high Milestone:
Component: MapScript Version: 3.5
Severity: normal Keywords:
Cc:

Description

The following code snippet segfaults at the getShape():

my $rv = $lyr->queryByPoint($map,$pt,$mapscript::MS_SINGLE,10.0);

die "Query failed" if $rv != $mapscript::MS_SUCCESS;

print $rslt->{shapeindex},"\n";
print $rslt->{tileindex},"\n";

my $shp = new shapeObj($mapscript::MS_SHAPE_POLYGON);
$rv = $lyr->getShape($shp,$rslt->{tileindex},$rslt->{shapeindex});

Change History (5)

comment:1 by sdlime, 23 years ago

Status: newassigned

comment:2 by sdlime, 23 years ago

While this certainly is a bug it also looks to be an error the script coding. 
There is no reference to the layer open method. Perhaps that should be called 
from getLayerByName or getLayer. It's not possible to do that with the layer 
constructor since the connection and data elements would not have values. In 
that case the layer must be explicitly opened.

comment:3 by refractions, 23 years ago

Here is the complete script. I do a getLayer to retrieve the layer object.

use mapscript;
my $map = new mapObj("/home/pramsey/arcims_proxy/imsbin/demo.map");
my $pt = new pointObj();
$pt->{x} = 900000;
$pt->{y} = 900000;
my $lyr = $map->getLayer(0);
print $lyr,"\n";
print $lyr->{metadata},"\n";
my $rv = $lyr->queryByPoint($map,$pt,$mapscript::MS_SINGLE,10.0);
die "Query failed" if $rv != $mapscript::MS_SUCCESS;
print $rv,"\n";
my $rsltcache = $lyr->{resultcache};
my $bds = $rsltcache->{bounds};
print "(" . $bds->{minx} . "," . $bds->{miny} . ") ";
print "(" . $bds->{maxx} . "," . $bds->{maxy} . ")\n";
my $numrslt = $rsltcache->{numresults};
my $rslt = $lyr->getResult(0);
print $rslt->{shapeindex},"\n";
print $rslt->{tileindex},"\n";
my $shp = new shapeObj($mapscript::MS_SHAPE_POLYGON);
$rv = $lyr->getShape($shp,$rslt->{tileindex},$rslt->{shapeindex});

comment:4 by sdlime, 21 years ago

This is still an error in 3.6.5, at least it was earlier in the week. I did
change the way shapefiles are handled to be more like PostGIS, SDE and so on.
That may have fixed the problem. Need to test under 3.7/4.0 to confirm that it's
still an issue.

Steve

comment:5 by sdlime, 21 years ago

Resolution: fixed
Status: assignedclosed
It's fixed in the 3.7/4.0 CVS. Here's a test script in perl. Comment out opening
the layer and the script fails as expected without a core dump.

Steve

#!/usr/bin/perl

use mapscript;

$map = new mapscript::mapObj('test.map');
die "Unable to open mapfile." unless $map;

print "Opened mapfile.\n";

$layer = $map->getLayerByName('city');
die "Unable to retrieve layer." unless $layer;

print "Retrived layer 'city'.\n";

$status = $layer->open();
die "Unable to open layer." unless $status == mapscript::MS_SUCCESS;

print "Open layer 'city'.\n";

$shape = new mapscript::shapeObj(-1);

$status = $layer->getShape($shape, -1, 0);
die "Unable to retrieve first shape." unless $status == mapscript::MS_SUCCESS;

print "Got first shape.\n";

$layer->close();
Note: See TracTickets for help on using tickets.