[mapserver] Java VM Crashes using the Mapscript API

Fernando Simon fsimon at UNIVALI.BR
Thu Jul 28 12:59:20 PDT 2005


Hi Sean,
    Thanks for your reply, I will check my code to improve it with
your hints. The blank backgound appear when I define a labelobject by
hand using JavaMapscript and set the it (setLabel) to my class.
    If I save the "mapscript mapfile" the label appear with a black
definition for background. I solve this problem using the way that I
wrote in the last e-mail. Any hints why occur this black backgound?
     Thanks.

Fernando Simon

Citando Sean Gillies <sgillies at FRII.COM>:

> Fernando,
> 
> This is improper usage and will result in memory leaks. An instance
> of 
> labelObj already holds references to many allocated colorObjs, and
> if 
> you bind new instances to the labelObj the originals will not be
> freed. 
> An example of proper usage is
> 
>      label.color.setRGB(0, 0, 0);
> 
> All colors should be undefined (-1,-1,-1) by default, so I am at a
> loss 
> how you get a black label background.
> 
> Sean
> 
> On Jul 28, 2005, at 1:27 PM, Fernando Simon wrote:
> 
> > Hi all,
> >     I found the same problem with black blackground here some
> weeks
> > ago, I solved the problem when I defined a blank color objects
> for
> > backgoundcolor and backgoundshadowcolor. Like:
> >             lObjCor = new colorObj(-1, -1, -1, 0);
> >             lObjLabel.setBackgroundcolor(lObjCor);
> >             lObjLabel.setBackgroundshadowcolor(lObjCor);
> >      So, using this way I can define all my layer using
> JavaMapscript.
> > To check the "mapscript mapfile" you can save it to see all the
> > definitions.
> >      Thanks.
> >
> >
> > Fernando Simon
> >
> >
> > Citando Rick Innis <rick at INNIS.CA>:
> >
> >> Im revisiting this somewhat old thread to contribute a few
> insights
> >>
> >> I've found while dealing with the same issue, in the hope it
> saves
> >>
> >> someone else time and effort in the future. The thread
> "Mapscript
> >>
> >> API: for object manipulation, not object creation?" , from
> earlier
> >>
> >> this year, also has some info on this topic.
> >>
> >>>>
> >>>> Christian reported a crash in layerObj.delete() which I
> >>>> also detected.
> >>>> I think I understood the following:
> >>>>
> >>>> Let's say, we have an initialized  mapObj mO;
> >>>>
> >>>> layerObj lO = new layerObj(mO);
> >>>> // Say lO is the 5th layer now.
> >>>> // Now lO.swigCMemOwn == true and
> >>>> //     lO.swigCPtr points onto the mO.swigCPtr->layers[4]
> >>>>
> >>>> ...
> >>>> // now the mapObj is deleted but the Java-layerObj continues
> to
> >> live.
> >>>> // the C-layer-Object mO.swigCPtr->layers[4] will deleted and
> >>>> freed also!
> >>>> mO.delete()
> >>>> // From now on O.swigCPtr points into invalid piece of
> >> C-memory.
> >>>> ...
> >>
> >> I also encountered this a few months back but didn't have time
> to
> >>
> >> write it up so coherently. One workaround I was given by Sean
> was
> >> to
> >> use insertLayer() to add the layer, which makes a copy,
> allowing
> >> the
> >> allocated Java object to be disposed of cleanly. This also
> requires
> >>
> >> making and inserting styleObj and classObj instances:
> >>
> >>                  // initially, layer not associated with any
> map
> >>                  layerObj myLayer = new layerObj(null);
> >>                  // initialise layer
> >>                  classObj myClass = new classObj(null);
> >>                  styleObj myStyle  = new styleObj(null);
> >>                  // initialize style, then insert into class
> >>                  myClass.insertStyle(styleObj, -1);
> >>                  // insert class into layer
> >>                  myLayer.insertClass(myClass, -1);
> >>                  // insert layer into map - makes copy!
> >>                  int ret = map.insertLayer(annos, -1);
> >>                  // get reference to inserted copy
> >>                  myLayer = map.getLayer(i);
> >>
> >>
> >> However, when  I started labelling my dynamic layers I found
> that
> >> my
> >> labels ended up with a black background.  The workaround I
> found
> >> was
> >> to define an empty layer in my map, including empty style info,
> and
> >>
> >> use cloneLayer() to make copies as needed.
> >>
> >> The layer definition looks like this:
> >>
> >>          # Blank generic annotation layer
> >>          LAYER
> >>                  NAME user_layer
> >>                  STATUS OFF
> >>                  TYPE POINT
> >>                  CLASS
> >>                      STYLE
> >>                          COLOR 255 255 255
> >>                      END
> >>                      LABEL
> >>                          COLOR 255 255 255
> >>                      END
> >>                  END
> >>          END
> >>
> >> To use it, I grab the layer from the map, clone it, initialize
> it,
> >>
> >> and insert the clone into the map:
> >>
> >>                  layerObj myLayer = map.getLayerByName
> >> ("blank_layer").cloneLayer();
> >>                  // initialise...
> >>                  int ret = map.insertLayer(annos, -1);
> >>
> >> The layer's type can be changed on the fly, so one definition
> >> suffices for all layers.
> >>
> >>      --Rick.
> >>
> >
> >
> >
> >
> > -------------------------------------------------
> >   Univali - Webmail - http://webmail.univali.br
> >
> >
> --
> Sean Gillies
> sgillies at frii dot com
> http://zcologia.com
> 




-------------------------------------------------
  Univali - Webmail - http://webmail.univali.br



More information about the MapServer-users mailing list