Problems w/ MapScript C#

Mike Saunt mikesaunt at GMAIL.COM
Mon Apr 4 11:09:22 EDT 2005


Sean

I replied to Ian last night but had hit reply and not reply all hence
it hadn't come on to the list.  I had a similar problem on a different
project with the .NET GDI+ locking the image file and the following
resolved it.

public System.Drawing.Image MapRefresh(int mapHeight, int mapWidth)
{
       if (map == null)
       {
               return null;
       }
       map.height = mapHeight;
       map.width = mapWidth;
       MapScriptDotNet.imageObj img = map.draw();

       string sMapImage = @"C:\windows\temp\map.png";
       img.save(sMapImage,map);

       //we need to load via a memory stream as the GDI+ locks the image
       System.IO.FileStream fs = new System.IO.FileStream(sMapImage,
FileMode.Open,  FileAccess.Read, FileShare.Read);
       System.Drawing.Image mapImage = System.Drawing.Image.FromStream(fs);
       fs.Close();
       fs = null;
       File.Delete(sMapImage);
       return mapImage;

}

Hope this helps

Cheers
Mike Saunt


On Apr 4, 2005 4:03 PM, Sean Gillies <sgillies at frii.com> wrote:
> On Apr 3, 2005, at 9:49 PM, Ian Erickson wrote:
>
> > I've successfully built the C# Mapscript assembly, and have
> > successfully
> > written code that generates an image file to disk.  Everything seems to
> > work just fine until I make repeated calls to the map.draw() function.
> > I get the following exception after 3 or 4 calls to the private member
> > function drawMapImage():
> >
> > System.NullReferenceException: Object reference not set to an instance
> > of an object.
> >    at mapscriptPINVOKE.mapObj_draw(IntPtr jarg1)
> >    at mapObj.draw()
> >    at SimpleMap.Form1.drawMapImage()
> >
>
> [snip]
>
> Ian,
>
> When you say "repeated calls", do you mean that these are sequential or
> concurrent?
>
> I (with no other info) interpret the exception to be saying that
> "jarg1" is Null.  As far as I can tell from the C# mapscript_wrap.c
> file this is a reference to the mapObj.  Are you destroying your mapObj
> instance in the middle of your calls to drawMapImage()?
>
> Sean
>
> --
> Sean Gillies
> sgillies at frii dot com
> http://users.frii.com/sgillies
>



More information about the mapserver-users mailing list