Linked material in Blender crashing importer

(I guess @Kaelthas is the person to address in his matter.)

I have a Blender workflow where I use a separate materials.blend that contains materials used by all objects in a scene. Other .blends link to this and they can in turn be linked from a master .blend file. It seems though that linking materials like this doesn’t work (recursive or not).
I’ve spent quite some time trying to debug this but I haven’t been able to solve it. My theory is that since each blend is loaded separately, they can’t access materials in another blend. And/Or a non-working reference is created. In the end, blenderContext ends up being null as the stack is popped, crashing the importer.

The simplest way to reproduce this is to create a mat.blend. This has a cube with a material.
Create test.blend and add a cube in it. Link only the material from mat.blend and apply it to the cube.
Try to load test.blend in jme.

Tested on master.

Any help on the matter is appreciated. The alternative (making all materials local to the master blend) would be extremely non-optimal as that would also limit the possibility of linking objects in other blends (that share materials).


The best way to work with materials in Jm3 is to create the materials in the Jm3 and dont use the blender ones.
You can create the materials on jm3 based on the materials you have on blender.
And its easy to reuse on the objects.

If you only intend to do it once or twice on an object and do the scene composing in the SDK, maybe. But if you’re doing a whole scene in Blender which you want to iterate on, having to reapply materials every time you want to check it out in the engine is a waste of time.

1 Like

You can do it in the code, like, when loading the spatial, set the materials by name of the object +"_mat.jm3".
Of course in this case, your objects names needs to be the same from the materials files.
Anyway, in Jm3 you can set properties and effects not available or different on blender, so its recommended anyway.

Hi @rickard

I have tried to replicate the problem but I managed to load it without errors.
My guess is that the blender importer cannot find the second file.

Do you keep them in the same folder ?

If you could send me the files where the importer crashes I could take a look at it.

Thanks for taking a look.
I’ve uploaded a simplified (and non-working) version to Google Drive:

It should be said that it’s made with Blender 2.74.

Edit: Yes, they’re in the same folder. I can see through logs that each .blend and its contents are loaded OK. Hence my guess that the linking goes wrong.

Hi @rickard
The problem here lies within the asset manager which is unable to properly locate the linked files.

I can see two solutions for this.

  1. Since blender importer is a desktop tool I can simply open the file without the help of the file manager and load the data.
  2. I can also do it in more jme-style and create a custome BlenderLinkedFilesLocator which would be registered at the beggining and unregistered at the end of the loading process. It would do exactly what is mentioned in number 1.

I’d prefer the second way but maybe someone would have better idea ?

I can’t say that I have an opinion, but given that both solutions are equally difficult to implement, I’d say that following the convention sounds like a good path. It does sound more complex, though.

Edit: Oh, and it’s good that you found out the reason :slight_smile:

Hi @rickard

Looks like the solution will work. I will just need to fix some bugs that occur during linked object managment in the importer.

Sorry it takes so long, but I’m working like 12h / day now and when I get home I have little time left :frowning:

I will try to commit a fix this week.

@Kaelthas No problem, I know the feeling. I really appreciate the work you have put into the plugin. It is a quite awesome tool.
Last week gave had another go with an animated stock model I had had trouble with some time ago. It worked well importing it with the 3.1 Alpha (albeit doing the application work-around, which is fine by me). I did some cleaning on the rig which might have solved the problem. Or if there had been some changes in the plugin, I don’t know.

It feels like it’s really becoming all-encompassing and the only import tool needed for jMonkeyEngine 3.1.

Look forward to testing the fix :slight_smile:


Hi @rickard

I have made a commit today. If you update the jme check if it is working.
If something still goes wrong I’ll work on this further :wink:

1 Like

I’ve had some time to test it now. Not everything seems to work as intended.
Of the example files untitled.blend (which contains a linked cube form untitled2.blend with a linked material from mats.blend) crashes with:

WARNING: No features loaded from path: untitled2.blend.
okt 30, 2015 4:38:45 EM com.jme3.scene.plugins.blender.AbstractBlenderHelper loadLibrary
WARNING: Could NOT find asset named Cube in the library of path: untitled2.blend.
okt 30, 2015 4:38:45 EM handleError
SEVERE: Uncaught exception thrown in Thread[jME3 Main,5,main]
com.jme3.asset.AssetLoadException: An exception has occured while loading asset: Models/test/untitled.blend
    at com.jme3.asset.DesktopAssetManager.loadLocatedAsset(
    at com.jme3.asset.DesktopAssetManager.loadAsset(

Untitled2.blend which contains a linked material from mats.blend load OK, but without the material:

okt 30, 2015 4:41:13 EM com.jme3.scene.plugins.blender.AbstractBlenderHelper loadLibrary
WARNING: No features loaded from path: mats.blend.
okt 30, 2015 4:41:13 EM com.jme3.scene.plugins.blender.AbstractBlenderHelper loadLibrary
WARNING: Could NOT find asset named ceiling_material in the library of path: mats.blend.

Can you tell me what is the folder herarchy where you keep your files?
I put everything in the same folder and it loaded.

Yeah. The test I sent used the same folder, not my “real” project.
I’ve however since had to move all the objects into the same scene anyway since I use the excellent TextureAtlas plugin (by @Mifth, incidentally) to generate lightmaps.