Removing and creating entity


A place to ask questions or discuss issues relating to implementing applications with Axiom

User avatar

Veteran

Posts: 79

Joined: Fri Apr 17, 2009 7:38 am

Post Fri Nov 06, 2009 2:36 am

Removing and creating entity

Whats wrong with this (testing) code?

  Code:
            // Destroy old entity
            scene.RootSceneNode.DetachObject(ogreHead);
            scene.RemoveEntity("OgreHead");
            ogreHead = null;

            // Create new entity
            ogreHead = scene.CreateEntity("OgreHead", "ogrehead.mesh");
            scene.RootSceneNode.AttachObject(ogreHead);


I tested this with CameraTrack.cs demo (copying it to OnFrameStarted -method).
Demo stops in SubEntity.cs, line 641.

This same problem occurs on YAT (tetris project, it removes and creates bricks again and again), so thats the why Im wondering this.

Veteran

Posts: 632

Joined: Wed Mar 22, 2006 8:06 pm

Post Fri Nov 06, 2009 10:49 am

Re: Removing and creating entity

Looks like a bug, what's the exception/stack trace and the Axiom package in use? (log should cover that)
User avatar

Veteran

Posts: 79

Joined: Fri Apr 17, 2009 7:38 am

Post Fri Nov 06, 2009 2:44 pm

Re: Removing and creating entity

Im using newest crickhollow svn (on xp/w7)

[09:41:23] Object reference not set to an instance of an object.
at Axiom.Core.SubEntity.get_Lights() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\SubEntity.cs:line 643
at Axiom.Core.SceneManager.RenderSingleObject(IRenderable renderable, Pass pass, Boolean doLightIteration, LightList manualLightList) in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\SceneManager.cs:line 5243
at Axiom.Core.SceneManager.RenderSolidObjects(SortedList list, Boolean doLightIteration, LightList manualLightList) in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\SceneManager.cs:line 5420
at Axiom.Core.SceneManager.RenderSolidObjects(SortedList list, Boolean doLightIteration) in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\SceneManager.cs:line 5428
at Axiom.Core.SceneManager.RenderBasicQueueGroupObjects(RenderQueueGroup group) in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\SceneManager.cs:line 6022
at Axiom.Core.SceneManager.RenderQueueGroupObjects(RenderQueueGroup group) in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\SceneManager.cs:line 6002
at Axiom.Core.SceneManager.RenderVisibleObjects() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\SceneManager.cs:line 6090
at Axiom.Core.SceneManager.RenderScene(Camera camera, Viewport viewport, Boolean showOverlays) in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\SceneManager.cs:line 4583
at Axiom.Core.Camera.RenderScene(Viewport viewport, Boolean showOverlays) in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\Camera.cs:line 1648
at Axiom.Core.Viewport.Update() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\Viewport.cs:line 692
at Axiom.Graphics.RenderTarget.Update() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Graphics\RenderTarget.cs:line 876
at Axiom.Graphics.RenderWindow.Update(Boolean swapBuffers) in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Graphics\RenderWindow.cs:line 293
at Axiom.RenderSystems.DirectX9.D3DRenderWindow.Update(Boolean swapBuffers) in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\RenderSystems\DirectX9\D3DRenderWindow.cs:line 1148
at Axiom.Graphics.RenderWindow.Update() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Graphics\RenderWindow.cs:line 269
at Axiom.Graphics.RenderSystem.UpdateAllRenderTargets() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Graphics\RenderSystem.cs:line 750
at Axiom.Core.Root.UpdateAllRenderTargets() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\Root.cs:line 1003
at Axiom.Core.Root.RenderOneFrame() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\Root.cs:line 927
at Axiom.Core.Root.StartRendering() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\Axiom\Engine\Core\Root.cs:line 957
at Axiom.Demos.TechDemo.Start() in F:\csharp\axiom_svn\trunk_orig\trunk\Projects\AxiomDemos\Source\Demos\TechDemo.cs:line 392

Veteran

Posts: 632

Joined: Wed Mar 22, 2006 8:06 pm

Post Fri Nov 06, 2009 5:40 pm

Re: Removing and creating entity

SubEntity.Lights
  Code:
      public LightList Lights
      {
         get
         {
            // get the parent entitie's parent node
            Node node = parent.ParentNode;

            Debug.Assert( node != null );

643         return parent.ParentNode.Lights;
         }
      }

then the MovableObject.ParentNode in the SubEntity's parent object becomes null. At a glance it is setup correctly in SceneNode.AttachObject() -> MovableObject.NotifyAttached() and any NotifyAttached() overrides don't break it. No idea how it becomes null, needs some debugging maybe, can't help atm, if you don't solve, don't forget to file a bug ticket with a (possibly simplest) failing TechDemo test, that will help
User avatar

Veteran

Posts: 79

Joined: Fri Apr 17, 2009 7:38 am

Post Sat Nov 07, 2009 1:06 pm

Re: Removing and creating entity

It seems that sceneNode.DetachObject is the problem. When replacing it with sceneNode.DetachAllObjects(); then it works.
But Ill make a ticket.

Veteran

Posts: 632

Joined: Wed Mar 22, 2006 8:06 pm

Post Sat Nov 07, 2009 2:11 pm

Re: Removing and creating entity

To me it seems that DetachAllObjects() has a bit "hacky" impl, because it doesn't notify the attached objects of parent change to null, comparing with OGRE confirms that. DetachObject() should be fine, it makes the MovableObject.Parent null, but that's correct.

I can confirm the issue, going to debug a bit, first clue: just noted that the ogreHead is not attached to RootSceneNode at all in the CameraTrack demo

Veteran

Posts: 632

Joined: Wed Mar 22, 2006 8:06 pm

Post Sat Nov 07, 2009 2:27 pm

Re: Removing and creating entity

The problem is in SceneNode.AttachObject() ln 385
  Code:
objectList.Add( obj );
is to be replaced with
  Code:
objectList.Add( obj.Name, obj );
There might be more places of that sort, I'll look into it a bit.

Veteran

Posts: 632

Joined: Wed Mar 22, 2006 8:06 pm

Post Sat Nov 07, 2009 3:12 pm

Re: Removing and creating entity

I added a patch to the ticket. The above correction is not required if you use the patch.
User avatar

Veteran

Posts: 79

Joined: Fri Apr 17, 2009 7:38 am

Post Sun Nov 08, 2009 2:56 am

Re: Removing and creating entity

That was fast. Patch works great. But using DetachAllObjects() until patch reaches to trunk.

Return to General Q & A

Who is online

Registered users: MSN [Bot], Yahoo [Bot]

Powered by phpBB © 2000, 2002, 2005, 2007 phpBB Group.
Designed by ST Software for PTF.