View Issue Details

IDProjectCategoryView StatusLast Update
0002073Spring engineAIpublic2010-11-23 01:40
Reporteroksnoop2 Assigned Toabma  
PrioritynormalSeveritycrashReproducibilityalways
Status closedResolutionno change required 
Product Version0.82.6.1 
Summary0002073: Broken AI API
DescriptionSpring's API seems to not work with regards to AI to gadget communication. When attempting to make Shard morph a unit the engine will crash.
TagsNo tags attached.
Attached Files
infolog.txt (Attachment missing)
Shard.7z (Attachment missing)
Checked infolog.txt for Errors

Relationships

related to 0002043 closed Startup crash with Shard 

Activities

AF

2010-09-02 22:07

reporter   ~0005419

I have investigated this, and the response is an unrelated statement regarding Shards compilation on Linux not working in a previous version of spring. I have investigated this and fiddled with parameters on my end with no result, only a crash somewhere in the engine. It is 100% reproducible.

Reproduction should not require a Linux build of Shard, 5-7 lines of code in the Init function of the C++ Wrapper Null test AI would work just as well.

If it is found that the API is demonstrably working, I would like to see documentation showing the correct usage of the API callout.

AF

2010-09-02 22:08

reporter   ~0005420

I may also add that I have been accused of fobbing this bug off on Hoijui because I cant be arsed fixing my own AI, and have been told it is none of his business. My response is that it is an API bug, and he is the API author and API maintainer.

abma

2010-11-11 19:19

administrator   ~0005858

please add an infolog.txt with the stacktrace of the crash...

abma

2010-11-18 13:24

administrator   ~0005877

is this file complete?

there are lines missing after

[ 0] Stacktrace:


:-/

how can i reproduce the bug?

oksnoop2

2010-11-20 19:34

reporter   ~0005884

Last edited: 2010-11-20 19:35

I have added shard. Now just get conflict terra from googlecode.
http://code.google.com/p/conflictterra/

abma

2010-11-22 00:35

administrator   ~0005902

Last edited: 2010-11-22 00:38

i get:

PANIC: unprotected error in call to Lua API (attempt to index a nil value)

to reproduce, get into 0.82 source tree:
git://github.com/Tarendai/Shard.git and run with conflict terra mod

looks like lua isn't initialized correctly somewhere...

abma

2010-11-22 00:48

administrator   ~0005903

Last edited: 2010-11-22 00:49

hm... looks like shrad's fault: comment out Shard/lua/ldo.c

line 107:

// exit(EXIT_FAILURE);


then it doesn't crash / exit. -> ("only" an endless-loop)

AF

2010-11-22 13:34

reporter   ~0005916

That makes no sense, the crash occurred inside the engine, so why is a piece of my code at fault? I've already followed it in the debugger through SWIG and into the C++ portion of the code, and it crashes in the interface on the call, but never returns, so it could not be Shards code, but more importantly it shouldnt.

Shards lua code shouldn't be being called anywhere inside the engine, or even being linked, as my lua VM isn't the same as the spring lua VM, so the exit(EXIT_FAILURE); should be unreachable from the interface because the interface was never linked and compiled to it (or at least that is how it should be).

AF

2010-11-22 13:36

reporter   ~0005917

Also did you checkout the whole repo or just the src folders contents? There's a chunk of data files in there that need moving and a cmake you need to account for, its not just a binary blob like some other native AIs, it has a tonne of lua code files too that need placing in /AI/Shard/dev/ai ( IIRC the path) of your spring install/test environment

abma

2010-11-22 17:03

administrator   ~0005921

Last edited: 2010-11-22 19:52

i did in spring source dir:

git checkout git://github.com/Tarendai/Shard.git AI/Skirmish/Shard
cmake .
make install
 
and then run it from the installed dir...

is the attached infolog.txt snipped? there is no stacktrace...

i think you're lua usage is also wrong:

http://www.lua.org/manual/5.1/manual.html#7.3

and you're using "luaopen_api(L);"

$ ls ~/local/spring/stable/share/games/spring/AI/Skirmish/Shard/dev/ai/

http://pastebin.com/7W6YEn2v

abma

2010-11-22 17:06

administrator   ~0005922

Last edited: 2010-11-22 17:09

as note: i think this way it happens: ai calls exit -> the current running thread exits, then the main thread segfaults, because all calls to the ai fails / access violation.

AF

2010-11-22 18:38

reporter   ~0005937

That's not correct at all, shards Lua VM is not the same as springs lua VM, it should never reach that point fullstop.

