Game Development Community

Plea for help with debugging a script

by Ken Finney · in Torque Game Engine · 03/10/2004 (8:23 pm) · 10 replies

I have some script code that is behaving bizarrely. There are two
slightly different variants of the same program, one works, one doesn't.
They both work fine in Single-Player, or as Player-Hosted, but when
you run a dedicated server on another 'puter on the LAN, the client
crashes when the client player spawns in to the dedicated server.
The LAN isn't sympomatic, it also happens over the net. The
server is apparently unaffected, and merrily continues to accept
more victims into its lair.

The specific error is in the unpackUpdate function for the Camera object,
on the client-side, in ShapeBase::unpackUpdate

at this line:
mDamage = mClampF(stream->readFloat(DamageLevelBits) * mDataBlock->maxDamage, 0.f, mDataBlock->maxDamage);

mDataBlock ends up being null, and then there's this earth-shattering kaboom.


Here's the call stack, in case this problem looks familiar to someone who has
encountered something similar to this in the past:

ShapeBase::unpackUpdate(NetConnection * 0x017411e0, BitStream * 0x0012f6b0) line 3025 + 9 bytes
Camera::unpackUpdate(NetConnection * 0x017411e0, BitStream * 0x0012f6b0) line 408
NetConnection::ghostReadPacket(BitStream * 0x0012f6b0) line 496 + 45 bytes
NetConnection::readPacket(BitStream * 0x0012f6b0) line 650
GameConnection::readPacket(BitStream * 0x0012f6b0) line 793
NetConnection::handlePacket(BitStream * 0x0012f6b0) line 514 + 17 bytes
ConnectionProtocol::processRawPacket(BitStream * 0x0012f6b0) line 225 + 17 bytes
NetConnection::processRawPacket(BitStream * 0x0012f6b0) line 487
NetInterface::processPacketReceiveEvent(PacketReceiveEvent * 0x0012f868) line 79 + 17 bytes
DemoGame::processPacketReceiveEvent(PacketReceiveEvent * 0x0012f868) line 738 + 22 bytes
GameInterface::processEvent(Event * 0x0012f868) line 59 + 17 bytes
GameInterface::postEvent(Event & {...}) line 153 + 17 bytes
Net::process() line 540 + 26 bytes
DemoGame::main(int 1, const char * * 0x01222bf0) line 477
run(int 1, const char * * 0x01222bf0) line 1142 + 26 bytes
main(int 1, const char * * 0x01222bf0) line 1178 + 13 bytes
TORQUEDEMO_DEBUG! mainCRTStartup + 197 bytes
KERNEL32! 77e814c7()



It's Torque 1.2.1 -- it also happens with 1.2 and older versions as well.

I've been tearing my hair out these past two days trying to sort this one out while juggling
a million other tasks at the same time. Today was a major deadline, and it's
been missed...with this thing, and the other lunatic distractions around this
place, I'm rapidly aging ;-)

If you want to take on this challenge. please email me, kfinney@canada.com
and I will make both versions of the program available to you. Unfortunately,
I can't post the whole program here !

There's a case of beer and a book in it for those who'd take pity on me :-( <-- woeful face ;-)

#1
03/10/2004 (8:48 pm)
Are you sure you're setting a valid datablock on the object?
#2
03/10/2004 (9:05 pm)
Yeah Ben, I've checked & rechecked. I believe that's the ghosted client camera, and it's there.
The identical code is in both variants:
datablock CameraData(Observer)
{
   mode = "Observer";
};


function GameConnection::OnClientEnterGame(%this)
{
   // Create a new camera object.
   %this.camera = new Camera() {
      dataBlock = Observer;
   };
   MissionCleanup.add( %this.camera );
   %this.camera.scopeToClient(%this);
   %this.CreatePlayer("0 0 300 1 0 0 0");
}


function GameConnection::CreatePlayer(%this, %spawnPoint)
{
   if (%this.player > 0)
   {                    
      Error( "Attempting to create an angus ghost!" );
   }
   %player = new Player() {
      dataBlock = HumanMaleAvatar;   // defined in players/player.cs
      client = %this;           // the avatar will have a pointer to its
   };                           // owner's connection
   %player.setTransform(%spawnPoint); // where to put it
   %this.camera.setTransform(%player.getEyeTransform());
   %player.setEnergyLevel(100);
   %this.player = %player;
   %this.setControlObject(%player);
}

There are no script errors. After having stripped down both versions and bringing
each towards the other, the only difference between them remaining that I can see
is that the version that doesn't work doesn't have a chat HUD ! I doubt that has
much to do with it, but I'll be getting around to that stuff tomorrow when I get the
chance. I'm 70% convinced that there is something simple and obvious that I've missed
that's causing this. Like a '$' vs. '%' problem. Especially since the bad variant works
fine in single-player mode.
#3
03/10/2004 (10:45 pm)
IF you defined your datablock where your post showed -- in game.cs and not in some script (camera.cs) loaded by function onServerCreated() -- then you probably don't have a valid datablock.

In the console type echo(isObject(Observer)); to see (should be 1 if good, 0 if invalid). You could also type Observer.dump(); to see the values or tree(); and look in the datablock group.
#4
03/11/2004 (5:14 am)
Thanks Scott, the datablock def'n is in camera.cs, and a dump & echo show that it's valid. But you prompted another idea...
#5
03/11/2004 (6:50 am)
Le bump of desperation :-)
#6
03/11/2004 (8:03 am)
Le bump of desperation :-)
#7
03/11/2004 (8:31 am)
Interesting new development. If I don't scope the camera the the client in the bad variant of the code, it works !!!

ie.
function GameConnection::OnClientEnterGame(%this)
{
   // Create a new camera object.
   %this.camera = new Camera() {
      dataBlock = Observer;
   };
   MissionCleanup.add( %this.camera );
   // %this.camera.scopeToClient(%this);      <-- commented out this line
   %this.CreatePlayer("0 0 300 1 0 0 0");
}

strange, since the other version does this, and there is no problem with that one...
#8
03/11/2004 (8:53 am)
So is it fixed now? :)
#9
03/11/2004 (9:35 am)
Well, I'm gonna pretend it's fixed. It works in all modes now, single player, player hosted & dedicated server.
It bugs me that the fix was so bizarre. I'd like to know what was really happening.

Yer lookin' for a case o' beer now I s'pose :-)
#10
03/11/2004 (9:54 am)
Nah, just want to know that it's fixed so I can stop keeping track of the issue. ;)

I'm under age, anyway, so it'd have to be a case o' root beer. :P