Creating new asset during execution

Hi jMonkey community!

We are - some students - using jMonkey for a project at university. This project requires to get images out of a database and load them into the game as textures. At the moment we have a thread which saves the images into the texture folder as files with the title “image” + ID +".png".
This works if we try to load them as textures in the next run, but jMonkey throws “AssetNotFoundException” if we try to load them in the same run those files were created. Do we have to clear a cache or similiar? Would it be a workaround to create for every image an unique folder and add it dynamically to the assets via locator?

You should have one folder you register with the assetmanager and then have subfolders in that so that the images are actually discernable. If you add two folders to the assetmanager root and both contain an “image.jpg” then only one of the two can be loaded as they are both called “image.jpg” for the assetmanager.

So you have to add the one folder to the assetmanager and then have the AssetKey as a full path from that root folder.

this should work are you sure there is not another error? I do this in my model precomiler (loading model converting textures to dds and then loading those instead before resaving)

<cite>@normen said:</cite> You should have one folder you register with the assetmanager and then have subfolders in that so that the images are actually discernable. If you add two folders to the assetmanager root and both contain an "image.jpg" then only one of the two can be loaded as they are both called "image.jpg" for the assetmanager.

So you have to add the one folder to the assetmanager and then have the AssetKey as a full path from that root folder.

We are adding this files to the Assets/Textures folder of our project. Each file name is unique because of the id from our database. They are named like “Image1.png” or “Image2.png”. So this shouldnt be the problem.

<cite>@Empire Phoenix said:</cite> this should work are you sure there is not another error? I do this in my model precomiler (loading model converting textures to dds and then loading those instead before resaving)

Nope, not other exceptions. We have read about an asset-folder-caching by jMonkey, is that true? Because this could be the reason. That caching would be perfomed at start of the game and is maybe never refreshed. If we added new files to our assets folder, jMonkey would not know about them and would throw a exception. As said, if we try to use the created images in a next run after creating them they are loaded properly. This problem only apperas when we try to load an image which was created during the execution.

Quite fast replies here, wow :smiley:

@unrealer2 said: We are adding this files to the Assets/Textures folder of our project. Each file name is unique because of the id from our database. They are named like "Image1.png" or "Image2.png". So this shouldnt be the problem.
What AssetKey (path+name) do you use to load the image? The assets folder isn't existing in a deployed application, it becomes a jar file.
1 Like
<cite>@normen said:</cite> What AssetKey (path+name) do you use to load the image? The assets folder isn't existing in a deployed application, it becomes a jar file.

Oh, that is new to me. It would be no problem for us to use a development version which is running in Eclipse, but somehow ‘unclean’. So we should load this images from a separat folder which is not part of the assets folder and created at runtime?

Here is the simple loading code for textures. It is used in our Entity class, which is thought for one model+texture+shader per instance:

[java]protected final String pathTextures = “Textures/”;

Texture tex = app.getAssetManager().loadTexture(pathTextures + texture + “.” + textureFormat);[/java]

AssetKey should be somewhere internal, do not know. It works fine for all Assets which were inside the assets folder at game startup.

Update:

I can even reproduce it with a model’s texture which is loaded during the game. If i delete “Rose.png”, start the game, put “Rose.png” back, it does not find the asset. But if i refresh the Assets folder in Eclipse while game is running it does find the texture. So it could be a problem with Eclipse. Maybe absolut pathes work…

Why not just let asset manager pull the images directly out of the database? See AssetLocator.

Two options, write a own assetLocator as pspeed mentiond, or configure a tmp folder and add it to the assetmanager with a FileLocator.

(BTW The cache only is for already loaded stuff, so if you load 10 times the same image, it would only be loaded one time)

Regarding eclipse, is your asset folder by any chancein the src path and not a registerd path with filelocator? cause eclipse copies those to /bin, and make it available in the classpath. But only when it rebuilds, and it does that if the src changed between starts before launching.

1 Like

Works now! I have created a new folder within the project which ist NO source folder and given it to jMonkey via registerLocator. Thanks alot, great community!