New C++ AI Interface - Page 3

New C++ AI Interface

Here is where ideas can be collected for the skirmish AI in development

Moderators: hoijui, Moderators

User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: New C++ AI Interface

Post by hoijui »

cmake can generate VS project files.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: New C++ AI Interface

Post by AF »

I have to use this stuff in an environment where cmake is not available

Hence the visual studio requirement.

edit: that and I dont know what commands I would use to generate the wrappers and visual studio projects anyway. I'm on my home machine atm though it shouldnt require jumping through hoops when the legacy wrapper and C API use the same generation mechanism but dont require all this. I've installed gawk but I dont know what to do with that either
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: New C++ AI Interface

Post by hoijui »

Neither the C Interface nor the C AI Interface plugin need/use AWK.
what relies on AWK:
* Java AI Interface (plugin)
* Java OO Wrapper
* (New) C++ Wrapper

on windows, awk.exe/gawk.exe should be in your PATH, or under mingwlibs/bin (at least for MinGW, but it should also work otherwise, for awk).
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: New C++ AI Interface

Post by AF »

Using the new C++ interface, Ive found if you pass in a unit type to closestbuildsite that si invalid it crashes the engine, whereas before the new C API it would not crash adn instead return UpVector.

How would one check for this? In the past one would merely do an if(unitdef){ docall} on the unitdef pointer.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: New C++ AI Interface

Post by hoijui »

lets see how it works in pureint first.
its pretty far by now, only the Python AI Interface needs porting.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: New C++ AI Interface

Post by AF »

hmmm, how would I check beforehand though? I'd rather avoid the cost of any overhead and keep as much of my AI in Shard land for debugging purposes than to be hopping here there back and forth over the dll boundry

( That and the pureint branch would require a new spring release, whereas my need is here and now )
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: New C++ AI Interface

Post by hoijui »

with unittype, you mean unitdef?
this is called inside springai::Map::FindClosestBuildSite():

Code: Select all

unitDef.GetUnitDefId()
i don't know how you end up with an invalid UnitDef, but i can't debug this.
if the problem is inside the engine, then it would also need a new release.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: New C++ AI Interface

Post by AF »

Indeed, until then I can check beforehand and never call the engine if I have invalid parameters to pass.

Namely whenever someone misspells a unitname in Shard, then attempts to find a location to build it, the engine crashes inside closestbuildsite. The only logical explanation is an invalid unitdef structure caused by attempting to retrieve a unitdef for a unitname that has been misspelt.
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: New C++ AI Interface

Post by gajop »

AF wrote:Namely whenever someone misspells a unitname in Shard, then attempts to find a location to build it, the engine crashes inside closestbuildsite. The only logical explanation is an invalid unitdef structure caused by attempting to retrieve a unitdef for a unitname that has been misspelt.
I'm just guessing here, since I didn't bother to look at your code, but you probably have some mapping of std::string -> UnitDef or similar. It could be that since someone misspelled the name of the UnitDef you aren't getting a valid UnitDef? Are you checking to see whether the spelled unit exists in your mapping?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: New C++ AI Interface

Post by AF »

Code: Select all

IUnitType* CSpringGame::GetTypeByName(std::string typeName){
	std::map<std::string,CSpringUnitType*>::iterator i = definitions.find(typeName);
	if(i != definitions.end()){
		return i->second;
	}else{
		return 0;
	}
}
When I ask the engine for a unitdef providing a unitname string, it returns a unitdef object that is invalid. Is it safe to assume that the returned spring::unitdef pointer is a null pointer?
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: New C++ AI Interface

Post by gajop »

i glanced over your code from git, and from what i understand you never check to see whether it's a null pointer, eventually ending up sending it as a null pointer to lua
is that what you intended to do? i have no idea how swig handles c++ -> lua transitions of null pointers, does c/c++ null become nil in lua?
further, on a quick inspection, i'm not sure whether you're checking for nuill on all places, f.e:
http://github.com/Tarendai/Shard/blob/m ... ur.lua#L28
http://github.com/Tarendai/Shard/blob/m ... ur.lua#L46
(there are more examples, but you got the idea)
i'm assuming that one of those lua Build() or CanBuild() functions is asking for a misspelled unitDef causing an engine to receive a null pointer and crash, but i could be wrong ;p
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: New C++ AI Interface

Post by AF »

closestbuildsite is where all the crash reports sent to me have been, and my local copy has checks I havent pushed to github yet

Eitherway those are lua files, and Shards lua doesn't have access to the unitdef internals of those objects

In the meantime, there is error detection in the form of:

http://github.com/Tarendai/Shard/blob/m ... ur.lua#L87

Which should have caught it, but Ill have to look at how null is transferred across swig as you said

edit:
One final note: if a function returns a NULL pointer, this is not encoded as a userdata, but as a Lua nil.

Code: Select all

> f=example.fopen("not there","r") -- this will return a NULL in C
> print(f)
nil
http://www.swig.org/Doc1.3/Lua.html
gajop
Moderator
Posts: 3051
Joined: 05 Aug 2009, 20:42

Re: New C++ AI Interface

Post by gajop »

Well the two parts I mentioned are just string literals so that isn't getting checked anywhere before it's called, which might cause a problem.
But anyhow, it would be great if you could show some error logs you were sent to better pinpoint the source of the problem.
oh and btw, this is also one case:
http://github.com/Tarendai/Shard/blob/m ... ur.lua#L29
Other than that, I can't be of much help, all other references to unittype seem to be checking to see if it's nil, maybe whoever is complaining is running an older version?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Re: New C++ AI Interface

Post by AF »

There are checks already within Shards C++ portion meaning s would return false, and it is assumed that the string is good to go anyway because it is game specific
Post Reply

Return to “AI”