2024-04-18 16:19 CEST

View Issue Details Jump to Notes ]
IDProjectCategoryView StatusLast Update
0003483Spring engineAIpublic2013-02-26 20:21
Reportercranphin 
Assigned Toabma 
PrioritynormalSeverityminorReproducibilityalways
StatusresolvedResolutionfixed 
Product Version92.0.1+git 
Target VersionFixed in Version 
Summary0003483: Get null as unit in JavaOO-AIWrapper.jar for team 1
DescriptionWhen I run a Java AI using JavaOO-AIWrapper.jar, with two teams (and one spectator), I get 'null' as first argument in the com.springrts.ai.oo.OOAI.unitCreated callback, for the first commander created.
Instead it should've given a Unit instance.

This happens on this build (latest I could find): spring-92.0.1-62-gc96d6b0.

I think this happens because the first unit gets id '0', and the Java OO wrapper expects to get 0 for "no unit", so returns null.
The reason I think this, is that if I build a minimal Java AI, without the OO wrapper, which only logs, I see a '0' id for only exactly the commander of team 1, which is where I get the null for.
If I manually build something (/cheat,/godmode), later units get higher id's.
I'll attach the script and (my own) log for that test run.

So mayby 0 used to be 'no unit', and now it's -1, and the Java OO wrapper didn't get updated for this, could that be the case?

The relevant classes from Spring are com.springrts.ai.oo.AIOO, and especially com.springrts.ai.oo.WrappUnit.getInstance(), I think, don't have the source here, since it's generated source (if I remember well).

If someone wants the logging java AI I used to test, or anything else, just ask.
TagsNo tags attached.
Checked infolog.txt for Errors
Attached Files
  • txt file icon test_script.txt (853 bytes) 2013-02-20 21:54 -
    [game]
    {
        gametype=Balanced Annihilation V7.72;
        mapname=Altored_Divide;
        myplayername=Supervisor;
        nohelperais=0;
        ishost=1;
        [player0]
        {
            name=Supervisor;
    	Spectator=1;
            team=0;
        }
        [ai0] 
    	{
            host=0;
            name=MrA;
            shortname=LogJavaAI;
            team=1;
            version=0.1;
        }
        [ai1] 
    	{
            host=0;
            name=MrB;
            shortname=KAIK;
            team=0;
            version=0.13;
        }
        [allyteam0]
        {
            numallies=0;
        }
        [allyteam1]
        {
            numallies=0;
        }
        [team0]
        {
            allyteam=0;
            teamleader=0;
            Side=Core;
        }
        [team1]
        {
            allyteam=1;
            teamleader=0;
            Side=Core;
        }
        [modoptions]
        {
            gamemode=3;
            maxspeed=20;
        }
    }
    
    txt file icon test_script.txt (853 bytes) 2013-02-20 21:54 +
  • log file icon main.log (451 bytes) 2013-02-20 21:54

-Relationships
related to 0003485closedKloot UnitIDs must be >=1 but are >=0 atm 
+Relationships

-Notes

~0009868

cranphin (reporter)

Attached my little test log, note this line:
init - DEBUG main com.springrts.ai.logai.LogAI - Unit created: unit: 0 builder: -1
So the unit id given is '0'.

Interestingly, the builder id is -1 (no builder for a commander), so it would seem the Java OO wrapper should handle '0' as a unit, '-1' as no unit.
But right now it seems to handle '0' as no unit.

~0009869

cranphin (reporter)

The source for the AI in the little test I did:
http://code.google.com/p/crans-java-ai/source/browse/#svn%2FLogJavaAI%2Ftrunk

~0009870

Kloot (developer)

Units getting assigned sequential (instead of random as before) id's starting at 0 is a bug which I will fix, but regardless no AI wrapper code should ever treat id 0 as a special value. I don't much feel like digging into that though...

~0009871

cranphin (reporter)

I'll dig then ^_^
https://github.com/spring/spring/blob/develop/AI/Wrappers/JavaOO/bin/wrappCallback.awk
There's this bit:
    print("\t" "public static " clsName_c " getInstance(" ctorParams ") {") >> outFile_jni_c;
print("") >> outFile_jni_c;
lastParamName = ctorParamsNoTypes;
sub(/^.*,[ \t]*/, "", lastParamName);
if (match(lastParamName, /^[^ \t]+Id$/)) {
if (clsName_c == "Unit") {
# the first valid unit ID is 1
print("\t\t" "if (" lastParamName " <= 0) {") >> outFile_jni_c;
} else {
# ... for all other IDs, the first valid one is 0
print("\t\t" "if (" lastParamName " < 0) {") >> outFile_jni_c;
}
print("\t\t\t" "return null;") >> outFile_jni_c;
print("\t\t" "}") >> outFile_jni_c;
print("") >> outFile_jni_c;
}

Remove the exception for "if (clsName_c == "Unit") {", and you should be done :)

~0009877

abma (administrator)

@cranphin:

can you check if the latest build works for you?
http://springrts.com/dl/buildbot/default/release/92.0-25-g0f187f0/

~0009940

cranphin (reporter)

Oops, didn't notice the request, still had an old (defunc) email here :)
'spring-92.0-33-g2be1d86' works for me, is that enough?
Otherwise place another comment with a version, and I'll check that when I've got more time :)
+Notes

-Issue History
Date Modified Username Field Change
2013-02-20 21:54 cranphin New Issue
2013-02-20 21:54 cranphin File Added: test_script.txt
2013-02-20 21:54 cranphin File Added: main.log
2013-02-20 21:56 cranphin Note Added: 0009868
2013-02-20 22:03 cranphin Note Added: 0009869
2013-02-20 23:00 Kloot Note Added: 0009870
2013-02-20 23:31 cranphin Note Added: 0009871
2013-02-21 12:56 abma Changeset attached => spring release 423cdaa4
2013-02-21 12:56 abma Assigned To => abma
2013-02-21 12:56 abma Status new => resolved
2013-02-21 12:56 abma Resolution open => fixed
2013-02-22 01:32 abma Relationship added related to 0003485
2013-02-22 12:07 abma Note Added: 0009877
2013-02-22 12:07 abma Status resolved => feedback
2013-02-22 12:07 abma Resolution fixed => reopened
2013-02-26 20:17 cranphin Note Added: 0009940
2013-02-26 20:17 cranphin Status feedback => assigned
2013-02-26 20:21 abma Status assigned => resolved
2013-02-26 20:21 abma Resolution reopened => fixed
+Issue History