[x3d-public] announce: X3DJSail multiple-object MFString/array bugfix

Brutzman, Donald (Don) (CIV) brutzman at nps.edu
Wed Nov 20 17:57:23 PST 2019


Am happy to post that an important/subtle bug was both reported and then diagnosed in X3DJSAIL.

An error in the code generator hid the appropriate generator for MF fields (implemented internally as strongly typed Java lists).  This bug only manifested when multiple copies of the same object were instantiated, resulting in original objects getting inadvertently clobbered.

Many thanks to Laurent Renard for his work on this.  Looks like we have it fixed, for all occurrences of the bug - further testing continues, just to be extra sure.  Exerpted code, output and (with permission) email trail included below.

Update available online, as usual, at

	X3DJSAIL: X3D Java Scene Access Interface Library
	https://www.web3d.org/specifications/java/X3DJSAIL.html

Amusez-vous avec Java et X3D -- have fun with Java and X3D!  8)

========================================
HelloWorldProgram.java
[...]

    /**
      * Testing and debugging
      */
	private static void SpecialTestSection()
	{
         System.out.println("Special test section:");
         
         // thanks to Laurent Renard <laurent.renard at geotoolkit.net> for exposing this bug and sleuthing the correct fix in FontStyleObject initialize() method
         FontStyleObject fontStyle1 = new FontStyleObject();
         FontStyleObject fontStyle2 = new FontStyleObject();
         fontStyle1.setJustify(FontStyleObject.JUSTIFY_BEGIN_MIDDLE);
         fontStyle2.setJustify(FontStyleObject.JUSTIFY_END_MIDDLE);
         System.out.println("justify 1=" + (new MFStringObject(fontStyle1.getJustify())).toString()); // Arrays.toString(fontStyle1.getJustify()));
         System.out.println("justify 2=" + (new MFStringObject(fontStyle2.getJustify())).toString()); // Arrays.toString(fontStyle2.getJustify()));
         // now test to ensure no mutual interference, expected result true:
         System.out.println("justify field independence test pass = " +
             Boolean.toString((new MFStringObject(fontStyle1.getJustify())).toString().equals(FontStyleObject.JUSTIFY_BEGIN_MIDDLE) &&
                              (new MFStringObject(fontStyle2.getJustify())).toString().equals(FontStyleObject.JUSTIFY_END_MIDDLE  )));
         // TODO additional convenience method needed for MFString values, e.g. getJustify(); getJustifyArray(); getJustifyList();
     }

========================================

> SpecialTestSection results:
>
> ===========================================
> Special test section:
> justify 1="BEGIN" "MIDDLE"
> justify 2="END" "MIDDLE"
> justify field independence test pass = true
> ===========================================
>
> as shown in
> https://www.web3d.org/specifications/java/examples/HelloWorldProgramOutputLog.txt

========================================

On 11/12/2019 7:43 AM, Laurent Renard wrote:
> Hi,
> 
> I will try to expose more clearly my issue.
> 
> In  the FontStyleObject you have a static variable for default values.
> For example :
> */public static final ArrayList<String> FAMILY_DEFAULT_VALUE = new ArrayList(Arrays.asList(new String[] { "SERIF" }));/*
> 
> Then in the initialize method the field this.family is set to the default value :
> /* this.family = FAMILY_DEFAULT_VALUE;*/ *//This should be this.family = new ArrayList<String>(FAMILY_DEFAULT_VALUE);*
> 
> Then when you set family on the style object, the field this.family is cleared and fill with the given family.
> But since the initialize method set the field to the existing share instance default value, all the FontStyleObject share the same instance for the family field.
> 
> I have attached a sample code to show you the issue with minimal code with PixelTexture and FontStyleObject.
> 
> I hope this helps and will look at other case where arrays are initialized with static default values.
> 
> *Laurent Renard*
> 
> /INT France //R&D Manager /
> 
> //
> 
> laurent.renard at int.com <mailto:laurent.renard at int.com>
> 
> INT, Inc. - *Empowering Visualization*
> 
> /Celebrate our 30th anniversary with us!
> /
> 
> 
> Le mar. 12 nov. 2019 à 14:41, Brutzman, Donald (Don) (CIV) <brutzman at nps.edu <mailto:brutzman at nps.edu>> a écrit :
> 
>     Thank you very much.  Keep reporting issues please, including code is very valuable.
> 
>     I have tried but not figured out the FontStyle problem yet.  Using Netbeans 11.1 in debug mode is helpful but have still not isolated when/where the bug occurs.  The FontStyleObject member variables are not static and should not be linked together among multiple objects, yet that kind of behavior is occurring.
> 
>     Getting more examples will help.  Whatever the failure mode, it is probably happening identically across the library.  My prior tests did not reveal this problem.
> 
>     Once we figure this out, I plan to turn them into unit tests for comprehensive checking.
> 
>     [...]   Merci de votre aide.
> 
>     On 11/8/2019 3:10 AM, Laurent Renard wrote:
>      > Hi Don,
>      >
>      > I have stopped my developments for a while but I am back on it.
>      > I am using PixelTextureObject and I think there is a bug.
>      > It seems that the image field of the PixelTextureObject is always initialize to the default value. This leads to an issue since all PixelTextureObject share the same image data arraylist.
>      >
>      > Do reproduce the issue, simply export 2 shapes with two different pixel textures. All the pixel textures will share the same image data.
>      >
>      > If you need me to work on this issue I can help.
>      > Regards,
>      > Laurent
>      >
>      > N-B : as before you can share my request with anyone.
>      >
>      > *Laurent Renard*
>      >
>      > /INT France //R&D Manager /

all the best, Don
-- 
Don Brutzman  Naval Postgraduate School, Code USW/Br       brutzman at nps.edu
Watkins 270,  MOVES Institute, Monterey CA 93943-5000 USA   +1.831.656.2149
X3D graphics, virtual worlds, navy robotics http://faculty.nps.edu/brutzman


More information about the x3d-public mailing list