Missing helper AIs should clear group rather than crash

Missing helper AIs should clear group rather than crash

Discuss the source code and development of Spring Engine in general from a technical point of view. Patches go here too.

Moderator: Moderators

Post Reply
YokoZar
Posts: 883
Joined: 15 Jul 2007, 22:02

Missing helper AIs should clear group rather than crash

Post by YokoZar »

Suppose you and your teammate are playing a game, and your teammate uses weird_helper.dll and assigns it to a unit.

Then, he crashes or disconnects. You, then, do a .take of his units. This in turn leads to you taking a unit with weird_helper.dll, which you don't have.

The game will then crash and spit out this missing AI, leading to your next teammate taking your units and suffering the same fate.


There's no need for this. It should be fairly simple to catch this exception and just clear the group for the missing AI, perhaps spitting out a warning in the process.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

+1 This is a must.

However there is an AI side fix. Exception handling. I use it as a failsafe for my AIs so that if they crash the AI can catch the error and display a message and proceed to shut itself down so the player can carry on playing.
YokoZar
Posts: 883
Joined: 15 Jul 2007, 22:02

Post by YokoZar »

AF wrote:+1 This is a must.

However there is an AI side fix. Exception handling. I use it as a failsafe for my AIs so that if they crash the AI can catch the error and display a message and proceed to shut itself down so the player can carry on playing.
True. But we should still fix the problem, especially because of the terrible exploit I just thought of:
  • Create stupid_ai.dll that no one has.
  • Assign stupid_ai.dll to a peewee and give to opponent.
  • Opponent crashes.
Actually, for irony purposes, you should probably use a crasher instead of a peewee.
imbaczek
Posts: 3629
Joined: 22 Aug 2006, 16:19

Post by imbaczek »

Hopefully it's fixed, I disabled transferring groups between players. See mantis #596.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

AF wrote:+1 This is a must.

However there is an AI side fix. Exception handling. I use it as a failsafe for my AIs so that if they crash the AI can catch the error and display a message and proceed to shut itself down so the player can carry on playing.
Erm, no.

The bug is that Spring crashes if the Group AI DLL is not available on the other PC, so there is no way you can fix this AI side, definitely not with exception handling.
CautionToTheWind
Posts: 272
Joined: 30 May 2006, 17:06

Post by CautionToTheWind »

This is an excellent example of a very small bug that gets out of hand. The cascade failure is really one of those "oh fuck" moments for the programmer.
YokoZar wrote:
  • Create stupid_ai.dll that no one has.
  • Assign stupid_ai.dll to a peewee and give to opponent.
  • Opponent crashes.
Actually, for irony purposes, you should probably use a crasher instead of a peewee.
Hehe, thankfully i think you can't give units to enemies without .cheat since the latest version.
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

Tobi, theyre not the same bug.

Yokozars talking about an exploit, crash caused by spring

What Im talking about is when the AI itself is at fault and spring unnecessarily exits.

Code: Select all

CGroupAI::Update(){
    int* a = new in[5];
    a[20]=4;
}
This would cause a crash in the groupAI. This would then be caught by spring. Spring would then exit unnecessarily. Instead it should remove the AI from the game and continue.

I said try catch because:

Code: Select all

CGroupAI::Update(){
    if(active==false) return;
    try{
        int* a = new in[5];
        a[20]=4;
    }catch(...){
        cb->SendTxtMgs("This AI has crashed",0);
        active=false;
    }
}
Thus the error is caught by the AI and the AI deactivates itself.
Tobi
Spring Developer
Posts: 4598
Joined: 01 Jun 2005, 11:36

Post by Tobi »

I know what you are talking about but it is totally unrelated to this bug, which was my point.

Also as I already explained a long time ago, try catch blocks do not catch segfaults or other signals (unless SEH is enabled but that's MSVC specific), they only catch exceptions.

Code: Select all

$ cat test.cpp
#include <iostream>
using std::cout;
using std::endl;

int main()
{
    try{
        int* a = NULL;
        *a=10;
        cout << "no exceptions caught" << endl;
    }catch(...){
        cout << "caught exception" << endl;
    }
    return 0;
}

$ g++ test.cpp -o test
$ ./test
Segmentation fault (core dumped)
YokoZar
Posts: 883
Joined: 15 Jul 2007, 22:02

Post by YokoZar »

imbaczek wrote:Hopefully it's fixed, I disabled transferring groups between players. See mantis #596.
.take should take his helper AIs though, if the taking player has them. There's no reason to clear the metal maker AI after .take, and users would likely think it a bug if it were.

As for units given away, sure, clearing the AI is fine.
YokoZar
Posts: 883
Joined: 15 Jul 2007, 22:02

Post by YokoZar »

Another thought: make sure the taker has the same version of the AI, otherwise you might want to clear it instead.
User avatar
KDR_11k
Game Developer
Posts: 8293
Joined: 25 Jun 2006, 08:44

Post by KDR_11k »

Isn't Metal Maker Lua better than Metal Maker AI, anyway?
User avatar
AF
AI Developer
Posts: 20687
Joined: 14 Sep 2004, 11:32

Post by AF »

indeed
Post Reply

Return to “Engine”