diff --git a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java index a7f0e0e..f1df5d5 100644 --- a/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java +++ b/DroidFishApp/src/main/java/org/petero/droidfish/activities/EditBoard.java @@ -442,7 +442,8 @@ public class EditBoard extends Activity { private void setPosFields() { setEPFile(getEPFile()); // To handle sideToMove change - TextIO.fixupEPSquare(cb.pos); + if (isValid()) + TextIO.fixupEPSquare(cb.pos); TextIO.removeBogusCastleFlags(cb.pos); } @@ -478,6 +479,16 @@ public class EditBoard extends Activity { return false; } + /** Return true if the position is valid. */ + private boolean isValid() { + try { + TextIO.readFEN(TextIO.toFEN(cb.pos)); + return true; + } catch (ChessParseError e) { + return false; + } + } + private String getParseErrString(ChessParseError e) { if (e.resourceId == -1) return e.getMessage();