Material.setDiffuse*Color() : copy or reference?

Is it intention or accident that the Material.setXXXColor(Color3f color) methods don’t copy the color object but store its reference? So you mustn’t re-use the color object after having used one of the method calls…
It took me several debug sessions to detect this irregularity, which isn’t documentated in the Javadoc. :wink:

This is valid for at least:
material.setAmbientColor(color)
material.setDiffuseColor(color)
material.setSpecularColor(color)
material.setEmissiveColor(color)

In other related method calls, Xith3d makes a copy of the color object, for example in:
ColoringAttributes colatt = new ColoringAttributes();
colatt.setColoringAttributes(color);

Btw, the new com.xith3d.utility.geometry.GeometryCreator does use objects by reference, too, but states so, for example in the method documentation it says [quote]Important - all methods in this class copy vecmath objects by reference, so please do NOT reuse them for filling data.
[/quote]
Which is good and important to know. :slight_smile:

What could be the answer to that?
:slight_smile:

From http://xith.org/tutes/xith3d.pdf:

1.1.2 Reduced memory copies

The Xith3D scenegraph rarely copies the contents of objects when the values of a node
are set. In almost all cases where an attribute of a node is set with the value of an object,
the object reference supplied replaces the object reference that the node previously used.
So for example setting the ambient color of a material and passing it a Color3f object
does not copy the values of the object, it just assigns the pointer internally. Conversely,
if you use the method that passes in the floats, the data is copied into the underlying
object. So for example mat.setAmbientColor(float r, float g, float b, float a) will write
the data into the Color4f object inside the material.

[quote]From http://xith.org/tutes/xith3d.pdf:

1.1.2 Reduced memory copies
[/quote]
Thanks for that hint. So it’s intended…
And again I would like to vote to include such important information into the Javadoc of my quoted Xith methods: because it’s the first place to look at usually.

I agree, the Javadoc is sparse at best :slight_smile:

I think it’s one of the areas of Xith3D that needs the most love and caring at the moment…

Terje