Setting tiles by grid co-ords[Solved, kind of]
by Cosmic Logic · in Torque X 2D · 09/03/2010 (6:02 am) · 6 replies
Hey,
I'm trying to simply change a tile in my grid. The problem I'm having is that as soon as I call the SetTileByGridCoords method the game crashes with "Cannot access a disposed object. Object name: 'DynamicVertexBuffer'."
I'm sure this is because the vertex buffer is invalidated at the end of SetTileByGridCoords. Should it not re-set the vb automatically?
Here's the call I'm using:
I tried creating my own custom tile to put in, but I thought that was the problem, so I tried simply cloning one of the other tiles and using that, but still no dice.
I'm trying to simply change a tile in my grid. The problem I'm having is that as soon as I call the SetTileByGridCoords method the game crashes with "Cannot access a disposed object. Object name: 'DynamicVertexBuffer'."
I'm sure this is because the vertex buffer is invalidated at the end of SetTileByGridCoords. Should it not re-set the vb automatically?
Here's the call I'm using:
SceneObject.SetTileByGridCoords((int)tile.GridPosition.X, (int)tile.GridPosition.Y, SceneObject.PickTile(Vector2.Zero).Clone() as T2DTileObject);
I tried creating my own custom tile to put in, but I thought that was the problem, so I tried simply cloning one of the other tiles and using that, but still no dice.
#2
09/03/2010 (5:18 pm)
That's pretty much the exact same thing I'm doing except that as soon as I call SetTileByGridCoords I get that disposed Vertex Buffer crash.
#3
09/03/2010 (7:41 pm)
Perhaps there is something that is done when you assign the tile type, that doesn't get done when you clone it.. did you try it my way?
#4
And then setting the tile like so:
(aStarNode is an overload of T2DTileObject that I use for my pathfinding. It just adds 3 properties to the T2DTileObject. I've changed my T2DTileLayer as well to take aStarNode as inputs for the picktile, gettile and settile methods. I've also made the list of tiles in the T2DTileLayer a list of astarNodes. It hasn't given me any problems so far and I couldn't see how this would create this kind of problem with invalidated resources)
09/03/2010 (8:08 pm)
Yeah. I used that way initially._finishTileVert = new aStarNode();
_finishTileVert.TileType = SceneObject.TileTypes.Find(delegate(T2DTileType obj) {
if(obj.MaterialRegionIndex == 4)
return true;
return false;
});
_finishTileVert.TileTypeIndex = _finishTileVert.TileType.Index;
_finishTileVert.TileTypeName = _finishTileVert.TileType.Name;(I've run the debug and the delegate finds a tile type and it is the one I'm looking for)And then setting the tile like so:
bool x = SceneObject.SetTileByGridCoords((int)tile.GridPosition.X, (int)tile.GridPosition.Y, _finishTileVert);
(aStarNode is an overload of T2DTileObject that I use for my pathfinding. It just adds 3 properties to the T2DTileObject. I've changed my T2DTileLayer as well to take aStarNode as inputs for the picktile, gettile and settile methods. I've also made the list of tiles in the T2DTileLayer a list of astarNodes. It hasn't given me any problems so far and I couldn't see how this would create this kind of problem with invalidated resources)
#5
09/04/2010 (6:20 am)
Alright, I loaded up a brand new project and tried doing the same thing and it works, so it must be the changes I've made to the engine.
#6
I've created a new project, I can set tiles. I even tried loading up my altered code with the aStarNode changes and it works fine (all of my changes. I did so by creating a Tortoise patch that I applied to the new project). I'm using Tortoise to go through all of the changes I've made to the source. In the mean time, does anyone know what might be happening?
Here's the stack trace if it helps anyone:
EDIT:
Well, it's definately not the source. I've copied it back from the working new project and still no dice.
I'm going to try to find when this is getting disposed.
EDIT:
Well, I've sorted out that it all works, except that you cannot seem to call a SetTileByGridCoords in a particle collision delegate. I'll fire Pino an e-mail about it.
09/04/2010 (6:48 am)
Hm, now this is boggling my mind.I've created a new project, I can set tiles. I even tried loading up my altered code with the aStarNode changes and it works fine (all of my changes. I did so by creating a Tortoise patch that I applied to the new project). I'm using Tortoise to go through all of the changes I've made to the source. In the mean time, does anyone know what might be happening?
Here's the stack trace if it helps anyone:
> GarageGames.TorqueX.Framework.dll!GarageGames.Torque.RenderManager.BaseRenderManager._RenderGroup Line 386 C# GarageGames.TorqueX.Framework2D.dll!GarageGames.Torque.RenderManager.T2DRenderManager._RenderGroup Line 109 C# GarageGames.TorqueX.Framework.dll!GarageGames.Torque.RenderManager.BaseRenderManager._RenderDiffuse Line 291 C# GarageGames.TorqueX.Framework2D.dll!GarageGames.Torque.RenderManager.T2DRenderManager.RenderOpaquePass Line 70 C# GarageGames.TorqueX.Framework.dll!GarageGames.Torque.RenderManager.SceneRenderer.Render Line 579 C# GarageGames.TorqueX.Framework.dll!GarageGames.Torque.SceneGraph.BaseSceneGraph.Render Line 558 C# GarageGames.TorqueX.Framework.dll!GarageGames.Torque.GUI.GUISceneview.OnRender Line 126 C# GarageGames.TorqueX.Framework.dll!GarageGames.Torque.GUI.GUICanvas.OnRender Line 259 C# GarageGames.TorqueX.Framework.dll!GarageGames.Torque.GUI.GUICanvas.RenderFrame Line 164 C# GarageGames.TorqueX.Framework.dll!GarageGames.Torque.XNA.TorqueEngineComponent.Draw Line 586 C# [External Code] GarageGames.TorqueX.Framework.dll!GarageGames.Torque.GameUtil.TorqueGame.Draw Line 407 C# [External Code] Cosmic Harvest.exe!CosmicHarvest.Game.Main Line 90 C#
EDIT:
Well, it's definately not the source. I've copied it back from the working new project and still no dice.
I'm going to try to find when this is getting disposed.
EDIT:
Well, I've sorted out that it all works, except that you cannot seem to call a SetTileByGridCoords in a particle collision delegate. I'll fire Pino an e-mail about it.
Torque 3D Owner Will O-Reagan
Modern Intrigues
So you can see, I basically get a tile type, create a brand new tile object, asign the object a new tile type, and set the tile by grid coords... seems to work.
-Will