Bug in AI Interfase and Segmentation fault, getTeamAllyTeam

Bug in AI Interfase and Segmentation fault, getTeamAllyTeam

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

Moderators: hoijui, Moderators

Post Reply
playerO1
Posts: 57
Joined: 25 Jun 2014, 15:22

Bug in AI Interfase and Segmentation fault, getTeamAllyTeam

Post 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.
abma
Spring Developer
Posts: 3798
Joined: 01 Jun 2009, 00:08

Re: Bug in AI Interfase and Segmentation fault, getTeamAllyT

Post 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!
playerO1
Posts: 57
Joined: 25 Jun 2014, 15:22

Re: Bug in AI Interfase and Segmentation fault, getTeamAllyT

Post 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.
User avatar
hoijui
Former Engine Dev
Posts: 4344
Joined: 22 Sep 2007, 09:51

Re: Bug in AI Interfase and Segmentation fault, getTeamAllyT

Post 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.
playerO1
Posts: 57
Joined: 25 Jun 2014, 15:22

Re: Bug in AI Interfase and Segmentation fault, getTeamAllyT

Post 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()?
Post Reply

Return to “AI”