Desperate Need Of Help "Attempted To Read Or Write Protected Memory"

H

humbleaptience

I have a web application that uses a DLL using DLLImport.

Twice I have put the application live on the net and it has been used
hundreds or thousands of time before it has been strangely brought
down.

System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt. at
ProjApi.Proj.pj_init_plus(String pjstr) at coordinate.LLtoUTM(Int32
datumIn, Int32 datumOut, Double p_lat, Double p_lon, Double&
UTMNorthing, Double& UTMEasting, Int32& UTMZone) at
coordinate.LLtoUTMZone(Double lat, Double lon, Int32 datumIn, Int32
datumOut, Int32& z, Double& n, Double& e) at
getfactory.Page_Load(Object sender, EventArgs e) at
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t, EventArgs e) at
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Here is my code that calls the extern method

public static int LLtoUTM(int datumIn, int datumOut, double p_lat,
double p_lon,ref double UTMNorthing,ref double UTMEasting,ref int
UTMZone)
{
int errno = 0;
//This is the formula for calculating which Zone a point is in at a
particular lat/long
int ZoneNumber = Convert.ToInt32(Math.Floor((p_lon + 180) / 6)) + 1;
double[] x = new double[1];
double[] y = new double[1];
double[] z = new double[1];
y[0] = p_lat * ProjApi.Proj.DEG_TO_RAD;
x[0] = p_lon * ProjApi.Proj.DEG_TO_RAD;
z[0] = 0.0;
IntPtr src0 = ProjApi.Proj.pj_init_plus("+proj=latlong
+datum=NAD27");
IntPtr src1 = ProjApi.Proj.pj_init_plus("+proj=latlong
+datum=NAD83");
IntPtr dst0 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
+ ZoneNumber + " +datum=NAD27");
IntPtr dst1 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
+ ZoneNumber + " +datum=NAD83");
//This nice little bit of code below is designed to execute
pj_transfrom (the proj lib all around function)
//with the correct parameters so that a datumshift to the correct
datum is included.
try
{
if (datumIn == 0)
{
if (datumOut == 0)
{
errno = ProjApi.Proj.pj_transform(src0, dst0,
1, 1, x, y, z);//NAD27-NAD83
}
else
{
errno = ProjApi.Proj.pj_transform(src0, dst1,
1, 1, x, y, z);//NAD27-NAD27
}
}
else
{
if (datumOut == 0)
{
errno = ProjApi.Proj.pj_transform(src1, dst0,
1, 1, x, y, z);//NAD83-NAD27
}
else
{
errno = ProjApi.Proj.pj_transform(src1, dst1,
1, 1, x, y, z);//NAD83-NAD83
}
}
}
catch { }

ProjApi.Proj.pj_free(dst1);
ProjApi.Proj.pj_free(src1);
ProjApi.Proj.pj_free(dst0);
ProjApi.Proj.pj_free(src0);
UTMNorthing = y[0];
UTMEasting = x[0];
UTMZone = ZoneNumber;
return errno;
}


