Page 1 of 1

Bug in AI Interfase and Segmentation fault, getTeamAllyTeam

Posted: 11 Aug 2014, 18:55
by playerO1
My spring crash when my bot call function getTeamAllyTeam with parameter -1.

Spring Engine version: 96.0
AI Interface Java: from Spring 94.1
infolog.txt fragment:

Code: Select all

[f=0006563] [*nickname*] but whats tithe the ai
[f=0006632] [*nickname*] or bot
[f=0006632] Error: Segmentation fault (SIGSEGV) in spring 96.0
[f=0006632] Error: Stacktrace for Spring 96.0:
[f=0006632] Error:   <0> ??:?
[f=0006632] Error:   <1> ??:?
[f=0006632] Error:   <2> /lib/x86_64-linux-gnu/libpthread.so.0(+0x10340) [0x7fc16b7e8340]
[f=0006632] Error:   <3> ??:?
[f=0006632] Error:   <4> [0x7fc11c2be790]
[f=0006632] Error: [ErrorMessageBox][1] msg="Spring has crashed:
Segmentation fault (SIGSEGV).
when *nickname* - spectator player name.
My Java code:

Code: Select all

@Override
public int message(int player, String message) {
  try {
  cpuTimer.start();
  ...
  some test with message with string function.
  ...
// crash call maybe this:
  if (clb.getGame().getTeamAllyTeam(clb.getGame().getPlayerTeam(player))!=clb.getGame().getTeamAllyTeam(owner.teamId)
            && !allowEnemyTeamCommand ) 
  {
    ...
  }
  ...
sendTextMsg("(test) Player " + player +" from team " +owner.clb.getGame().getPlayerTeam(player) + " say: '" + message+"'." , FieldBOT.MSG_DBG_ALL);
   cpuTimer.stop();
  } catch (Exception e) {
      sendTextMsg("ERROR message, exception: "+e.toString(), MSG_ERR);
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw);
        e.printStackTrace(pw); // print stack
      sendTextMsg("STACK TRACE> "+sw.toString(), MSG_ERR);
     cpuTimer.stop();
      return -1; // signaling: error
  }
    return 0; // signaling: OK
}
My bot log file fragment: "(test) Player 6 from team -1 say: 'but whats tithe the ai'."

I think the reason for bug is not exist range check in getGame().getTeamAllyTeam(-1), where player is spectator and clb.getGame().getPlayerTeam(player) return -1.
I do not want all Spring crash. I want throw AI Exception.

Re: Bug in AI Interfase and Segmentation fault, getTeamAllyT

Posted: 12 Aug 2014, 20:14
by abma
Spring Engine version: 96.0
AI Interface Java: from Spring 94.1
does it crash with spring 94.1, too?

mixing spring version & ai interface from different version very likely could cause such a crash when datatypes changed between versions...

current development version of spring contains the java interface, too!

Re: Bug in AI Interfase and Segmentation fault, getTeamAllyT

Posted: 13 Aug 2014, 13:06
by playerO1
Yes, it crash with spring 94.1, too. If I check (player!=-1) before call clb.getGame().getTeamAllyTeam(player) id doesn't crash and play next.
abma wrote:current development version of spring contains the java interface, too!
Do it work for linux 64 with Oracle Java (no OpenJDK)?

p.s. Test with 97 dev AI interface on Spring Engine 96 take crash too.

Re: Bug in AI Interfase and Segmentation fault, getTeamAllyT

Posted: 14 Aug 2014, 08:37
by hoijui
spring in general puts speed over "security" in many cases. you can not expect it to fail nicely in the Java AI Interface if you feed it illegal arguments. of course that would be nice, but ... better stay realistic in this regard.
of course you can submit a patch, and maybe someone will even change this for you, but i am sure there are thousands of other ways to make spring crash with illegal arguments, and that is very very low, at best, on the todo lists of any devs.

Re: Bug in AI Interfase and Segmentation fault, getTeamAllyT

Posted: 18 Aug 2014, 14:11
by playerO1
Ok, I undestand it is my problem.
Then how check ally player or enemy player truing?

I need good stable code for check:
1. This player is friend (ally) for me?
My code:

Code: Select all

    boolean allowThisCommand=allowEnemyTeamCommand ||
            (player!=-1 && owner.clb.getGame().getPlayerTeam(player)!=-1 &&
clb.getGame().getTeamAllyTeam(owner.clb.getGame().getPlayerTeam(player))==clb.getGame().getTeamAllyTeam(owner.teamId));
2. This player (bot) is spectator now?

Code: Select all

player==-1
and for me(bot):

Code: Select all

if (owner.clb.getSkirmishAI().getTeamId()==-1) do_I_am_now_spectator;
It is truing code? Or need use other functions, for example game.isAllied()?