Quantcast

Problems using SHPDestroyObject()

classic Classic list List threaded Threaded
4 messages Options
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Problems using SHPDestroyObject()

Mario Härtwig
Hi all,
I am trying to write an intersection-tool with Delphi using ShapeLib 1.2.10. Everything works proper with small shapes but when I try to intersect bigger shapes, after some time an access-violation message occurs when I try to read a shape using the SHPReadObject()-method.
Possibly the problem is that I am not using SHPDestroyObject(). It causes an error-message the first time I access it.

The following code works fine:
      pSHPStr := SHPReadObject(hSHPHandleStr,i);
      SHPDestroyObject(pSHPStr);

This code causes an cpu-error-message in my Delphi IDE:
      pSHPStr := SHPReadObject(hSHPHandleStr,i);
      aXIn := pSHPStr.padfX; //Array of nVertices X coordinates;
      aYIn := pSHPStr.padfY; //Array of nVertices Y coordinates;
      SHPDestroyObject(pSHPStr);

Do you have any ideas what the problem could be? Thanks a lot!
Mario Härtwig

_______________________________________________
Shapelib mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/shapelib
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems using SHPDestroyObject()

Brian Peschel

> Hi all,
> I am trying to write an intersection-tool with Delphi using ShapeLib 1.2.10.
> Everything works proper with small shapes but when I try to intersect bigger
> shapes, after some time an access-violation message occurs when I try to
> read a shape using the SHPReadObject()-method.
> Possibly the problem is that I am not using SHPDestroyObject(). It causes an
> error-message the first time I access it.
>
> The following code works fine:
>        pSHPStr := SHPReadObject(hSHPHandleStr,i);
>        SHPDestroyObject(pSHPStr);
>
> This code causes an cpu-error-message in my Delphi IDE:
>        pSHPStr := SHPReadObject(hSHPHandleStr,i);
>        aXIn := pSHPStr.padfX; //Array of nVertices X coordinates;
>        aYIn := pSHPStr.padfY; //Array of nVertices Y coordinates;
>        SHPDestroyObject(pSHPStr);
>
> Do you have any ideas what the problem could be? Thanks a lot!
> Mario H?
padfX and padFY are pointers into the pSHPStr object.  Once you call
SHPDestroyObject(), aXIn and aYIn are no longer valid.  Instead you want
to do something like

for (int i = 0; i < size, i++
{
     pSHPStr := SHPReadObject(hSHPHandleStr,i);
     aXIn := pSHPStr.padfX; //Array of nVertices X coordinates;
     aYIn := pSHPStr.padfY; //Array of nVertices Y coordinates; < use
aXIn, aYIn >
     SHPDestroyObject(pSHPStr);
}

- Brian
_______________________________________________
Shapelib mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/shapelib
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems using SHPDestroyObject()

Mario Härtwig
Hi,
thanks for your help, Brian. I have tried this but there's still the CPU error message in my IDE when I try to use SHPDestroyObject(). The message does not appear when I try to access padfX or padfY but when I call SHPDestroyObject().

Screenshot of the error message:
http://img221.imageshack.us/img221/3159/cpuu.jpg

Mario Haertwig

_______________________________________________
Shapelib mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/shapelib
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate

Re: Problems using SHPDestroyObject()

Vassilis Perantzakis

padfX and padfY are pointers to double as pointed out, but Brian forgot to put the * sign after the := sign.

 

They are declared in shapefil.h as:

   double          *padfX;

    double         *padfY;

 

That means you copy the object memory when you assign them to aXIn and aYIn, not their values. The call to SHPDestroyObject then has a problem with that.

 

The correct syntax should be:

     aXIn := *pSHPStr.padfX; //Array of nVertices X coordinates;

     aYIn := *pSHPStr.padfY; //Array of nVertices Y coordinates;

 

Tell us  if it helped

 

From: [hidden email] [mailto:[hidden email]] On Behalf Of Mario Haertwig
Sent: Friday, November 26, 2010 12:29 PM
To: Shapelib Development
Subject: Re: [Shapelib] Problems using SHPDestroyObject()

 

Hi,
thanks for your help, Brian. I have tried this but there's still the CPU error message in my IDE when I try to use SHPDestroyObject(). The message does not appear when I try to access padfX or padfY but when I call SHPDestroyObject().

Screenshot of the error message:
http://img221.imageshack.us/img221/3159/cpuu.jpg

Mario Haertwig


_______________________________________________
Shapelib mailing list
[hidden email]
http://lists.maptools.org/mailman/listinfo/shapelib
Loading...