2025-07-18 03:54 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0000362Spring engineAIpublic2010-11-23 01:42
ReporterKloot 
Assigned Totvo 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Product Version 
Target VersionFixed in Version 
Summary0000362: patch for rts/ExternalAI/GlobalAI.cpp
DescriptionAs described in http://taspring.clan-sy.com/phpbb/viewtopic.php?t=8746, AI destructors aren't always called because the value of IsCInterface isn't explicitly set to false in CGlobalAI::CGlobalAI() if _IsCInterface == 0. This patch corrects this, and also adds a check for the return value of an AI's exported IsCInterface function so that it's only considered to present a C interface if the function exists *and* returns 1.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • patch file icon GlobalAI.patch (3,559 bytes) 2007-01-04 14:46 -
    Index: GlobalAI.cpp
    ===================================================================
    --- GlobalAI.cpp	(revision 3061)
    +++ GlobalAI.cpp	(working copy)
    @@ -10,81 +10,80 @@
     #include "ExternalAI/GlobalAICInterface/AbicProxy.h"
     #include "LogOutput.h"
     
    -CGlobalAI::CGlobalAI(int team, const char* dll)
    -: team(team), cheatevents(false)
    -{
    -	ai=0;
     
    +CGlobalAI::CGlobalAI(int team, const char* dll): team(team), cheatevents(false) {
    +	ai = 0;
    +
     	if (!filesystem.GetFilesize(dll)) {
    -		handleerror(NULL,dll,"Could not find AI lib",MBF_OK|MBF_EXCL);
    +		handleerror(NULL, dll, "Could not find AI lib", MBF_OK | MBF_EXCL);
     		return;
     	}
     
     	lib = SharedLib::Instantiate(dll);
    +	_IsCInterface = (ISCINTERFACE) lib -> FindAddress("IsCInterface");
     
    -	// check if presents C interface
    -	_IsCInterface = (ISCINTERFACE)lib->FindAddress("IsCInterface");
    -	if( _IsCInterface != 0 )
    -	{
    +	// check if IsCInterface function exported and return value true
    +	if ( _IsCInterface != 0 && _IsCInterface() == 1) {
     		// presents C interface
    -        logOutput << dll <<  " has C interface\n";
    +		logOutput << dll <<  " has C interface\n";
     		IsCInterface = true;
    -		AbicProxy* ai=SAFE_NEW AbicProxy; // keep as AbicProxy, so InitAI works ok
    -		this->ai = ai;
    -		gh=SAFE_NEW CGroupHandler(team);
    -		callback=SAFE_NEW CGlobalAICallback(this);
    -		ai->InitAI(dll,callback,team);
    +
    +		// keep as AbicProxy, so InitAI works ok
    +		AbicProxy* ai = SAFE_NEW AbicProxy;
    +		this -> ai = ai;
    +
    +		gh = SAFE_NEW CGroupHandler(team);
    +		callback = SAFE_NEW CGlobalAICallback(this);
    +		ai -> InitAI(dll, callback, team);
     	}
    -	else
    -	{
    +	else {
     		// presents C++ interface
     		logOutput << dll <<  " has C++ interface\n";
    +		IsCInterface = false;
    +	
    +		GetGlobalAiVersion = (GETGLOBALAIVERSION) lib -> FindAddress("GetGlobalAiVersion");
     
    -		GetGlobalAiVersion = (GETGLOBALAIVERSION)lib->FindAddress("GetGlobalAiVersion");
    -		if (GetGlobalAiVersion==0){
    -			handleerror(NULL,dll,"Incorrect Global AI dll",MBF_OK|MBF_EXCL);
    +		if (GetGlobalAiVersion == 0) {
    +			handleerror(NULL, dll, "Incorrect Global AI dll", MBF_OK|MBF_EXCL);
     			return;
     		}
    +		
    +		int i = GetGlobalAiVersion();
     
    -		int i=GetGlobalAiVersion();
    -
    -		if (i!=GLOBAL_AI_INTERFACE_VERSION){
    -			handleerror(NULL,dll,"Incorrect Global AI dll version",MBF_OK|MBF_EXCL);
    +		if (i != GLOBAL_AI_INTERFACE_VERSION) {
    +			handleerror(NULL, dll, "Incorrect Global AI dll version", MBF_OK | MBF_EXCL);
     			return;
     		}
     
    -		GetNewAI = (GETNEWAI)lib->FindAddress("GetNewAI");
    -		ReleaseAI = (RELEASEAI)lib->FindAddress("ReleaseAI");
    +		GetNewAI = (GETNEWAI) lib -> FindAddress("GetNewAI");
    +		ReleaseAI = (RELEASEAI) lib -> FindAddress("ReleaseAI");
     
    -		ai=GetNewAI();
    -		gh=SAFE_NEW CGroupHandler(team);
    -		callback=SAFE_NEW CGlobalAICallback(this);
    -		ai->InitAI(callback,team);
    +		ai = GetNewAI();
    +		gh = SAFE_NEW CGroupHandler(team);
    +		callback = SAFE_NEW CGlobalAICallback(this);
    +		ai -> InitAI(callback, team);
     	}
     }
     
    -void CGlobalAI::PreDestroy ()
    -{
    -	callback->noMessages = true;
    +void CGlobalAI::PreDestroy () {
    +	callback -> noMessages = true;
     }
     
    -CGlobalAI::~CGlobalAI(void)
    -{
    -	if(ai){
    -		if( !IsCInterface )
    -		{
    +CGlobalAI::~CGlobalAI(void) {
    +	if (ai) {
    +		if (!IsCInterface) {
     			ReleaseAI(ai);
    -		}// note to self: ideally should clean up c interface too
    +		}
    +
     		delete lib;
     		delete callback;
     		delete gh;
     	}
     }
     
    -void CGlobalAI::Update(void)
    -{
    -	gh->Update();
    -	ai->Update();
    +void CGlobalAI::Update(void) {
    +	gh -> Update();
    +	ai -> Update();
     }
     
     IMPLEMENT_PURE_VIRTUAL(IGlobalAI::~IGlobalAI())
    
    patch file icon GlobalAI.patch (3,559 bytes) 2007-01-04 14:46 +

-Relationships
+Relationships

-Notes

~0000524

tvo (reporter)

committed.

Next time, could you not add spaces around the "->" operator, and put the function opening brace on a separate line, ie. like this:

void CGlobalAI::Update(void)
{
    gh->Update();
    ai->Update();
}

Not this:

void CGlobalAI::Update(void) {
    gh -> Update();
    ai -> Update();
}

Also it would be great if you could keep (major) whitespace cleanup separated from actual code changes, mixing them both makes it very hard to properly review a patch.

Thanks
+Notes

-Issue History
Date Modified Username Field Change
2007-01-04 14:46 Kloot New Issue
2007-01-04 14:46 Kloot File Added: GlobalAI.patch
2007-01-04 20:33 tvo Status new => resolved
2007-01-04 20:33 tvo Resolution open => fixed
2007-01-04 20:33 tvo Assigned To => tvo
2007-01-04 20:33 tvo Note Added: 0000524
2010-11-22 22:59 abma Project AI => Spring engine
2010-11-22 23:11 abma Project Spring engine => AI
2010-11-23 01:42 abma Project AI => Spring engine
+Issue History