Here is the definition and DLL import.
[DllImport("proj.dll", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int pj_transform(IntPtr src, IntPtr
dst,
int point_count, int point_offset,
[InAttribute, OutAttribute] double[] x,
[InAttribute, OutAttribute] double[] y,
[InAttribute, OutAttribute] double[] z);

Any help at all would be useful. I am not able to trigger this error
myself so I can't even do trial and error.
 
W

Winista

Did you develop unmanaged proj.dll? Do you source for that DLL?
That code seems to be causing some meory overwrite.

humbleaptience said:
I have a web application that uses a DLL using DLLImport.

Twice I have put the application live on the net and it has been used
hundreds or thousands of time before it has been strangely brought
down.

System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt. at
ProjApi.Proj.pj_init_plus(String pjstr) at coordinate.LLtoUTM(Int32
datumIn, Int32 datumOut, Double p_lat, Double p_lon, Double&
UTMNorthing, Double& UTMEasting, Int32& UTMZone) at
coordinate.LLtoUTMZone(Double lat, Double lon, Int32 datumIn, Int32
datumOut, Int32& z, Double& n, Double& e) at
getfactory.Page_Load(Object sender, EventArgs e) at
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t, EventArgs e) at
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Here is my code that calls the extern method

public static int LLtoUTM(int datumIn, int datumOut, double p_lat,
double p_lon,ref double UTMNorthing,ref double UTMEasting,ref int
UTMZone)
{
int errno = 0;
//This is the formula for calculating which Zone a point is in at a
particular lat/long
int ZoneNumber = Convert.ToInt32(Math.Floor((p_lon + 180) / 6)) + 1;
double[] x = new double[1];
double[] y = new double[1];
double[] z = new double[1];
y[0] = p_lat * ProjApi.Proj.DEG_TO_RAD;
x[0] = p_lon * ProjApi.Proj.DEG_TO_RAD;
z[0] = 0.0;
IntPtr src0 = ProjApi.Proj.pj_init_plus("+proj=latlong
+datum=NAD27");
IntPtr src1 = ProjApi.Proj.pj_init_plus("+proj=latlong
+datum=NAD83");
IntPtr dst0 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
+ ZoneNumber + " +datum=NAD27");
IntPtr dst1 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
+ ZoneNumber + " +datum=NAD83");
//This nice little bit of code below is designed to execute
pj_transfrom (the proj lib all around function)
//with the correct parameters so that a datumshift to the correct
datum is included.
try
{
if (datumIn == 0)
{
if (datumOut == 0)
{
errno = ProjApi.Proj.pj_transform(src0, dst0,
1, 1, x, y, z);//NAD27-NAD83
}
else
{
errno = ProjApi.Proj.pj_transform(src0, dst1,
1, 1, x, y, z);//NAD27-NAD27
}
}
else
{
if (datumOut == 0)
{
errno = ProjApi.Proj.pj_transform(src1, dst0,
1, 1, x, y, z);//NAD83-NAD27
}
else
{
errno = ProjApi.Proj.pj_transform(src1, dst1,
1, 1, x, y, z);//NAD83-NAD83
}
}
}
catch { }

ProjApi.Proj.pj_free(dst1);
ProjApi.Proj.pj_free(src1);
ProjApi.Proj.pj_free(dst0);
ProjApi.Proj.pj_free(src0);
UTMNorthing = y[0];
UTMEasting = x[0];
UTMZone = ZoneNumber;
return errno;
}


Here is the definition and DLL import.
[DllImport("proj.dll", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int pj_transform(IntPtr src, IntPtr
dst,
int point_count, int point_offset,
[InAttribute, OutAttribute] double[] x,
[InAttribute, OutAttribute] double[] y,
[InAttribute, OutAttribute] double[] z);

Any help at all would be useful. I am not able to trigger this error
myself so I can't even do trial and error.
 
H

humbleaptience

No however the DLL is used to do these same operations thousands of
time and has been around for years and there has been no mention of any
problem like this on their mailing list. We have been using this
EXACT same dll on our web site to do reprojections (classic ASP) for
years hundreds of thousands of times a day.
Did you develop unmanaged proj.dll? Do you source for that DLL?
That code seems to be causing some meory overwrite.

humbleaptience said:
I have a web application that uses a DLL using DLLImport.

Twice I have put the application live on the net and it has been used
hundreds or thousands of time before it has been strangely brought
down.

System.AccessViolationException: Attempted to read or write protected
memory. This is often an indication that other memory is corrupt. at
ProjApi.Proj.pj_init_plus(String pjstr) at coordinate.LLtoUTM(Int32
datumIn, Int32 datumOut, Double p_lat, Double p_lon, Double&
UTMNorthing, Double& UTMEasting, Int32& UTMZone) at
coordinate.LLtoUTMZone(Double lat, Double lon, Int32 datumIn, Int32
datumOut, Int32& z, Double& n, Double& e) at
getfactory.Page_Load(Object sender, EventArgs e) at
System.Web.Util.CalliHelper.EventArgFunctionCaller(IntPtr fp, Object o,
Object t, EventArgs e) at
System.Web.Util.CalliEventHandlerDelegateProxy.Callback(Object sender,
EventArgs e) at System.Web.UI.Control.OnLoad(EventArgs e) at
System.Web.UI.Control.LoadRecursive() at
System.Web.UI.Page.ProcessRequestMain(Boolean
includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint)

Here is my code that calls the extern method

public static int LLtoUTM(int datumIn, int datumOut, double p_lat,
double p_lon,ref double UTMNorthing,ref double UTMEasting,ref int
UTMZone)
{
int errno = 0;
//This is the formula for calculating which Zone a point is in at a
particular lat/long
int ZoneNumber = Convert.ToInt32(Math.Floor((p_lon + 180) / 6)) + 1;
double[] x = new double[1];
double[] y = new double[1];
double[] z = new double[1];
y[0] = p_lat * ProjApi.Proj.DEG_TO_RAD;
x[0] = p_lon * ProjApi.Proj.DEG_TO_RAD;
z[0] = 0.0;
IntPtr src0 = ProjApi.Proj.pj_init_plus("+proj=latlong
+datum=NAD27");
IntPtr src1 = ProjApi.Proj.pj_init_plus("+proj=latlong
+datum=NAD83");
IntPtr dst0 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
+ ZoneNumber + " +datum=NAD27");
IntPtr dst1 = ProjApi.Proj.pj_init_plus("+proj=utm +zone="
+ ZoneNumber + " +datum=NAD83");
//This nice little bit of code below is designed to execute
pj_transfrom (the proj lib all around function)
//with the correct parameters so that a datumshift to the correct
datum is included.
try
{
if (datumIn == 0)
{
if (datumOut == 0)
{
errno = ProjApi.Proj.pj_transform(src0, dst0,
1, 1, x, y, z);//NAD27-NAD83
}
else
{
errno = ProjApi.Proj.pj_transform(src0, dst1,
1, 1, x, y, z);//NAD27-NAD27
}
}
else
{
if (datumOut == 0)
{
errno = ProjApi.Proj.pj_transform(src1, dst0,
1, 1, x, y, z);//NAD83-NAD27
}
else
{
errno = ProjApi.Proj.pj_transform(src1, dst1,
1, 1, x, y, z);//NAD83-NAD83
}
}
}
catch { }

ProjApi.Proj.pj_free(dst1);
ProjApi.Proj.pj_free(src1);
ProjApi.Proj.pj_free(dst0);
ProjApi.Proj.pj_free(src0);
UTMNorthing = y[0];
UTMEasting = x[0];
UTMZone = ZoneNumber;
return errno;
}


Here is the definition and DLL import.
[DllImport("proj.dll", CharSet = CharSet.Ansi,
CallingConvention = CallingConvention.Cdecl)]
public static extern unsafe int pj_transform(IntPtr src, IntPtr
dst,
int point_count, int point_offset,
[InAttribute, OutAttribute] double[] x,
[InAttribute, OutAttribute] double[] y,
[InAttribute, OutAttribute] double[] z);

Any help at all would be useful. I am not able to trigger this error
myself so I can't even do trial and error.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,756
Messages
2,569,535
Members
45,007
Latest member
OrderFitnessKetoCapsules

Latest Threads

Top