Clearing BulletAppState

Currently at work so I don’t have any code to post at the moment but wanted to go ahead and get the concept of my issue out here.

My BulletAppState contains everything from my Level1 AbstractAppState, which is a bunch of Geometries with RigidBodyControls. All of the geometries are added to a single spatial then attached to the rootNode all at once.

I tried using this spatial in the physics removeAll and also tried looping through all of the children of the spatial on using remove to remove level1 physics from the BulletAppState but neither of these methods worked for me.

To make each geometry for the level, I do the following:

  • Create geometry
  • Add new RigidBodyControl
  • Attach geometry to parent spatial
  • Attach geometry to BulletAppState

If I place a breakpoint after the attach to BulletAppState and look at the geometry I noticed that the control list is now empty where before it contains 1, which was the RigidBodyControl. I know understand that is why I could not remove the control from the BulletAppState on cleanup using the geometry list.

So considering the only other physics control in the BulletAppState is the one for my character I decided to just destroy the BulletAppState and recreate it on each level load. Once the level is loaded I will add the existing character to this new BulletAppState. This works great on the desktop version but when I test this on Android the adding of the existing character’s CharacterControl causes my app to crash with “Unfortunately the game has stopped working” or something along those lines. I have the log output set to ALL and do not see an error at the time this crash occurs. If I detach the character AbstractAppState and recreate it after loading the second level it works fine on Android.

That being said the issue seems to be directly related to adding the existing CharacterControl to the new BulletAppState, but as to why this error is occurring on Android I’m in the dark.

As I’m still new to jmonkey I figured I would post this in hopes of someone being able to give me some ideas to try out by the time I make it home.

The BulletAppState doesn’t remove the Control from the Spatial, why would it? Your code seems to have other issues and is apparently not doing what you think it does.

That is very possible. I stepped back through my code and wasn’t able to reproduce that issue.

Okay found out my issue with removeAll not working.

I was constructing my level base using 10 x 10 quad geometries and adding them to a spatial groundNode. Each geometry had its own RigidBodyControl. I’m doing this to prevent the shaking issue that I was having with the CharacterControl.

Before adding the groundNode to the rootNode I was calling GeometryBatchFactory.optimize(groundNode); Doing this is what was preventing the removeAll(groundNode) not to work since it was condensing my ground into only 3 geometries.

So this issue is a direct result of my code. Just have to figure out how I want to fix this now.

short answer : you don’t want to create a level made of small quads, it will end with a very slow rendering. Instead of that, you want (yes, you want, even if you don’t know it yet ^^) to create a mesh yourself, even if it’s harder, as it will make the rendering faster.

You may want to have a look at the “block” framework ( even if i never used if myself, so i don’t know how good (or bad) it is.