Item::unpackUpdate() Bug - Affects setCollisionTimeout()
by Edward F. Maurina III · in · 01/27/2005 (4:12 pm) · 5 replies
Anyone using the provided (integrated) version of this kit should take a look at
Item.cc at about line 853.
If you use the setCollisionTimeout() while throwing objects, or for other purposes, you may experience intermittent:
- Crashes (in non-debug mode)
- NULL Ghost Error (then crash) in Debug-mode
- Non-rendering of Items (or sudden pop-in) of items
- Other
The problem is that the Item:packUpdate() uses an ENUM to set the bit transfer size for the collision timeout data, while the Item::unpackUpdate() uses a hardcoded value of (10). Simply update your code to this to fix the problem:
Note: This bug exists in TGE 1.3 also.
[HOW]EdM|EGTGE
PS - If you want to test this issue try adding this code to a virgin copy of crossbow.cs:
Note: The above code depends on $player being set in game.cs->
Item.cc at about line 853.
If you use the setCollisionTimeout() while throwing objects, or for other purposes, you may experience intermittent:
- Crashes (in non-debug mode)
- NULL Ghost Error (then crash) in Debug-mode
- Non-rendering of Items (or sudden pop-in) of items
- Other
The problem is that the Item:packUpdate() uses an ENUM to set the bit transfer size for the collision timeout data, while the Item::unpackUpdate() uses a hardcoded value of (10). Simply update your code to this to fix the problem:
void Item::unpackUpdate(NetConnection *connection, BitStream *stream)
{
Parent::unpackUpdate(connection,stream);
if (stream->readFlag()) {
mRotate = stream->readFlag();
mStatic = stream->readFlag();
mCollideable = stream->readFlag();
if (stream->readFlag())
mathRead(*stream, &mObjScale);
else
mObjScale.set(1, 1, 1);
}
if (stream->readFlag()) {
// S32 gIndex = stream->readInt(10);
S32 gIndex = stream->readInt(NetConnection::GhostIdBitSize);
setCollisionTimeout(static_cast<ShapeBase*>(connection->resolveNote: This bug exists in TGE 1.3 also.
[HOW]EdM|EGTGE
PS - If you want to test this issue try adding this code to a virgin copy of crossbow.cs:
function a()
{
echo("Throwing bow");
%this = $player;
%obj = new Item() {
datablock = Crossbow;
rotation = "0 0 1 " @ (getRandom() * 360);
};
MissionGroup.add(%obj);
// Throw the given object in the direction the shape is looking.
// The force value is hardcoded according to the current default
// object mass and mission gravity (20m/s^2).
%throwForce = %this.throwForce;
if (!%throwForce)
%throwForce = 20;
// Start with the shape's eye vector...
%eye = %this.getEyeVector();
%vec = vectorScale(%eye, %throwForce);
// Add a vertical component to give the object a better arc
%verticalForce = %throwForce / 2;
%dot = vectorDot("0 0 1",%eye);
if (%dot < 0)
%dot = -%dot;
%vec = vectorAdd(%vec,vectorScale("0 0 " @ %verticalForce,1 - %dot));
// Add the shape's velocity
%vec = vectorAdd(%vec,%this.getVelocity());
// Set the object's position and initial velocity
%pos = getBoxCenter(%this.getWorldBox());
%obj.setTransform(%pos);
%obj.applyImpulse(%pos,%vec);
// Since the object is thrown from the center of the
// shape, the object needs to avoid colliding with it's
// thrower.
%obj.setCollisionTimeout(%this);
}Note: The above code depends on $player being set in game.cs->
function GameConnection::createPlayer(%this, %spawnPoint)
{
// ...
$player = %this.player;
}About the author
Recent Threads
#2
Thanks for pointing it out!
-John
01/27/2005 (7:34 pm)
Cool, I'll make sure the next release incorporates this.Thanks for pointing it out!
-John
#3
03/14/2005 (10:44 pm)
Ok, I've committed this fix. Thanks Ed!
#4
05/26/2005 (11:25 pm)
I'm so happy you found that. I've been racking my brains for days on an issue and just found it to be this bug. Finally, I can move on! thanks
#5
This issue is already fixed in the latest Lighting Pack (version 1.3.5).
-John
05/27/2005 (12:01 pm)
Hi Rob,This issue is already fixed in the latest Lighting Pack (version 1.3.5).
-John
Associate Kyle Carter