Also, the AI does not run in a separate thread from the simulation, and when I run shard her. I get a crash, not an exit.

AF

2010-11-22 18:40

reporter   ~0005938

I know this because when the lua code in shard loads a file via 'require', if this fails then exit() is called. If you are correct then this would duplicate the crash. This does not happen. Instead the engine exits, and the last thing in infolog.txt is the error message for the failed require giving a lua stack trace and description of whatever syntax error caused it to fail.

AF

2010-11-22 18:44

reporter   ~0005939

I have followed the line of execution as far as I can in the visual studio debugger, and the crash occurs within a C++ portion of the code, to be precise inside the API call to the engine, after which I don't have the means to figure out what code the stack trace is referring to because of the compiler differences. Shards lua code cannot w the cause because it should not be in the engine and the call never returns, so it never leaves the C code because of the crash.

If you are getting traces leading from engine code directly into shards lua then something has been compiled horribly wrong. All of shards lua is wrapped around by the C++ portion of the Shard AI. The shard lua VM does not use the same codebase as the spring lua VM, they are not the same instances and the two should never mix, and bydefinition should never even be able to mix

abma

2010-11-22 19:48

administrator   ~0005940

Last edited: 2010-11-22 20:07

i get this exit within linux (ubuntu 10.4 to be more specific). i think, you're using windows?

when i run win32 spring with wine i get this:

http://pastebin.com/TfZev168

but this still looks like an crash in the ai...


1. ok, then why the exit() get's called?
2. you're ai should be a bit more verbose to identify bugs/missing files,is there somewhere a logfile?
3. and why you don't get a stacktrace?
4. did you try to comment out exit()?

AF

2010-11-22 21:08

reporter   ~0005945

I did get a stack trace, but since oksnoop is the one who retested on latest spring I dont have a copy relevant to current spring.

std::string CSpringGame::SendToContent(std::string data){
    SCallLuaRulesCommand c;
    c.data = data.c_str();
    c.inSize = -1;
    // The next line calls the engine, this is the last call to be made before the crash
    callback->GetEngine()->HandleCommand(callback->GetTeamId(),-1,COMMAND_CALL_LUA_RULES,&c);
    //this line is never reached
    return c.ret_outData;
}

By definition, no lua can be ran by Shard here because it is in the middle of a C++ call, one that goes out to the engine, not Shards internals. The only lua executed ehre is in lua gadget/widget land over in the spring executable. If Shard source for lua has been found during this call then please provide a stack trace I can interpret showing where the code re-enters the Shard AI, otherwise, I can only assume Shard still isnt building correctly as a result of Spring muddling up the lua source for Shard lua and Spring lua, which are not the same, and are pretty much a guaranteed crash at startup.

AF

2010-11-22 21:17

reporter   ~0005946

I suggest you take the generic function I gave you and put it in an empty C++ api AI. There is already one in the spring git repo, it should be a copy paste operation, either way what you are describing is impossible, and defies the very reasoning behind Shards creation in the first place.

In the CPPTestAI, use the following constructor:

cpptestai::CCppTestAI::CCppTestAI(springai::AICallback* callback):
        callback(callback),
        teamId(callback != NULL ? callback->GetTeamId() : -1)
        {
            SCallLuaRulesCommand c;
            c.data = "hello gadget world, Im a native C++ AI";
            c.inSize = -1;
            callback->GetEngine()->HandleCommand(callback->GetTeamId(),-1,COMMAND_CALL_LUA_RULES,&c);

            SSendTextMessageCommand cmd;
            cmd.text = c.ret_outData;
            cmd.zone = 0;
            callback->GetEngine()->HandleCommand(0, -1, COMMAND_SEND_TEXT_MESSAGE, &cmd);
        }

The expected behaviour of this is that a callin will occur on all gadgets in the game with the value "hello gadget world, Im a native C++ AI", the response of which will then be returned to the AI and printed to the console. Since its assumed no gadgets will be listening, nothing should happen. Actual behaviour suggests the result currently is a hard crash.

abma

2010-11-22 21:46

administrator   ~0005949

it works in 0.82.6.1... no crash...

AF

2010-11-22 22:26

reporter   ~0005950

Can you please post a stack trace showing how the path of execution reached the EXIT() in Shard?

abma

2010-11-22 22:34

administrator   ~0005951

Last edited: 2010-11-22 22:42

