Page 1 of 1

didn't find a local variable: are you sure you called your f

Posted: Tue Nov 13, 2007 4:38 am
by Captain Segfault
The following code produces an exception:

Code: Select all

import java.util.Random;

public class wtfbot {
    public int orderType = 1; // always a move order
    public double destX, destY; // the move order will use these fields to communicate a destination
    public int[] radio = new int[4];

    public Object think(double dx, double dy, double x, double y, boolean moving, int terrain,
            int ourID, double hp, double maxHP, double range, double time,
            double[] objX, double[] objY, int[] objID, int[] objFaction, int[] objType, int[][] incomingRadio) {
        if (true) {
            int i0 = 0;
            int i1 = 0;
            double d0 = 0.0;
        }
        if (true ) {
            double d1 = 100000000;
            boolean boolwtf = false;
            double d2 = 100.0;
            if (boolwtf)
                d1 =42;

        }
        return this;
    }
    
    public int build(double dx, double dy, double x, double y, int terrain, int id, int buildItem,
            double hp, double maxHP, double time,
            double[] objX, double[] objY, int[] objID, int[] objFaction, int[] objType, int[][] incomingRadio) {
        return 1;
    }
}
The exception:

Code: Select all

didn't find a local variable: are you sure you called your function with correct args?
failure to think: ojvm.data.JavaException null
ojvm.data.JavaException
        at ojvm.operations.Exceptions.makeAndThrow(Exceptions.java:40)
        at ojvm.machine.ControlUnit.makeAndThrow(ControlUnit.java:212)
        at ojvm.operations.BytecodeInterpreter.visit_iload(BytecodeInterpreter.java:1509)
        at ojvm.loading.instructions.Ins_iload.accept(Ins_iload.java:32)
        at ojvm.machine.ControlUnit.run(ControlUnit.java:167)
        at org.hacker.engine.war.HackVMWarSpinalCord.think(HackVMWarSpinalCord.java:134)
        at org.hacker.engine.war.Faction.think(Faction.java:136)
        at org.hacker.engine.war.WarModel.step(WarModel.java:68)
        at org.hacker.engine.GameUI.stepToIt(GameUI.java:166)
        at org.hacker.engine.GameUI$5.run(GameUI.java:99)

Took a while to track this down this evening...

I suspect that the interpreter's handling of booleans is the root problem here. I had some problems with them in worm also...

Posted: Wed Nov 14, 2007 7:17 am
by adum
whew, this was an interesting bug to track down! turns out that under certain rare conditions, reuse of local variables for different types would cause it to invalidate some memory. i think i have fixed this -- the new SDK v 242 should work on this code.

this wasn't a problem with booleans, but i think i have seen that one before too. if you see it again, please post some sample code and i'll fix it.

thanks,
adum