You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Training a unit when the queue is full throws Index out of Bounds #61
Training a unit when the queue is full throws Index out of Bounds Exception. Tested on dev branch w/ latcom on.
Stack Trace:
java.lang.ArrayIndexOutOfBoundsException: Index 5 out of bounds for length 5
at bwapi.CommandTemp.execute(CommandTemp.java:725)
at bwapi.CommandTemp.execute(CommandTemp.java:41)
at bwapi.Unit.issueCommand(Unit.java:2119)
Solution would be for here to ignore train commands when the unit's training queue is already full.
There may be some fanciness required to accurately handle the case when the front of the queue will finish training prior to latency-delayed command execution, but I imagine the simpler solution is good-enough. Since there's never an advantage to queuing more than 2 units nobody should be harmed by brief prediction errors in that case.
diff --git a/src/main/java/bwapi/Unit.java b/src/main/java/bwapi/Unit.java
index 821f648..87524ee 100644
--- a/src/main/java/bwapi/Unit.java+++ b/src/main/java/bwapi/Unit.java@@ -2116,6 +2116,13 @@ public class Unit implements Comparable<Unit> {
}
if (game.isLatComEnabled()) {
+ // reject training commands when the trainingQueue is full+ if (command.type == UnitCommandType.Train) {+ final Integer queueCount = self().trainingQueueCount.get();+ if (queueCount != null && queueCount >= self().trainingQueue.length) {+ return false;+ }+ }
new CommandTemp(command, game).execute();
}
Activity
dgant commentedon Sep 10, 2020
Solution would be for here to ignore train commands when the unit's training queue is already full.
There may be some fanciness required to accurately handle the case when the front of the queue will finish training prior to latency-delayed command execution, but I imagine the simpler solution is good-enough. Since there's never an advantage to queuing more than 2 units nobody should be harmed by brief prediction errors in that case.
JasperGeurtz commentedon Sep 10, 2020
Code is identical to https://github.com/bwapi/bwapi/blob/e4a29d73e6021037901da57ceb06e37248760240/bwapi/include/BWAPI/Client/CommandTemp.h#L878
But Java will throw & C++ will just overwrite the next value in memory?
Ignoring those train commands is probably the "fix'
JasperGeurtz commentedon Sep 11, 2020
Proposed fix:
@ryanleecode can you check if the fix-training-oob branch fixes it for you?
ryanleecode commentedon Sep 12, 2020
Doesn't seem the work the
trainingQueueCountis out of sync (1) withunitData.getTrainingQueueCount()(5).JasperGeurtz commentedon Sep 13, 2020
OK, seems like I was too optimistic
Debugging a bit more it seems like it's a BWAPI Server latcom bug
the
unitData.getTrainingQueueCount()skips from 1 to 3 for some reasongetTrainingQueueCount: 1
getTrainingQueueCount: 3
With
latcomdisabled, this bug does not occur@N00byEdge any ideas where this could happen?