Hi Steve, I think I have found the problem in Tags.java that was causing the assertion when I tried to delete multiple tags. I believe the root cause was the fact that remove() would decrement size so it looked as if there was space but it didn't actually remove the key (as the comment there suggests that is not the place to do that). So later, when trying to add another tag, it looked as if there was space (because size had been decremented) but keyPos() returned null because all the slots in the key array were full.
The attached patch fixes this issue by not decrementing size when a tag is deleted (the key will get "garbage collected" in ensureSpace() so that it will be removed when the arrays are grown) and size gets adjusted (see below). I also set size to 0 in ensureSpace() before copying the key/value pairs into the new arrays because put() will increment size when there isn't an existing value for that key (which there won't be when the arrays are being grown because they are newly allocated). Previously, when ensureSpace() copied the key/values into the new arrays size would have been incremented from its current value so that the arrays would look like they are almost full again straight away which means that they would be doubled in size for every couple of tags added (can that really be true?) Anyway, please check the attached patch for sanity as I don't profess to understand the tag stuff that well. Cheers, Mark
diff --git a/src/uk/me/parabola/mkgmap/reader/osm/Tags.java b/src/uk/me/parabola/mkgmap/reader/osm/Tags.java index 96bf4e6..707f1ba 100644 --- a/src/uk/me/parabola/mkgmap/reader/osm/Tags.java +++ b/src/uk/me/parabola/mkgmap/reader/osm/Tags.java @@ -99,7 +99,7 @@ public class Tags implements Iterable<String> { ensureSpace(); Integer ind = keyPos(key); if (ind == null) - assert false; + assert false : "keyPos(" + key + ") returns null - size = " + size + ", capacity = " + capacity; keys[ind] = key; String old = values[ind]; @@ -118,8 +118,6 @@ public class Tags implements Iterable<String> { // except when resizing. String old = values[k]; values[k] = null; - if (old != null) - size--; return old; } return null; @@ -149,10 +147,12 @@ public class Tags implements Iterable<String> { keys = new String[ncap]; values = new String[ncap]; capacity = ncap; + size = 0; for (int i = 0; i < okey.length; i++) { String k = okey[i]; - if (k != null) - put(k, oval[i]); + String v = oval[i]; + if (k != null && v != null) + put(k, v); } } assert size < capacity;
_______________________________________________ mkgmap-dev mailing list mkgmap-dev@lists.mkgmap.org.uk http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev