X-Git-Url: http://www2.svjatoslav.eu/gitweb/?a=blobdiff_plain;f=src%2Fmain%2Fjava%2Feu%2Fsvjatoslav%2Fsixth%2Fe3d%2Frenderer%2Fraster%2Fshapes%2Fbasic%2FGlowingPoint.java;h=8b37068369d16ef1b4a1c7bedf6f571cdfa409aa;hb=dcdff57f0bab42387b2e4e215778d9e8efc60221;hp=4dd454f8a16a8f3539c90b2745ed3c5516d8a618;hpb=a4176a2e53a8b0475d69091c49529e87bb505c52;p=sixth-3d.git diff --git a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java index 4dd454f..8b37068 100644 --- a/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java +++ b/src/main/java/eu/svjatoslav/sixth/e3d/renderer/raster/shapes/basic/GlowingPoint.java @@ -1,5 +1,5 @@ /* - * Sixth 3D engine. Copyright ©2012-2016, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu + * Sixth 3D engine. Copyright ©2012-2018, Svjatoslav Agejenko, svjatoslav@svjatoslav.eu * * This program is free software; you can redistribute it and/or * modify it under the terms of version 3 of the GNU Lesser General Public License @@ -20,20 +20,26 @@ import java.util.WeakHashMap; public class GlowingPoint extends ForwardOrientedTexture { private static final int TEXTURE_SIZE = 50; - private final Color color; - private static final Set glowingPoints = Collections.newSetFromMap(new WeakHashMap()); + private final Color color; public GlowingPoint(final Point3D point, final double pointSize, final Color color) { super(point, pointSize, getTexture(color)); this.color = color; + + synchronized (glowingPoints) { + glowingPoints.add(this); + } } private static Texture getTexture(final Color color) { // attempt to reuse texture from existing glowing point of the same color - for (GlowingPoint glowingPoint : glowingPoints) - if (color.equals(glowingPoint.color)) return glowingPoint.texture; + synchronized (glowingPoints) { + for (GlowingPoint glowingPoint : glowingPoints) + if (color.equals(glowingPoint.color)) + return glowingPoint.texture; + } // existing texture not found, creating new one return createTexture(color);