Thanks. That one was tricky. It turned out that the PhongFilter was modifying several arrays during filter processing, and since arrays are copied by reference instead of being cloned too during the cloning process, all clones of PhongFilter were modifying the same original arrays, thereby overwriting the values for one another.
Yes it does. That makes sense (or as much sense as my tired head can make of it). Data race I guess is one way of putting it?
I resolved the issue by modifying the clone() method of PhongFilter so it also clones all arrays that are created when the original PhongFilter instance is first created. Now each instance is separated properly:
public Object clone() throws CloneNotSupportedException {
PhongFilter clone = (PhongFilter)super.clone();
clone.ambient = ambient.clone();
clone.diffuse = diffuse.clone();
clone.specular = specular.clone();
clone.light = light.clone();
clone.ambientRGB = ambientRGB.clone();
clone.diffuseRGB = diffuseRGB.clone();
clone.specularRGB = specularRGB.clone();
clone.lightRGB = lightRGB.clone();
clone.colour = colour.clone();
return clone;
}
This solves the problem! Did you modify any of the other filters?
Arrays that are read-only don't need to be cloned, but I didn't want to spend time figuring out which ones are read-only so I cloned all as you can see.
I totally agree that that's the better way to go about it. In fact I couldn't even answer that for you myself (edit: at least without looking at the code for a bit but why bother when it's easiest to do it on all the arrays?).
I'm attaching my updated version of your skin here. The speed gain between jAlbum 22 and jAlbum 24.1.1 for building the Sample Portfolio project is huge: From 17s to 10s.
If you have other filters that modify the contents of arrays that are created on object creation, then they need also be cloned like this IF you're implementing the Cloneable interface. If you rely on the JavaBean cloning, then such arrays gets instantiated as a new filter instance is created.
All seems good - except for the strange combination of three of the filters making the image completely black. But that's I guess to be expected with what the filters do.
Thank you very much! This also solves the problem of slow processing and running out of memory - which makes sense.
Now the one obvious question that remains: do I mark the skin as needing the new jAlbum version or can I keep it as 17?
Have a good night!
Edit: I checked that you didn't modify any other filters (diff) so my sole question remaining is the one on jAlbum version for the skin. Thank you again.
Edited by: xexyl on 21 Jul 2021, 13:22