From 36137ab5b72aeb0b305a8023071317f33776afe9 Mon Sep 17 00:00:00 2001 From: wdbee Date: Sat, 25 Sep 2010 11:10:19 +0000 Subject: [PATCH] Bug fix career mode modifications git-svn-id: https://svn.code.sf.net/p/speed-dreams/code/trunk@2793 30fe4595-0a0c-4342-8851-515496e4dcbd Former-commit-id: 002f687b583c4b87a2efc70cf9a99f39b3e19fc2 Former-commit-id: a4089d6026007b47c5399111109b57e536089319 --- src/drivers/simplix/src/unitdriver.cpp | 56 +++++++++++++++++--------- src/drivers/simplix/src/unitmain.cpp | 18 ++++++--- 2 files changed, 49 insertions(+), 25 deletions(-) diff --git a/src/drivers/simplix/src/unitdriver.cpp b/src/drivers/simplix/src/unitdriver.cpp index 98d12f14..31f1a0b0 100644 --- a/src/drivers/simplix/src/unitdriver.cpp +++ b/src/drivers/simplix/src/unitdriver.cpp @@ -9,10 +9,10 @@ // // File : unitdriver.cpp // Created : 2007.11.25 -// Last changed : 2010.02.08 +// Last changed : 2010.09.25 // Copyright : © 2007-2010 Wolf-Dieter Beelitz // eMail : wdb@wdbee.de -// Version : 2.00.000 +// Version : 2.00.001 //--------------------------------------------------------------------------* // Teile dieser Unit basieren auf diversen Header-Dateien von TORCS // @@ -58,6 +58,12 @@ // GNU GPL (General Public License) // Version 2 oder nach eigener Wahl eine spätere Version. //--------------------------------------------------------------------------* +// THIS VERSION WAS MODIFIED TO BE USED WITH SD CAREER MODE +// This results in some issues while using it with windows! +// Known bugs: +// Heap corruption -> do not used delete for oCarType, use free (oCarType) +// +//--------------------------------------------------------------------------* //#undef SPEED_DREAMS #include @@ -80,11 +86,11 @@ // Statics //--------------------------------------------------------------------------* int TDriver::NBBOTS = MAX_NBBOTS; // Nbr of drivers/robots -//double TDriver::CurrSimTime = 0; // Current simulation time -const char* TDriver::MyBotName = "simplix"; // Name of this bot -const char* TDriver::ROBOT_DIR = "drivers/simplix"; // Sub path to dll -const char* TDriver::SECT_PRIV = "simplix private"; // Private section -const char* TDriver::DEFAULTCARTYPE = "car1-trb1"; // Default car type +//double TDriver::CurrSimTime = 0; // Current simulation time +const char* TDriver::MyBotName = "simplix"; // Name of this bot +const char* TDriver::ROBOT_DIR = "drivers/simplix";// Sub path to dll +const char* TDriver::SECT_PRIV = "simplix private";// Private section +const char* TDriver::DEFAULTCARTYPE = "car1-trb1";// Default car type bool TDriver::AdvancedParameters = false; // Advanced parameters bool TDriver::UseOldSkilling = false; // Use old skilling bool TDriver::UseSCSkilling = false; // Use supercar skilling @@ -99,7 +105,7 @@ bool TDriver::Learning = false; // Initialize double TDriver::LengthMargin; // safety margin long. bool TDriver::Qualification; // Global flag -static const char *WheelSect[4] = // TORCS defined sections +static const char *WheelSect[4] = // TORCS defined sections {SECT_FRNTRGTWHEEL, SECT_FRNTLFTWHEEL, SECT_REARRGTWHEEL, SECT_REARLFTWHEEL}; //static double (TDriver::*CalcCrv)(double Crv); @@ -333,7 +339,8 @@ TDriver::TDriver(int Index): // GfOut("#TDriver::TDriver() >>>\n"); int I; oIndex = Index; // Save own index - oExtended = ( Index < 0 || Index >= NBBOTS ) ? 1 : 0; //Determine if it is extended or not + oExtended = // Determine if it + ( Index < 0 || Index >= NBBOTS ) ? 1 : 0; // is extended or not // Motion survey oSysFooStuckX = new TSysFoo(1,128); // Ringbuffer for X @@ -362,7 +369,9 @@ TDriver::~TDriver() delete [] oOpponents; if (oCarType != NULL) - delete oCarType; +// delete oCarType; // CAUSES HEAP CORRUPTION ASSERTION + free(oCarType); + if (oStrategy != NULL) delete oStrategy; if (oSysFooStuckX != NULL) @@ -385,7 +394,8 @@ void TDriver::SetBotName(void* RobotSettings, char* Value) // in the teams xml file and to load depending // setup files we have to find it out: - if (oCarType) + // Needed for Career mode? + if (oCarType) free (oCarType); oCarType = NULL; @@ -398,19 +408,27 @@ void TDriver::SetBotName(void* RobotSettings, char* Value) ,ROB_SECT_ROBOTS,ROB_LIST_INDEX,oIndex); // Index of own driver char* Section = SectionBuffer; - oCarType = strdup(GfParmGetStr // Get pointer to - (RobotSettings // car type - , Section // defined in corresponding - , ROB_ATTR_CAR, DEFAULTCARTYPE)); // section, default car type - oBotName = Value; // Get pointer to drivers name - -#ifdef SPEED_DREAMS //Speed dreams has a trick to find out the oCarType +#ifdef SPEED_DREAMS + // Modified to avoid memory leaks + // Speed dreams has a trick to find out the oCarType RtGetCarindexString(oIndex, "simplix", oExtended, indexstr, 32); if( oExtended ) - oCarType = strdup( indexstr ); + oCarType = strdup( indexstr ); + else // avoid empty car type + oCarType = strdup(GfParmGetStr // Get pointer to + (RobotSettings // car type + , Section // defined in corresponding + , ROB_ATTR_CAR, DEFAULTCARTYPE)); // section, default car type +#else // IF NOT SPEED_DREAMS use simplix way to do it + oCarType = strdup(GfParmGetStr // Get pointer to + (RobotSettings // car type + , Section // defined in corresponding + , ROB_ATTR_CAR, DEFAULTCARTYPE)); // section, default car type #endif //SPEED_DREAMS + oBotName = Value; // Get pointer to drivers name + oTeamName = GfParmGetStr // Get pointer to (RobotSettings // drivers team name , Section // defined in corresponding diff --git a/src/drivers/simplix/src/unitmain.cpp b/src/drivers/simplix/src/unitmain.cpp index 16161322..d6241b50 100644 --- a/src/drivers/simplix/src/unitmain.cpp +++ b/src/drivers/simplix/src/unitmain.cpp @@ -2,16 +2,20 @@ // unitmain.cpp //--------------------------------------------------------------------------* // TORCS: "The Open Racing Car Simulator" -// A robot for Speed Dreams-Version 1.4.0 +// A robot for Speed Dreams-Version 1.4.0/2.0 //--------------------------------------------------------------------------* // Interface to TORCS // // File : unitmain.cpp // Created : 2008.01.27 -// Last changed : 2009.12.22 -// Copyright : © 2007-2009 Wolf-Dieter Beelitz +// Last changed : 2010.09.25 +// Copyright : © 2007-2010 Wolf-Dieter Beelitz // eMail : wdb@wdbee.de -// Version : 2.00.000 +// Version : 2.00.001 +//--------------------------------------------------------------------------* +// V2.00.01 (Speed Dreams - Career mode): +// Uses new Speed Dreams Interfaces and was extended to use career mode +// - Still work in progress //--------------------------------------------------------------------------* // V2.00 (Speed Dreams): // Uses new Speed Dreams Interfaces @@ -178,6 +182,7 @@ typedef struct stInstanceInfo int cUnusedCount; } tInstanceInfo; +//#undef ROB_SECT_ARBITRARY #ifdef ROB_SECT_ARBITRARY static tInstanceInfo *cInstances; static int cInstancesCount; @@ -562,8 +567,6 @@ extern "C" int simplixShut() static int InitFuncPt(int Index, void *Pt) { tRobotItf *Itf = (tRobotItf *)Pt; // Get typed pointer - int xx; - tInstanceInfo *copy; Itf->rbNewTrack = InitTrack; // Store function pointers Itf->rbNewRace = NewRace; @@ -574,6 +577,9 @@ static int InitFuncPt(int Index, void *Pt) Itf->index = Index; // Store index #ifdef ROB_SECT_ARBITRARY + int xx; + tInstanceInfo *copy; + //Make sure enough data is allocated if (cInstancesCount <= Index-IndexOffset) { copy = new tInstanceInfo[Index-IndexOffset+1];