fix Unit.getUnitsInWeaponRange crashing due to bwapi bug

bwapi's implementation of getUnitsInWeaponRange does not check for a
null filter function, so it crashes if one is not passed in. we were
never passing one in here. to work around this for now, we'll just pass
in a dummy filter function that always returns true (so returns all
units in range always).
This commit is contained in:
gered 2017-04-19 21:52:06 -04:00
parent 688c611e91
commit e450e25e99
2 changed files with 18 additions and 1 deletions

View file

@ -1,11 +1,13 @@
package bwmirror.generator;
import bwmirror.c.Param;
import bwmirror.util.Generic;
import bwmirror.util.PointerTest;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* Created with IntelliJ IDEA.
@ -29,6 +31,8 @@ public class JavaContext {
private List<String> selfReturnTypes = Arrays.asList("BWTA::Polygon");
private Map<String, Param> requiresExplicitDummyPredicate = new HashMap<>();
private String packageName = "bwapi";
@ -39,6 +43,8 @@ public class JavaContext {
javaToCType.put("void", "void");
javaToCType.put("boolean", "jboolean");
javaToCType.put("String", "jstring");
requiresExplicitDummyPredicate.put("getUnitsInWeaponRange", new Param("", "IdentityUnitFilter"));
}
public boolean isSelfReturnType(String clsName, String methodName) {
@ -93,6 +99,10 @@ public class JavaContext {
return constantTypes.contains(javaType);
}
public boolean needsExtraFilterParameter(String methodName) { return requiresExplicitDummyPredicate.containsKey(methodName); }
public Param getExtraFilterParameter(String methodName) { return requiresExplicitDummyPredicate.get(methodName); }
public String ptrCType() {
return "jobject";
}

View file

@ -60,7 +60,12 @@ public class CallImplementer {
"#include <jni.h>\n" +
"#include <cstring>\n" +
"\n" +
"using namespace BWAPI;\n\n");
"using namespace BWAPI;\n\n" +
"\n" +
"bool IdentityUnitFilter(Unit u) {\n" +
"\treturn true;\n" +
"}\n" +
"\n");
}
private void implementAccessObject(String clsName, String objName) {
@ -505,6 +510,8 @@ public class CallImplementer {
String genericType = convertToBWTA(Generic.extractGeneric(javaRetType));
if (javaPackageName.equals("bwta") || (!genericType.equals("UnitType") && !genericType.equals("Position") && !genericType.equals("TilePosition"))){
out.print(wrapInCCollection(genericType, javaMethodName) + " cresult = " + objectAccessor + (javaContext.isSelfReturnType(clsName, javaMethodName) ? "" : javaMethodName + "("));
if (javaContext.needsExtraFilterParameter(javaMethodName))
params.add(javaContext.getExtraFilterParameter(javaMethodName));
implementRealParams(params);
if (!javaContext.isSelfReturnType(clsName, javaMethodName)) {
out.print(")");