Thread 1 (Thread 0x7f79a4485780 (LWP 18340)):
#0 0x00007f79aa33afbd in __libc_waitpid (pid=18346, stat_loc=<value optimized out>, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:41
#1 0x00007f79aa2d27e9 in do_system (line=<value optimized out>) at ../sysdeps/posix/system.c:149
#2 0x00007f79aa2d2b20 in __libc_system (line=<value optimized out>) at ../sysdeps/posix/system.c:190
0000003 0x00007f798ba24a31 in luaD_throw (L=0x7f799795c560, errcode=2) at /home/abma/dev/spring/stable/AI/Skirmish/Shard/src/lua/ldo.c:108
0000004 0x00007f798ba1a9c8 in luaG_errormsg (L=0x7f799795c560) at /home/abma/dev/spring/stable/AI/Skirmish/Shard/src/lua/ldebug.c:627
0000005 0x00007f798ba1aaba in luaG_runerror (L=0x7f799795c560, fmt=0x7f798ba9e0cb "attempt to %s a %s value")
    at /home/abma/dev/spring/stable/AI/Skirmish/Shard/src/lua/ldebug.c:636
#6 0x00007f798ba1a664 in luaG_typeerror (L=0x7f799795c560, o=0x7f7997933df0, op=0x7f798ba9f806 "index")
    at /home/abma/dev/spring/stable/AI/Skirmish/Shard/src/lua/ldebug.c:577
#7 0x00007f798ba2b6eb in luaV_gettable (L=0x7f799795c560, t=0x7f7997933df0, key=0x7fffa9ca4b60, val=0x7f7997933e00)
    at /home/abma/dev/spring/stable/AI/Skirmish/Shard/src/lua/lvm.c:123
---Type <return> to continue, or q <return> to quit---
#8 0x00007f798ba12f02 in lua_getfield (L=0x7f799795c560, idx=-1, k=0x7f798baa08e1 "Init") at /home/abma/dev/spring/stable/AI/Skirmish/Shard/src/lua/lapi.c:551
#9 0x00007f798ba3d9fa in CTestAI::Init (this=0x7f79976b8df0) at /home/abma/dev/spring/stable/AI/Skirmish/Shard/src/TestAI.cpp:137
0000010 0x00007f798ba3196b in cpptestai::CCppTestAI::HandleEvent (this=0x7f7997822920, topic=1, data=0x7fffa9ca4e10)
    at /home/abma/dev/spring/stable/AI/Skirmish/Shard/src/CppTestAI.cpp:44
#11 0x00007f798ba36616 in handleEvent (teamId=1, topic=1, data=0x7fffa9ca4e10) at /home/abma/dev/spring/stable/AI/Skirmish/Shard/src/AIExport.cpp:89
0000012 0x0000000000e4402b in CSkirmishAILibrary::HandleEvent (this=0x7f79976b2250, teamId=1, topic=1, data=0x7fffa9ca4e10)
    at /home/abma/dev/spring/stable/rts/ExternalAI/SkirmishAILibrary.cpp:87
0000013 0x0000000000e2bd1c in CSkirmishAI::HandleEvent (this=0x7f7997852cd0, topic=1, data=0x7fffa9ca4e10) at /home/abma/dev/spring/stable/rts/ExternalAI/SkirmishAI.cpp:48
0000014 0x0000000000e55173 in CSkirmishAIWrapper::Init (this=0x7f799795d650) at /home/abma/dev/spring/stable/rts/ExternalAI/SkirmishAIWrapper.cpp:177
#15 0x0000000000e4c2fb in CEngineOutHandler::CreateSkirmishAI (this=0x7f7996884070, skirmishAIId=0) at /home/abma/dev/spring/stable/rts/ExternalAI/EngineOutHandler.cpp:522
#16 0x0000000000e30ded in CSkirmishAIHandler::CreateLocalSkirmishAI (this=0x22bb640, skirmishAIId=0) at /home/abma/dev/spring/stable/rts/ExternalAI/SkirmishAIHandler.cpp:184
#17 0x00000000007da557 in CGame::StartPlaying (this=0x2405120) at /home/abma/dev/spring/stable/rts/Game/Game.cpp:3534
#18 0x00000000007db38c in CGame::ClientReadNet (this=0x2405120) at /home/abma/dev/spring/stable/rts/Game/Game.cpp:3742
#19 0x00000000007d67d8 in CGame::Update (this=0x2405120) at /home/abma/dev/spring/stable/rts/Game/Game.cpp:2830
0000020 0x0000000000d8110d in SpringApp::Update (this=0x7fffa9ca5d00) at /home/abma/dev/spring/stable/rts/System/SpringApp.cpp:1051
#21 0x0000000000d814cb in SpringApp::Run (this=0x7fffa9ca5d00, argc=1, argv=0x7fffa9ca5e78) at /home/abma/dev/spring/stable/rts/System/SpringApp.cpp:1182
#22 0x0000000000d85dbf in Run (argc=1, argv=0x7fffa9ca5e78) at /home/abma/dev/spring/stable/rts/System/Main.cpp:55
#23 0x0000000000d85f17 in main (argc=1, argv=0x7fffa9ca5e78) at /home/abma/dev/spring/stable/rts/System/Main.cpp:90

