I’ve been messing with the same bug for 4 hours now with no results whatsoever. Here’s the problem:
I have a weapon class. Each weapon type has a specific number of parts that they can have. Each weapon holds it’s parts in the same spot each time (i.e., a Top part will always go to index 3 of the part array, a handle will always be at 2, and so on). On the initialization of a part, I (for debugging) output it’s weapon type and name, which gives me an output of something like “Pistol, Top1” for example. Next, I use these 2 things to load the corresponding model. Next, again for debugging, I output the name of the model to clarify that it’s loading the right model, and it always is. The names always correspond.
I create a new local instance of my own class called WeaponMaterial. It takes 3 textures and uses ImageRasters to color and add them together. This instance of the WeaponMaterial is re-created each time the model is reloaded, and can only be used 1 time before it’s reloaded. Inside this class is the method “build()” which does the following:
First, loads a template to print the new texture onto. Each run, I make sure it’s reset by manually resetting every one of it’s pixels to black.
Next, it loads all of the part’s textures. I output the name and weapon type here as well, and it’s always right too.
Next, I create a local (never references outside the build() method anywhere whatsoever) DefaultImageRaster called “output” that uses the template texture…
After that, I iterate over the Main layer picture first, and colorize the pixels of the output rasterizer, then the secondary and extra.
Finally, I take the output image, add it to a Texture2D, set that texture as the diffuse for a new material (local instance again) and return that material.
So setting the part’s material looks something like:
[java]partModel.setMaterial(partMaterial.build());[/java]
Now, in Nifty I’ve made a GUI where players can change the part model and part color of their weapon. I added flags to the WeaponPart class that specifies whether or not the part needs updating. In Nifty, when the player changes a part it’s set to need an update. Next, (on the same thread as the weapon customization), I check the weapon for out-dated parts, and ONLY update the parts that are marked with needing it.
Here’s the problem: When I update the parts, sometimes it sets the right material to the right part. However, sometimes when I change a part, it applies the generated material to the previously customized weapon part, which doesn’t even need updating and does not output anything. The outputs even read the right model being loaded, the right textures, names, and types, but it’s still applying them to the wrong model. Almost every single variable used in the customization is local and has no access to the rest of the class outside of the method where it’s created. Yet somehow the material finds it’s way to being applied to other models. I don’t see how this is even possible, considering each part’s material is entirely local to it’s class of origin, which I make sure is correct by outputting it’s name and type. Yet still, no matter what I change, it continually happens. I’m beyond lost at this point.
Hopefully I explained it clearly enough. If I didn’t, I’ll probably just put up a download for the code of it. Ask any questions you have, and I’ll answer them as best as I can. I just wanted to see if anyone else could figure this out. Thanks in advance.