Client.car.delete crashing game.
by Peterjohn Griffiths · in Torque Game Engine · 08/17/2006 (7:36 pm) · 6 replies
I have been having a problem respawning the car in the racing starter kit.
When you press Ctrl + R the whole program crashes. This would seem to be because the program still thinks the car you have deleted is still in the scene and is trying to process it.
I have tried alternate ways to create the same effect, but without a Vehicle::setVelocity method in vehicle.cc, I can see no other way to get around this.
The problem with car.delete(); is that when you delete the control item for the client from the server, the fuction "void fxSunLight::renderObject(SceneState* state, SceneRenderImage* ri)" in fxSunLight.cc is still being run against the deleted car object and you get an unhandled exception against the line
"ControlObj->getEyeTransform(&eye);"
It would seem that this would be because the control object is no longer the car that has been deleted but is now a different car object, but the function thinks its still the deleted car object.
Anyone got any idea if this sounds right and what can be done to get around it. Some sort of error trap at the start of the function or something to over ride it?.
I havn't touched C++ in a couple of years and am a bit rusty and new to Torque aswell, but this bug sure isn't going away with a simple tweek from what I understand.
Many thanks in advance.
When you press Ctrl + R the whole program crashes. This would seem to be because the program still thinks the car you have deleted is still in the scene and is trying to process it.
I have tried alternate ways to create the same effect, but without a Vehicle::setVelocity method in vehicle.cc, I can see no other way to get around this.
The problem with car.delete(); is that when you delete the control item for the client from the server, the fuction "void fxSunLight::renderObject(SceneState* state, SceneRenderImage* ri)" in fxSunLight.cc is still being run against the deleted car object and you get an unhandled exception against the line
"ControlObj->getEyeTransform(&eye);"
It would seem that this would be because the control object is no longer the car that has been deleted but is now a different car object, but the function thinks its still the deleted car object.
Anyone got any idea if this sounds right and what can be done to get around it. Some sort of error trap at the start of the function or something to over ride it?.
I havn't touched C++ in a couple of years and am a bit rusty and new to Torque aswell, but this bug sure isn't going away with a simple tweek from what I understand.
Many thanks in advance.
#2
:)
That being the case, I would like to aproach the problem by trying to detect if an object exists.
Something along the following lines.
08/18/2006 (12:29 am)
Thanks Tim.:)
That being the case, I would like to aproach the problem by trying to detect if an object exists.
Something along the following lines.
if (exists(ControlObj)){
//Some code.
}
else {
//Some other code.
}But I am unsure if there is a function to detect if the object exists or if I would need to create one.
#3
08/18/2006 (1:18 am)
IsObject(ControlObj) would be what you're looking for, I believe.
#4
I will give it a go tonight and post the results.
Would be good to solve this problem.
I will keep you posted.
08/18/2006 (10:02 am)
Great, thanks Jesse,I will give it a go tonight and post the results.
Would be good to solve this problem.
I will keep you posted.
#5
I have been trying several things to determine if the object is Null and have finaly got it to work.
IsObject is a console function and doesn't work within the c++ function.
I have been trying several things to determine if the object is Null and have finaly got it to work.
Very small modification to the "fxSunLight.cc" source file.
Open "fxSunLight.cc"
Find the function "void fxSunLight::renderObject(SceneState* state, SceneRenderImage* ri)"
Within the function find
WHEYEHY!.
This would be a good one to put into the starter racing kit so that it works from the off.
08/18/2006 (5:26 pm)
IsObject is a console function and doesn't work within the c++ function.I have been trying several things to determine if the object is Null and have finaly got it to work.
IsObject is a console function and doesn't work within the c++ function.
I have been trying several things to determine if the object is Null and have finaly got it to work.
Very small modification to the "fxSunLight.cc" source file.
Open "fxSunLight.cc"
Find the function "void fxSunLight::renderObject(SceneState* state, SceneRenderImage* ri)"
Within the function find
ControlObj->getEyeTransform(&eye); eye.getColumn(3, &eyePos);Replace with
//Check object exists incase object is NULL.
if (ControlObj){
ControlObj->getEyeTransform(&eye);
eye.getColumn(3, &eyePos);
}Thats it. Nice little one liner. Just rebuild Torque and all is now working fine.WHEYEHY!.
This would be a good one to put into the starter racing kit so that it works from the off.
#6
In file "server\scripts\commands.cs"
Replace the serverCmdReset function with the one below.
08/18/2006 (6:49 pm)
Just tried this on a head release and realised I changed my serverCmdReset function as well. Sorry. Forgot. :).In file "server\scripts\commands.cs"
Replace the serverCmdReset function with the one below.
function serverCmdReset(%client)
{
//Record client.car to delete later.
%tmpcar = %client.car;
// Create the player object
%car = new WheeledVehicle() {
dataBlock = DefaultCar;
client = %this;
};
MissionCleanup.add(%car);
// Player setup...
%spawnPoint = pickSpawnPoint();
%car.setTransform(%spawnPoint);
%car.setShapeName(%client.car.getShapeName);
// Update the camera to start with the player
%client.camera.setTransform(%car.getEyeTransform());
// Give the client control of the player
%client.car = %car;
//Set control of the car to the client.
%client.setControlObject(%client.car);
%client.nextCheck = 1;
%tmpcar.delete();
}
Torque Owner Tim Heldna