MapScript C# Memory Corruption Problem (MapServer 4.10)

Tamas Szekeres szekerest at GMAIL.COM
Sat Jan 20 11:16:38 PST 2007


Hi Hong,

I've looked into the code, but I've no option to set up an SDE test
environmment to test it though.
I consider the SDE driver is thread unsafe even if the USE_THEAD
switch was definied during the compilation.
Therefore I would discourage to retain the mapObj reference between
the subsequent requests, especially when there are existing open
connections to the database. The subsequent requests might be handled
by different threads with the ASP.NET applications.


Here are my further questions you should check before proceeding with the issue:

1. Make sure mapserver was compiled with USE_THEAD enabled. (Use
mapserv -v to check)
2. Try not to keep the mapscript objects between the requests.
Instead, you should reload the map object every time and set the
required properties one by one.
3. It would be desirable if the mapscript/mapserver related dll-s was
using the same CRT library. You should use a suitable utility (like
the Visual Studio Depends tool) to check the CRT dependency of the
libraries. Heap corruption may arise when memory segments are passed
between libraries using different CRT heaps.
4. For the ASP.NET + VS80 builds the manifest containing the CRT
dependency should always be embedded as a resource into mapscript.dll
as described at
http://mapserver.gis.umn.edu/docs/howto/mapscriptcscompile.


Best Regards,

Tamas



2007/1/20, Hong <ljfong at sdf.lonestar.org>:
> Hi Tamas,
>
> I have created a skeleton application that can show the map and the user can
> "refresh", "zoom in", or "zoom out" on the map. The map draws without problem
> on "refresh", but it will crash with either the memory corruption message or
> the SDE connection exception randomly. Typically the crash occurs after the
> 3rd or 4th call to zoomPoint() followed by draw() subroutine. The SDE
> connection exception is:
>
> msDrawMap(): Image handling error. Failed to draw layer named 'District';
> msSDELayerOpen(): SDE error. SE_Version_get_info(): Bad connection handle.
> (-92)
>
> All the layers in the map file are SDE layers accessed using ArcSDE 9.1
> libraries.
>
> I am sure that the correct versions of the dlls are loaded as the problem
> disappears after I switch back to the old 4.8.4 dlls. I also verified the
> dependencies using dependency walker to show the paths.
>
> As for the call stack, this is what I got after the protected memory error:
>
> [AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.]
>    System.Diagnostics.StackTrace.GetStackFramesInternal(StackFrameHelper sfh, Int32 iSkip, Exception e) +0
>    System.Diagnostics.StackTrace.CaptureStackTrace(Int32 iSkip, Boolean fNeedFileInfo, Thread targetThread, Exception e) +49
>    System.Diagnostics.StackTrace..ctor(Exception e, Boolean fNeedFileInfo) +32
>    System.Web.UnhandledErrorFormatter.get_ColoredSquare2Content() +579
>    System.Web.UnhandledErrorFormatter.PrepareFormatter() +42
>    System.Web.ErrorFormatter.GetHtmlErrorMessage(Boolean dontShowSensitiveInfo) +51
>    System.Web.HttpResponse.WriteErrorMessage(Exception e, Boolean dontShowSensitiveErrors) +787
>    System.Web.HttpResponse.ReportRuntimeError(Exception e, Boolean canThrow, Boolean localExecute) +478
>    System.Web.HttpRuntime.FinishRequest(HttpWorkerRequest wr, HttpContext context, Exception e) +541
>
>
> I am sending testpage.aspx, testpage.aspx.vb for the sample app and Odessa.map
> for the mapfile I used directly to your email account.
>
> Thanks.
>
> Hong
>
>
> On Fri, Jan 19, 2007 at 10:34:06AM +0100, Tamas Szekeres wrote:
> > Could you provide the code sample and possibly a call stack to locate
> > this error?
> > Are you sure that the correct versions of the dll-s are loaded?
> >
> > Best Regards,
> >
> > Tamas Szekeres
> >
> >
> > 2007/1/19, Hong <ljfong at sdf.lonestar.org>:
> > >Hi,
> > >
> > >I recently tried building MapServer 4.10 from the build kit
> > >(mapserver-buildkit-011607.zip) using MS Visual Studio 2005 SP1. The build
> > >was
> > >successful but during regular operation, there would be memory corruption
> > >that
> > >happened sporadically (randomly when calling draw() function of mapObj).
> > >The
> > >message was:
> > >
> > >Attempted to read or write protected memory. This is often an indication
> > >that
> > >other memory is corrupt.
> > >
> > >The following DLLs were produced and used:
> > >- bgd.dll (from separately downloaded gdwin32 package)
> > >- libmap.dll (with manifest attached through 'mt')
> > >- mapscript.dll (with manifest attached through 'mt')
> > >- mapscript_csharp.dll
> > >
> > >This problem did not happen with MapServer 4.8.4 buildkit
> > >(mapserver-4.8.3-msvc71-build-kit.zip) built using MS Visual Studio 2003.
> > >The
> > >4.8.4 binaries had been running in .NET 2.0 environment without any
> > >problem.
> > >
> > >I can use any suggestion/help here.
> > >
> > >Thanks.
> > >
> > >Surya
> > >
>



More information about the MapServer-users mailing list