[mapserver] Java VM Crashes using the Mapscript API

Sean Gillies sgillies at FRII.COM
Fri Jul 29 09:02:28 PDT 2005


Fernando,

A new layerObj instance is complete, except that 1) it contains no 
child classObjs, 2) it might need to be added to a map. Same situation 
for new instances of classObj: they are also complete except that they 
contain no child styleObjs.

classObj.getLabel() returns a reference to the classObj's label 
attribute. It is not a copy.

There is no need to delete any object that you have not explicitly 
created. getLabel() returns a reference to an object owned by the 
classObj. There is no need to delete the reference returned by 
getLabel().

Sean

On Jul 29, 2005, at 9:20 AM, Fernando Simon wrote:

> Sean,
>     Thanks for your reply.
>     Now, after your hints, I have some doubts, using SWIG (Java
> support) if I do this code: lObjLabel = lObjClass.getLabel(); And
> after I change some attributes for the lObjLabel,  these changes will
> affect the lObjClass.label? Is it the same objects, lObjLabel
> reference the same that lObjClass.getLabel(), or is a new copy? After
> I change the attributes I need to do a setLabel?
>     The other doubt is about the delete() function for the objects. If
> I call this function the objects (in JavaSwig) will be release or
> clean the objects? In the lObjLabel, this function will be clean the
> lObjClass.label?
>     The last doubt :) what is the objects that exist by default when I
> create a new class object or layer object?
>     Thanks
>
> Fernando Simon
>
> Citando Sean Gillies <sgillies at frii.com>:
>
>> Now I understand. You should never bind a new labelObj to a
>> classObj.
>> All the MapServer classes exist primarily to support the CGI
>> mapserv
>> program, and therefore are complete. An new instance of classObj,
>> for
>> example, already contains a labelObj attribute named "label". To
>> set a
>> class's label color, you should do this
>>
>>      class.label.color.setRGB(red, green, blue)
>>
>> Sean
>>
>> On Jul 28, 2005, at 1:59 PM, Fernando Simon wrote:
>>
>>> 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
>>>
>>
>>
>
>
>
>
> -------------------------------------------------
>   Univali - Webmail - http://webmail.univali.br
>



More information about the MapServer-users mailing list