I’m tying to create an OSGi application with JMonkey, the first part which is integrating JMonkey in an OSGi environment is a success but now we want to create multiple bundles for multiple Applications (each Application is in his own Bundle so has it’s own ClassLoader etc …). Does JMonkey supports this case ?
Because after making a rapid test we had a nice NullPointerException in lwjgl apparently.
Well if you take the implications into account then yes. The jMonkeyEngine SDK modules are the same. Hint: you can only load classes from another module through the classloader but the classes you load do have full access to the module classpath.
In fact the problem is more to have several displays (Canvas). Is there a way to do so?
You can have multiple canvases, yes.
I suspect Normen’s advice is to use one “canvas” class loader to create Canvas objects, and hand these to “worker” class loaders that attach scene graphs. I further suspect that that’s necessary because while you can duplicate Java “globals” by setting up multiple class loaders, the C libraries behind LWJGL might have globals that do not duplicate if you have multiple LWJGLs.
(It would be nice if somebody could confirm or correct that.)
Two risks associated with the whole approach:
Canvas has bugs that may or may not affect you. In particular, the sizing behaviour of the AWT panel seems flaky, there might be more. (This is unrelated to what you’re doing, it’s a general problem with LJWGL canvases.)
Handing nonprimitive objects around between class loaders is risky, because each inter-class loader reference create a link that might prevent a class loader from becoming unreachable that should have long died. If this becomes a problem, expect resource and memory leaks; if it comes to the worst, you may get dangling pointers on the C side of things.
This is less of a problem if the LWJGL layer of JME was carefully built to avoid any references from its data structures to the rest of JME. I do not know if that is the case.