Game Development Community

GameConnection and initPersistFields madness

by Fyodor -bank- Osokin · in Torque Game Engine · 11/13/2008 (3:22 am) · 4 replies

I'm trying to add:
static void initPersistFields();
to GameConnection class, so I can have some variables in script and in engine.

GameConnection is already properly declared to be console object with all supported features, so I went and added initPersistFields
gameConnection.h
...
   bool mTestVar; // Added!
public:
   DECLATE_CONOBJECT(GameConnection);
...
   static void consoleInit();
   static void initPersistFields(); // Added!
and
gameConnection.cc
IMPLEMENT_CONOBJECT(GameConnection);
...
// After ::consoleInit()
void GameConnection::initPersistFields()
{
   Parent::initPersistFields();
   addGroup("Scripted");	
   addField("testVar", TypeBool, Offset(mTestVar, GameConnection));
   endGroup("Scripted");
}
In c'cor of gameConnection I've added:
GameConnection::GameConnection()
{
   mTestVar = false;
...

So, all seems to be fine... but! Looks like it goes not work as it should, the scripted and engine variables are out of sync.
I've added consoleMethods to directly change value of var and it works (getTest()/setTest(bool)) but does not change the value in scripts.
When I chage from console - it does not update engine-side variable.

Am I missing something? o_O
Any help/assistance/hints appreciated!

P.S. I've made some new console object types which inherit similar to gamecon (originated from SimObject) and it works fine for me.

P.P.S. After some playing got some crashes after doing .dump() and setting value from console at different places like
CodeBlock::~CodeBlock() --- delete[] breakList;
and
platformMemory.cc -> rorateLeft(TreeNode *hdr) --- temp->left->parent = hdr;

#1
11/21/2008 (10:38 am)
IIRC mTestVar needs to be public if you're going to expose it to the console that way.
#2
11/21/2008 (2:24 pm)
Done a clean rebuild? It looks like there's memory corruption, which might be due to a mismatch in the console data structures due to incremental build.

Pub/private issues would show up at compile time... and I think it's ok with private vars.
#3
11/23/2008 (3:51 am)
Thanks for comments guys!
The pub/protected is not an issue, as most of fields (exported to script) in engine are protected Tried public too, no luck.

Re: clean/rebuild. Actually, I've started with clean install of 1.5.2, tried clean AFX1.0.2 too. And I'm always doing full rebuild (with /MP4 switch on my C2Q) when developing something new and/or getting weird ;) stuff

More log:
*** Load Main Menu
==>new gameconnection(sc);
==>sc.dump();
Member Fields:
  testVar = "1"
Tagged Fields:
Methods:
... skipped
==>echo(sc.testVar=0);
0
==>sc.dump();
Member Fields:
  testVar = "1"
Tagged Fields:
Methods:
... skipped
I've started tree(sc); and opened the gameconnection properties, - it showed that bool var has un-checked (value==0), but when I try to toggle it - crash @
static void free(void* mem, bool array)
{
   ...
   PROFILE_START(MemoryFree);
   AllocatedHeader *hdr = ((AllocatedHeader *)mem) - 1; // Here

   AssertFatal(hdr->flags & Allocated, avar("Not an allocated block!"));
   ...
}
Next start - got a crash in Memory::rotateRight.
#4
11/26/2008 (7:50 am)
Just a hunch but, since GameConnection does not have an initPersistFields method inherently, maybe the method is not called when a GameConnection is created. Which would explain the out of sync behavior since the script variable and the code variable will not be linked.

As for where to start looking to correct this behavior, I cannot say. Hope my hunch proves useful! :)