MapScript C# Memory Corruption Problem (MapServer 4.10)

Hong ljfong at SDF.LONESTAR.ORG
Mon Jan 22 10:47:25 PST 2007


On Sat, Jan 20, 2007 at 08:16:38PM +0100, Tamas Szekeres wrote:
> 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)

USE_THREAD is enabled.

MapServer version 4.10.0 OUTPUT=PNG OUTPUT=JPEG OUTPUT=SVG SUPPORTS=FREETYPE
SUPPORTS=THREADS SUPPORTS=POINT_Z_M INPUT=SDE INPUT=SHAPEFILE DEBUG=MSDEBUG

> 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.

Now instead of using the mapObj stored in the session, I perform a clone()
on the mapObj from the session, and use the clone to perform draw(). So far, I
have not seen any crash after doing this. The only problem I observed was that
the symbol transparencies was messed up after subsequent clone + draw. Maybe
the clone is not perfect, I'm not sure.

However, I would still like your opinion on this approach.

> 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.

I have verified them to be using the same CRT library using Visual Studio
dependency tool. They are all using c:\windows\system32\MSVCRT.DLL.

> 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.

These were what I did on the DLLs and EXEs:

mt /manifest mapscript.dll.manifest /outputresource:mapscript.dll
mt /manifest libmap.dll.manifest /outputresource:libmap.dll
mt /manifest mapserv.exe manifest /outputresource:mapserv.exe 

mapserv.exe had c++ runtime loading problem before the manifest was embedded
into it. 

Thanks.

> 
> 
> 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