flaing / jnibwapi

Automatically exported from code.google.com/p/jnibwapi
0 stars 0 forks source link

bwapi.getAllUnits() returning an empty collection every odd frame #10

Closed GoogleCodeExporter closed 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
public void gameUpdate() 
{
    System.out.println("frame:" + bwapi.getFrameCount() + ", UnitCount:" + bwapi.getAllUnits().size());
}           

What is the expected output? What do you see instead?
Should see:
frame:0, UnitCount:0
frame:0, UnitCount:132
frame:1, UnitCount:19
frame:2, UnitCount:19
frame:3, UnitCount:19
...

What happens:
frame:0, UnitCount:0
frame:0, UnitCount:132
frame:1, UnitCount:0
frame:2, UnitCount:19
frame:3, UnitCount:0
frame:4, UnitCount:19
frame:5, UnitCount:0
frame:6, UnitCount:19
frame:7, UnitCount:0
frame:8, UnitCount:19
frame:9, UnitCount:0
...

What version of the product are you using? On what operating system?
r12, XP, eclipse

Please provide any additional information below.
No idea what's causing it at this stage. Other game data might also have issues 
on odd frame numbers?

Original issue reported on code.google.com by Fobbah on 9 Jul 2011 at 4:08

GoogleCodeExporter commented 9 years ago
issue succesfully reproduced by dooke.

Original comment by Fobbah on 9 Jul 2011 at 4:14

GoogleCodeExporter commented 9 years ago
fix:

It seems that gameUpdate() was removing all units it thought were "dead" - it 
initialised the list of dead units as the list of all units from the last 
frame, but did not remove units that were still alive from the list of dead 
units - thus every frame, any unit that was in the list of units last frame was 
removed, and the frame after that, re-added.

One line fix:
 in JNIBWAPI.java -> JNIBWAPI.gameUpdate()

...
ArrayList<Unit> neutralList = new ArrayList<Unit>();

System.out.println("frm: " + gameFrame + " - " + unitData.length);

for (int index=0; index<unitData.length; index += Unit.numAttributes) {
    int id = unitData[index];

    Unit unit = units.get(id);
    deadUnits.remove(id);   ///ADD THIS LINE
    if (unit == null) {
        unit = new Unit(id);
        units.put(id, unit);        }
...

Original comment by Fobbah on 9 Jul 2011 at 5:19

GoogleCodeExporter commented 9 years ago

Original comment by LukeDic...@gmail.com on 15 Jul 2011 at 8:37