Problems with supermarket game in JMECanvas together with Swing

Hi everybody,



I'm currently trying to setup a 3D supermarket game integrated in a swing application based on JME. For the Swing integration I'm using SimpleCanvasImpl together with a JMECanvas similar to JMESwingTest. So far actually everything works. My problem now is that I have to load hundreds of products with textures, models for shelves and room textures. Of course that actually takes quite long and therfore my GUI freezes for about 20 seconds.



Now I want to preload all this stuff during showing the panel with the shopping list BEFORE I go to the panel where the JMECanvas and the actual supermarket is shown (basically I just want to add the preloaded product nodes, room nodes and shelve nodes to the root node when starting to show the panel where the JMECanvas resides). Unfortunately when I try to load models before I get the following exception:



java.lang.NullPointerException

at com.jmex.model.converters.ObjToJme$MaterialGrouping.<init>(Unknown Source)

at com.jmex.model.converters.ObjToJme.convert(Unknown Source)



As I have seen the problem actually is that the renderer is NULL when the system is trying to do renderer.createMaterialState(); inside the constructur of MaterialGrouping. It looks like that the Renderer will be generated first when the JMECanvas is fully shown and getting repainted.



Is there any possibility in that case to do all this preloading stuff before the panel with the JMECanvas is shown without having these problems?



Thanks,



Michael

GameStates would probably be your friend here, check out the testGameStateSystem test…

basixs said:

GameStates would probably be your friend here, check out the testGameStateSystem test....


Thank you for your reply. I did have a look at TestGameStateSystem, but there they only use a normal window, but not actually a JMECanvas together with a JMECanvasImplementor. Do you know a good example where somebody uses Game States together with a JMECanvas? Do I need to use BaseGame for working with Game States?

Thanks,

Michael

Look at StandardGame, which is what you need to use gamestates; it can use a  Canvas. :slight_smile:

basixs said:

Look at StandardGame, which is what you need to use gamestates; it can use a  Canvas. :)


Well, I tried the following:

StandardGame game = new StandardGame(gameName);
StandardGame.DISPLAY_MODE = StandardGame.DISPLAY_CANVAS;
game.start();



Already at the point of starting the StandardGame I get a NullPointer Exception in StandardGame at the following code line:

camera = display.getRenderer().createCamera(display.getWidth(), display.getHeight());



It looks like the Renderer is NULL. Do you have any idea how I can get rid of this problem?

I would like to create products with attached textures and shelf models in a GameState, but that's simply not possible when Renderer is NULL.

Thanks,

Michael

There's a current bug in StandardGame when trying to render in a Canvas and I haven't had time to work through it yet and no one has offered a solution.  If you have the time to go through the examples that do this and point out how to fix the problem in StandardGame many people would thank you and I'd be happy to apply the patch.

Also, you could take a look at the way Renanse's ParticleEditor does it.