BEPU Exception when exiting the Editor

Dec 23, 2011 at 3:22 PM

Thanks for releasing that 0.9.1.0 build! I appreaciate the quick turn around!

One other thing that I've been running into is an exception from the Space.Remove() method when I close the Editor. When I restart the app, the saves from the Editor are there and everything works fine. Do you think I'm missing something to deal with this case?

System.ArgumentException was unhandled
  Message=The object does not belong to this space; cannot remove it.
  Source=Indiefreaks.Game.Physics
  StackTrace:
       at BEPUphysics.Space.Remove(ISpaceObject spaceObject) in C:\PhoneCode\Xna\IGF\1 - Source\Main\Indiefreaks Game Framework Solution\Indiefreaks.Game.Physics\BEPU\Space.cs:line 365
       at BEPUphysics.OtherSpaceStages.SpaceObjectBuffer.UpdateStage() in C:\PhoneCode\Xna\IGF\1 - Source\Main\Indiefreaks Game Framework Solution\Indiefreaks.Game.Physics\BEPU\OtherSpaceStages\SpaceObjectBuffer.cs:line 75
       at BEPUphysics.ProcessingStage.Update() in C:\PhoneCode\Xna\IGF\1 - Source\Main\Indiefreaks Game Framework Solution\Indiefreaks.Game.Physics\BEPU\ProcessingStage.cs:line 34
       at BEPUphysics.Space.DoTimeStep() in C:\PhoneCode\Xna\IGF\1 - Source\Main\Indiefreaks Game Framework Solution\Indiefreaks.Game.Physics\BEPU\Space.cs:line 484
       at BEPUphysics.Space.Update() in C:\PhoneCode\Xna\IGF\1 - Source\Main\Indiefreaks Game Framework Solution\Indiefreaks.Game.Physics\BEPU\Space.cs:line 510
       at Indiefreaks.Xna.Physics.BEPUPhysicsManager.Update(GameTime gameTime) in C:\PhoneCode\Xna\IGF\1 - Source\Main\Indiefreaks Game Framework Solution\Indiefreaks.Game.Physics\Physics\BEPUPhysicsManager.cs:line 121
       at SynapseGaming.LightingSystem.Core.SceneInterface.Update(GameTime gameTime)
       at Indiefreaks.Xna.Core.GameState.Indiefreaks.Xna.Core.IUpdate.Update(GameTime gameTime) in C:\PhoneCode\Xna\IGF\1 - Source\Main\Indiefreaks Game Framework Solution\Indiefreaks.Game.Framework\Core\GameState.cs:line 117
       at Indiefreaks.Xna.Core.Application.Update(GameTime gameTime) in C:\PhoneCode\Xna\IGF\1 - Source\Main\Indiefreaks Game Framework Solution\Indiefreaks.Game.Framework\Core\Application.cs:line 323
       at Microsoft.Xna.Framework.Game.Tick()
       at Microsoft.Xna.Framework.Game.HostIdle(Object sender, EventArgs e)
       at Microsoft.Xna.Framework.GameHost.OnIdle()
       at Microsoft.Xna.Framework.WindowsGameHost.RunOneFrame()
       at Microsoft.Xna.Framework.WindowsGameHost.ApplicationIdle(Object sender, EventArgs e)
       at System.Windows.Forms.Application.ThreadContext.System.Windows.Forms.UnsafeNativeMethods.IMsoComponent.FDoIdle(Int32 grfidlef)
       at System.Windows.Forms.Application.ComponentManager.System.Windows.Forms.UnsafeNativeMethods.IMsoComponentManager.FPushMessageLoop(IntPtr dwComponentID, Int32 reason, Int32 pvLoopData)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoopInner(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.ThreadContext.RunMessageLoop(Int32 reason, ApplicationContext context)
       at System.Windows.Forms.Application.Run(Form mainForm)
       at Microsoft.Xna.Framework.WindowsGameHost.Run()
       at Microsoft.Xna.Framework.Game.RunGame(Boolean useBlockingRun)
       at Microsoft.Xna.Framework.Game.Run()
       at FlyingCodeMonkeys.BroomBots3D.Boot.Main() in C:\PhoneCode\Xna\BroomBots3D\BroomBots3D\BroomBots3D\BroomBotsApplication.cs:line 22
  InnerException:

Coordinator
Dec 23, 2011 at 3:50 PM

Maybe another bug then :)

In BEPUPhysicsManager.Update() method, I perform a check to see if the Editor exists and if it is active: therefore, it won't update physics.

If you add a SceneObject with a BEPUCollisionMove instance, it'll try to add itself to the Space using Space.Add() and since the Update() isn't performed, I believe it is placed on a buffer until the next Update() call is made. As such, it could raise an exception such as the one you have.

If you're still playing with IGF's source code, you may wanna try to go on BEPUPhysicsManager.cs in the Update() method and comment the following lines:

        /// <summary>
        /// Updates the object and its contained resources.
        /// </summary>
        /// <param name="gameTime"/>
        public void Update(GameTime gameTime)
        {
            _sceneEntities.Clear();
            _frameCollisionMoves.Clear();

            _sceneInterface.GetManager<IObjectManager>(true).FindFast(_sceneEntities);

            foreach (var sceneEntity in _sceneEntities)
            {
                if (sceneEntity is ICollisionObject && ((ICollisionObject)sceneEntity).CollisionMove is BEPUCollisionMove)
                {
                    var collisionMove = ((ICollisionObject) sceneEntity).CollisionMove as BEPUCollisionMove;
                    _frameCollisionMoves.Add(collisionMove);
                }
            }
            
            foreach (var bepuCollisionMove in _frameCollisionMoves)
            {
                bepuCollisionMove.Begin();
            }

            /* COMMENT THESE TWO LINES */
            //if (_sceneInterface.GetManager<SynapseGaming.LightingSystem.Editor.SunBurnEditor>(false) != null && _sceneInterface.GetManager<SynapseGaming.LightingSystem.Editor.SunBurnEditor>(true).EditorAttached)
             // return;

            if(UseInternalTimeStepping)
                Space.Update((float) gameTime.ElapsedGameTime.TotalSeconds);
            else
                Space.Update();

            foreach (var bepuCollisionMove in _frameCollisionMoves)
            {
                bepuCollisionMove.End();
            }
        }

 



Build and see what you get. Sole issue I can see with this is that the Physics will be applied while working on the Editor (such as Gravity forces for instance).

Dec 23, 2011 at 4:00 PM

Yeah, that does fix the problem....you're all over it! It's kind of funny using the editor with the objects still falling and stuff. :)

 

Coordinator
Dec 23, 2011 at 4:22 PM

I'll add another fix so that physics aren't applied in the Editor but differently. Just need to think how to do this. ;)

Coordinator
Dec 23, 2011 at 4:23 PM
This discussion has been copied to a work item. Click here to go to the work item and continue the discussion.
Dec 24, 2011 at 11:49 AM

Yeah, I think there is probably more work to do then just commenting those lines because I still hit that same error in other areas of BEPU when using the Editor with BEPUPhysicsManager running. For example, when I added new objects to the scene, I would get the error from Space.Add this time.

To work around the problem, I just switched back to the SunBurn physics engine (CollisionManager) until I have the scene totally configured. After the scene is all set, I can go back to BEPU.

Coordinator
Dec 28, 2011 at 2:43 PM

Yes, I need to make a bunch of use cases and test them all against an IGF application. I'll make some work on that direction in the coming weeks.