Stronghold - add terrain and crash...
by Andy Hawkins · in Torque Game Engine Advanced · 07/10/2008 (8:20 am) · 10 replies
I delete the existing terrain, click on F4->Mission Objects->Environment->Terrain, give it a name and select newmission.ter, leave grid size as 8 - then click to close the dialog - >Crash!!!!!
Very annoying - is this a known issue?
Very annoying - is this a known issue?
#2
There's still another follow-up error that I'm still tracking (resource lookup thing).
The reason for the crash was that EditTSCtrl was modified to keep a reference to the active terrain block without updating the reference when the terrain got deleted. The following brings the EditTSCtrl code in sync with TerrainEditor (which is already tracking the active terrain block).
07/10/2008 (11:45 am)
Ok, this should fix the crash. I'd be thankful if you could apply this and report back whether it solves the issue you are seeing.There's still another follow-up error that I'm still tracking (resource lookup thing).
The reason for the crash was that EditTSCtrl was modified to keep a reference to the active terrain block without updating the reference when the terrain got deleted. The following brings the EditTSCtrl code in sync with TerrainEditor (which is already tracking the active terrain block).
Index: engine/source/gui/missionEditor/editTSCtrl.h
===================================================================
--- engine/source/gui/missionEditor/editTSCtrl.h
+++ engine/source/gui/missionEditor/editTSCtrl.h
@@ -73,7 +73,6 @@
Point3F mRawCamPos;
Point2I mLastMousePos;
bool mLastMouseClamping;
- TerrainBlock* mActiveTerrain;
bool mAllowBorderMove;
S32 mMouseMoveBorder;
@@ -92,7 +91,6 @@
// SimObject
bool onAdd();
- bool onWake();
//
bool mRenderMissionArea;
@@ -152,6 +150,8 @@
virtual S32 getDisplayType() {return mDisplayType;}
virtual void setDisplayType(S32 type) {mDisplayType = type;}
+ virtual TerrainBlock* getActiveTerrain();
+
virtual void calcOrthoCamOffset(F32 mousex, F32 mousey, U8 modifier=0);
DECLARE_CONOBJECT(EditTSCtrl);Index: engine/source/gui/missionEditor/editTSCtrl.cpp
===================================================================
--- engine/source/gui/missionEditor/editTSCtrl.cpp
+++ engine/source/gui/missionEditor/editTSCtrl.cpp
@@ -47,8 +47,6 @@
mIsoCamAngle = mDegToRad(45.0f);
mIsoCamRot = EulerF(0, 0, 0);
- mActiveTerrain = NULL;
-
mRenderGridPlane = true;
mGridPlaneOriginColor = ColorI(0, 0, 0, 255);
mGridPlaneColor = ColorI(0, 0, 0, 255);
@@ -85,23 +83,6 @@
return true;
}
-bool EditTSCtrl::onWake()
-{
- if(!Parent::onWake())
- return(false);
-
- // Find a terrain block
- SimSet * scopeAlwaysSet = Sim::getGhostAlwaysSet();
- for(SimSet::iterator itr = scopeAlwaysSet->begin(); itr != scopeAlwaysSet->end(); itr++)
- {
- mActiveTerrain = dynamic_cast<TerrainBlock*>(*itr);
- if(mActiveTerrain)
- break;
- }
-
- return true;
-}
-
void EditTSCtrl::onRender(Point2I offset, const RectI &updateRect)
{
// Perform possible mouse border move...
@@ -238,6 +219,22 @@
//------------------------------------------------------------------------------
+TerrainBlock* EditTSCtrl::getActiveTerrain()
+{
+ // Find a terrain block
+ SimSet* scopeAlwaysSet = Sim::getGhostAlwaysSet();
+ for(SimSet::iterator itr = scopeAlwaysSet->begin(); itr != scopeAlwaysSet->end(); itr++)
+ {
+ TerrainBlock* block = dynamic_cast<TerrainBlock*>(*itr);
+ if( block )
+ return block;
+ }
+
+ return NULL;
+}
+
+//------------------------------------------------------------------------------
+
void EditTSCtrl::getCursor(GuiCursor *&cursor, bool &visible, const GuiEvent &event)
{
make3DMouseEvent(mLastEvent, event);
@@ -339,7 +336,8 @@
if(mDisplayType == DisplayTypeIsometric)
{
// Store the screen center point on the terrain for a possible rotation
- if(mActiveTerrain)
+ TerrainBlock* activeTerrain = getActiveTerrain();
+ if( activeTerrain )
{
F32 extx, exty;
if(event.modifier & SI_SHIFT)
@@ -358,11 +356,11 @@
Point3F end = start + mLastEvent.vec * 4000.0f;
Point3F tStartPnt, tEndPnt;
- mActiveTerrain->getTransform().mulP(start, &tStartPnt);
- mActiveTerrain->getTransform().mulP(end, &tEndPnt);
+ activeTerrain->getTransform().mulP(start, &tStartPnt);
+ activeTerrain->getTransform().mulP(end, &tEndPnt);
RayInfo info;
- bool result = mActiveTerrain->castRay(tStartPnt, tEndPnt, &info);
+ bool result = activeTerrain->castRay(tStartPnt, tEndPnt, &info);
if(result)
{
info.point.interpolate(start, end, info.t);
@@ -600,9 +598,10 @@
F32 height = 0.f;
- if( mActiveTerrain != NULL )
+ TerrainBlock* activeTerrain = getActiveTerrain();
+ if( activeTerrain != NULL )
{
- GridSquare * gs = mActiveTerrain->findSquare(TerrainBlock::BlockShift, Point2I(0,0));
+ GridSquare * gs = activeTerrain->findSquare(TerrainBlock::BlockShift, Point2I(0,0));
height = F32(gs->maxHeight) * 0.03125f + 10.f;
}
#3
Anyways, to fix the resource lookup failures that, for example, show up when creating the terrain block and Torque won't find the .ter file, apply the following:
07/10/2008 (12:21 pm)
This is turning into a chain of bugs. Each time I get done with one, I stumble across a new one.Anyways, to fix the resource lookup failures that, for example, show up when creating the terrain block and Torque won't find the .ter file, apply the following:
Index: engine/source/platform/platformFileIO.cpp
===================================================================
--- engine/source/platform/platformFileIO.cpp
+++ engine/source/platform/platformFileIO.cpp
@@ -204,11 +204,8 @@
return buffer;
}
- // [rene, 05/05/2008] Based on overall file handling in Torque, it does not seem to make
- // that much sense to me to base things off the current working directory here.
-
if(cwd == NULL)
- cwd = Con::isCurrentScriptToolScript() ? Platform::getMainDotCsDir() : Platform::getCurrentDirectory();
+ cwd = Platform::getMainDotCsDir();
dStrncpy(buffer, cwd, size);
buffer[size-1] = 0;
#4
My platformFileIO.cpp fix above goes only half-way. Somewhere paths get messed up. Might revisit this later.
07/10/2008 (12:46 pm)
Ok, running out of time with this one. The trace leads into Torque's messy resource lookup stuff. It manifests itself in that for the first TerrainBlock created, everything's fine. For all others, Torque will emit the newObject.cs file to the wrong destination and then execute the previous one, consequently always generating a TerrainBlock with the initially specified values.My platformFileIO.cpp fix above goes only half-way. Somewhere paths get messed up. Might revisit this later.
#5
07/10/2008 (1:07 pm)
Rene, you scare me with your insane programming knowledge sometimes!
#6
07/10/2008 (1:43 pm)
Hehehe...
#7
07/10/2008 (4:11 pm)
Thanks Rene - I just saw your posts just before I have to go to work so I will apply the changes tonight - thanks very much for your prompt attention!
#9
09/01/2008 (8:34 am)
I've run into a similar problem. Using an empty game, no terrain or other objects, I add a Mega Terrain which works fine. The second Mega Terrain always crashes the engine. Could this be a related issue?
#10
09/13/2008 (2:43 am)
It sounds similar to me. Try the code change above from Rene.
Associate Rene Damm