Note: if you just want to change a texture at runtime in code then you don’t need to write it to a file to do it. You can, but you don’t need to.
Else make sure you use the same key to load the texture as you did to clear it from the cache. loadTexture(string) builds a texture key internally that may not match the one you created manually. Better to create them the same.
If you load via a FileLocator, you can modify the file via the normal java api.
If you load via classpath locator, this behaviour is not supported in any way, and will not work with a distributed game anyway.
I’m still curious what you are actually doing in game terms… because if you think the only way to update a texture at runtime is to write a file then know that there are better ways… and that’s almost the slowest possible way imaginable.
Usually, even if you needed to save the texture for later (extremely rare since generally textures are generated from game data) then you’d update the texture and THEN (occasionally) write it back to the disk.
So, repeating, if your game process is currently like:
-game modifies image
-game saves image
-game loads texture
…so user can see texture.
Then know that the only slower way to do that would be to upload it to FTP in the process.
Lol, yes I get you. The saving to disk part is for terrain alphamaps that are generated based on procedurally generated terrain. I save it to disk because I am inside the “Editing” zone in my game, not indented for players.
Now, ingame there will be terrain modification and terrain painting but for that I will save to disk only when player leaves a planet. For multiplayer, I will send alphamap / terrain changes by TCP as they happen but only if a player is on a planet where another user is making modifications.
Yeah, but if it’s the same code generating the alpha map that’s loading the texture then it should be:
generate image → update texture → save image…
generate image → write to disk → clear cache → reload texture
In the first case, you never have to worry about the cache and you can also decide to save later.
One more thing, I get following buffer error if I don’t wait long enough before saving to disk. How can I make it so that the buffer error does not happen ?
Jan 17, 2016 6:40:44 PM com.jme3.app.Application handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]