abma

2010-11-22 22:35

administrator   ~0005952

note: i replaced exit with system("sleep 10000");

AF

2010-11-22 22:54

reporter   ~0005953

pull from Shard master, I've made changes regarding the lua you mentioned before and extra logging for missing files on load

abma

2010-11-22 23:06

administrator   ~0005954

Last edited: 2010-11-22 23:17

<SkirmishAI: Shard dev (team 1)>: error loading "/home/abma/local/spring/stable/share/games/spring/AI/Skirmish/Shard/dev\ai\ai.lua" with error code: 


ehm... can you please contact me in lobby? abma or abma_irc? should be easier... if i'm not there, continue here ... :)

abma

2010-11-23 00:39

administrator   ~0005955

fixed in current shard version, thanks AF! :)

Issue History

Date Modified Username Field Change
2010-09-02 21:47 oksnoop2 New Issue
2010-09-02 22:07 AF Note Added: 0005419
2010-09-02 22:08 AF Note Added: 0005420
2010-11-11 19:19 abma Note Added: 0005858
2010-11-17 01:12 oksnoop2 File Added: infolog.txt
2010-11-18 13:24 abma Note Added: 0005877
2010-11-20 19:34 oksnoop2 File Added: Shard.7z
2010-11-20 19:34 oksnoop2 Note Added: 0005884
2010-11-20 19:35 oksnoop2 Note Edited: 0005884
2010-11-22 00:35 abma Note Added: 0005902
2010-11-22 00:38 abma Note Edited: 0005902
2010-11-22 00:48 abma Note Added: 0005903
2010-11-22 00:49 abma Note Edited: 0005903
2010-11-22 11:16 abma Relationship added related to 0002043
2010-11-22 13:34 AF Note Added: 0005916
2010-11-22 13:36 AF Note Added: 0005917
2010-11-22 17:03 abma Note Added: 0005921
2010-11-22 17:06 abma Note Added: 0005922
2010-11-22 17:09 abma Note Edited: 0005922
2010-11-22 17:09 abma Note Edited: 0005922
2010-11-22 18:38 AF Note Added: 0005937
2010-11-22 18:40 AF Note Added: 0005938
2010-11-22 18:44 AF Note Added: 0005939
2010-11-22 19:48 abma Note Added: 0005940
2010-11-22 19:49 abma Note Edited: 0005940
2010-11-22 19:49 abma Note Edited: 0005940
2010-11-22 19:51 abma Note Edited: 0005940
2010-11-22 19:52 abma Note Edited: 0005921
2010-11-22 19:53 abma Note Edited: 0005940
2010-11-22 19:55 abma Note Edited: 0005940
2010-11-22 19:56 abma Note Edited: 0005940
2010-11-22 20:00 abma Note Edited: 0005940
2010-11-22 20:07 abma Note Edited: 0005940
2010-11-22 21:08 AF Note Added: 0005945
2010-11-22 21:17 AF Note Added: 0005946
2010-11-22 21:46 abma Note Added: 0005949
2010-11-22 22:26 AF Note Added: 0005950
2010-11-22 22:34 abma Note Added: 0005951
2010-11-22 22:35 abma Note Added: 0005952
2010-11-22 22:42 abma Note Edited: 0005951
2010-11-22 22:54 AF Note Added: 0005953
2010-11-22 23:06 abma Note Added: 0005954
2010-11-22 23:06 abma Note Edited: 0005954
2010-11-22 23:17 abma Note Edited: 0005954
2010-11-23 00:39 abma Note Added: 0005955
2010-11-23 00:39 abma Status new => resolved
2010-11-23 00:39 abma Resolution open => not fixable
2010-11-23 00:39 abma Assigned To => abma
2010-11-23 00:57 Kloot Status resolved => feedback
2010-11-23 00:57 Kloot Resolution not fixable => reopened
2010-11-23 00:57 Kloot Status feedback => closed
2010-11-23 00:57 Kloot Resolution reopened => no change required
2010-11-23 01:40 abma Project AI => Spring engine
2010-11-23 01:40 abma Product Version => 0.82.6.1