Hi Andrzej
Sorting arguments could be a good trick to bypass the problem. After
finding the reason I have added sorting to my scripts and now it works OK.
I've created a patch (attached) that does the sorting. It will need
some testing.
I removed all the old code that attempted to fix up the sections after
they had been created. It does seem that it was that code that caused
the map source crashes.
Jar file at: http://files.mkgmap.org.uk/download/294/mkgmap.jar
Differences in img files worry me a bit too. I can't see any negative
consequences but it looks like compilation is state dependent, maybe
some variables are not cleared at the start of new img?
This is harmless, files can always be different unless you give the
--preserve-element-order option. A quick test shows no differences
for me if that option is given.
Cheers,
..Steve
Index: src/uk/me/parabola/imgfmt/app/mdr/MDRFile.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/MDRFile.java (revision 3672)
+++ src/uk/me/parabola/imgfmt/app/mdr/MDRFile.java (working copy)
@@ -266,8 +266,6 @@
private void writeSections(ImgFileWriter writer) {
sizes = new MdrMapSection.PointerSizes(sections);
- mdr1.finish();
-
// Deal with the dependencies between the sections. The order of the following
// statements is sometimes important.
mdr28.buildFromRegions(mdr13.getRegions());
@@ -383,7 +381,6 @@
MdrMapSection mapSection = (MdrMapSection) section;
mapSection.setMapIndex(mdr1);
mapSection.initIndex(sectionNumber);
- mapSection.relabelMaps(mdr1);
}
if (section instanceof HasHeaderFlags)
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr1.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr1.java (revision 3672)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr1.java (working copy)
@@ -13,8 +13,6 @@
package uk.me.parabola.imgfmt.app.mdr;
import java.util.ArrayList;
-import java.util.Collections;
-import java.util.Comparator;
import java.util.List;
import uk.me.parabola.imgfmt.app.ImgFileWriter;
@@ -46,7 +44,6 @@
*/
public class Mdr1 extends MdrSection implements HasHeaderFlags {
private final List<Mdr1Record> maps = new ArrayList<>();
- private int[] mapping;
public Mdr1(MdrConfig config) {
setConfig(config);
@@ -70,30 +67,6 @@
}
}
- /**
- * The maps must be sorted in numerical order.
- */
- public void finish() {
- Collections.sort(maps, new Comparator<Mdr1Record>() {
- public int compare(Mdr1Record o1, Mdr1Record o2) {
- if (o1.getMapNumber() == o2.getMapNumber())
- return 0;
- else if (o1.getMapNumber() < o2.getMapNumber())
- return -1;
- else
- return 1;
- }
- });
-
- // Used to renumber all the existing (pre-sorted) map index numbers.
- mapping = new int[maps.size()];
- int count = 1;
- for (Mdr1Record r : maps) {
- mapping[r.getMapIndex()-1] = count;
- count++;
- }
- }
-
public void writeSubSections(ImgFileWriter writer) {
if (isForDevice())
return;
@@ -166,8 +139,4 @@
magic |= 1;
return magic;
}
-
- public int sortedMapIndex(int n) {
- return mapping[n-1];
- }
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr10.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr10.java (revision 3672)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr10.java (working copy)
@@ -132,13 +132,4 @@
// Nothing to do here
return 0;
}
-
- /**
- * Nothing to do for this section.
- *
- * Although this section has a subsection by map index in mdr1, its record does not contain the
- * map index and so nothing needs to be re-written here. The map index is contained in its mdr11ref.
- */
- public void relabelMaps(Mdr1 maps) {
- }
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr11.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr11.java (revision 3672)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr11.java (working copy)
@@ -173,8 +173,4 @@
public List<Mdr11Record> getPois() {
return new ArrayList<>(pois);
}
-
- public void relabelMaps(Mdr1 maps) {
- relabel(maps, pois);
- }
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr2x.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr2x.java (revision 3672)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr2x.java (working copy)
@@ -124,8 +124,4 @@
* @return True if the streets are in the same group (city, region etc).
*/
protected abstract boolean sameGroup(Mdr7Record street1, Mdr7Record street2);
-
- public void relabelMaps(Mdr1 maps) {
- // Nothing to do, since all streets are re-labeled in their own section.
- }
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr5.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr5.java (revision 3672)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr5.java (working copy)
@@ -202,8 +202,4 @@
public List<Mdr5Record> getSortedCities() {
return Collections.unmodifiableList(cities);
}
-
- public void relabelMaps(Mdr1 maps) {
- relabel(maps, cities);
- }
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java (revision 3672)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr6.java (working copy)
@@ -88,8 +88,4 @@
public int getExtraValue() {
return ((getSizes().getZipSize()-1)&0x03) | (isForDevice() ? 0 : 0x04);
}
-
- public void relabelMaps(Mdr1 maps) {
- relabel(maps, zips);
- }
}
Index: src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java (revision 3672)
+++ src/uk/me/parabola/imgfmt/app/mdr/Mdr7.java (working copy)
@@ -331,8 +331,4 @@
public List<Mdr7Record> getSortedStreets() {
return Collections.unmodifiableList(streets);
}
-
- public void relabelMaps(Mdr1 maps) {
- relabel(maps, allStreets);
- }
}
Index: src/uk/me/parabola/imgfmt/app/mdr/MdrMapSection.java
===================================================================
--- src/uk/me/parabola/imgfmt/app/mdr/MdrMapSection.java (revision 3672)
+++ src/uk/me/parabola/imgfmt/app/mdr/MdrMapSection.java (working copy)
@@ -12,8 +12,6 @@
*/
package uk.me.parabola.imgfmt.app.mdr;
-import java.util.List;
-
import uk.me.parabola.imgfmt.app.ImgFileWriter;
/**
@@ -71,25 +69,4 @@
protected boolean hasFlag(int val) {
return (getExtraValue() & val) != 0;
}
-
- public abstract void relabelMaps(Mdr1 maps);
-
- /**
- * Relabel every map-index in the given set of records.
- *
- * The maps must be in sorted order, but because of the incremental way that we build the
- * index, this isn't known until the end. So we get rewrite the mapIndex from the
- * initial to the final ordering.
- *
- * @param maps The final ordering of the maps.
- * @param records The set of records to be relabeled.
- * @param <T> The type of the record. Must be a subclass of RecordBase.
- */
- protected <T extends RecordBase> void relabel(Mdr1 maps, List<T> records) {
- for (T r : records) {
- int n = r.getMapIndex();
- int newIndex = maps.sortedMapIndex(n);
- r.setMapIndex(newIndex);
- }
- }
}
Index: src/uk/me/parabola/mkgmap/combiners/MdrBuilder.java
===================================================================
--- src/uk/me/parabola/mkgmap/combiners/MdrBuilder.java (revision 3672)
+++ src/uk/me/parabola/mkgmap/combiners/MdrBuilder.java (working copy)
@@ -310,13 +310,12 @@
String name = road.getName();
if (name == null || name.isEmpty())
continue;
- Mdr5Record mdrCity = null;
List<City> cities = road.getCities();
if (cities.isEmpty())
- mdrFile.addStreet(road, mdrCity);
+ mdrFile.addStreet(road, null);
else {
for (City city : cities){
- mdrCity = cityList.get(city.getIndex() - 1);
+ Mdr5Record mdrCity = cityList.get(city.getIndex() - 1);
if (mdrCity.getMapIndex() == 0)
mdrCity = null;
@@ -378,7 +377,7 @@
* These are only held for a single map at a time, which is
* sufficient to link them all up.
*/
- class AreaMaps {
+ private class AreaMaps {
private final Map<Integer, Mdr5Record> cities = new HashMap<>();
private Map<Integer, Mdr13Record> regions;
private Map<Integer, Mdr14Record> countries;
Index: src/uk/me/parabola/mkgmap/main/Main.java
===================================================================
--- src/uk/me/parabola/mkgmap/main/Main.java (revision 3672)
+++ src/uk/me/parabola/mkgmap/main/Main.java (working copy)
@@ -21,6 +21,8 @@
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collections;
+import java.util.Comparator;
import java.util.Date;
import java.util.HashMap;
import java.util.HashSet;
@@ -74,14 +76,14 @@
private static final Logger log = Logger.getLogger(Main.class);
// Final .img file combiners.
- private final List<Combiner> combiners = new ArrayList<Combiner>();
+ private final List<Combiner> combiners = new ArrayList<>();
- private final Map<String, MapProcessor> processMap = new HashMap<String, MapProcessor>();
+ private final Map<String, MapProcessor> processMap = new HashMap<>();
private String styleFile = "classpath:styles";
private String styleOption;
private boolean verbose;
- private final List<FilenameTask> futures = new LinkedList<FilenameTask>();
+ private final List<FilenameTask> futures = new LinkedList<>();
private ExecutorService threadPool;
// default number of threads
private int maxJobs = 1;
@@ -95,7 +97,6 @@
/**
* Used for unit tests
- * @param args
*/
public static void mainNoSystemExit(String[] args) {
Main.mainStart(args);
@@ -194,7 +195,7 @@
if (stream == null)
return null;
- Set<String> result = new HashSet<String>();
+ Set<String> result = new HashSet<>();
try {
BufferedReader r = new BufferedReader(new InputStreamReader(stream, "utf-8"));
@@ -276,7 +277,8 @@
public void processOption(String opt, String val) {
log.debug("option:", opt, val);
- if (opt.equals("number-of-files")) {
+ switch (opt) {
+ case "number-of-files":
// This option always appears first. We use it to turn on/off
// generation of the overview files if there is only one file
@@ -285,28 +287,37 @@
if (n > 0) // TODO temporary, this option will become properly default of on.
createTdbFiles = true;
- } else if (opt.equals("help")) {
+ break;
+ case "help":
printHelp(System.out, getLang(), (!val.isEmpty()) ? val : "help");
- } else if (opt.equals("style-file") || opt.equals("map-features")) {
+ break;
+ case "style-file":
+ case "map-features":
styleFile = val;
- } else if (opt.equals("style")) {
+ break;
+ case "style":
styleOption = val;
- } else if (opt.equals("verbose")) {
+ break;
+ case "verbose":
verbose = true;
- } else if (opt.equals("list-styles")) {
+ break;
+ case "list-styles":
listStyles();
- } else if (opt.equals("check-styles")) {
+ break;
+ case "check-styles":
checkStyles();
- } else if (opt.equals("max-jobs")) {
+ break;
+ case "max-jobs":
if (val.isEmpty())
maxJobs = Runtime.getRuntime().availableProcessors();
else
maxJobs = Integer.parseInt(val);
- if(maxJobs < 1) {
+ if (maxJobs < 1) {
log.warn("max-jobs has to be at least 1");
maxJobs = 1;
}
- } else if (opt.equals("version")) {
+ break;
+ case "version":
System.err.println(Version.VERSION);
System.exit(0);
}
@@ -365,7 +376,6 @@
*/
private void checkStyles() {
String[] names;
- int checked = 0;
try {
StyleFileLoader loader = StyleFileLoader.createStyleLoader(styleFile, null);
names = loader.list();
@@ -383,8 +393,9 @@
else
System.out.println("Found one style in " + styleFile);
}
+ int checked = 0;
for (String name : names) {
- if (styleOption != null && name.equals(styleOption) == false)
+ if (styleOption != null && !name.equals(styleOption))
continue;
if (names.length > 1){
System.out.println("checking style: " + name);
@@ -391,7 +402,7 @@
}
++checked;
boolean performChecks = true;
- if ("classpath:styles".equals(styleFile) && "default".equals(name) == false){
+ if ("classpath:styles".equals(styleFile) && !"default".equals(name)){
performChecks = false;
}
Style style = readOneStyle(name, performChecks);
@@ -411,8 +422,8 @@
* @return the style or null in case of errors
*/
private Style readOneStyle(String name, boolean performChecks){
+ searchedStyleName = name;
Style style = null;
- searchedStyleName = name;
try {
style = new StyleImpl(styleFile, name, new EnhancedProperties(), performChecks);
} catch (SyntaxException e) {
@@ -454,7 +465,7 @@
}
- List<FilenameTask> filenames = new ArrayList<FilenameTask>();
+ List<FilenameTask> filenames = new ArrayList<>();
int numMapFailedExceptions = 0;
@@ -525,8 +536,30 @@
for (Combiner c : combiners)
c.init(args);
- // will contain img files for which an additional ovm file was found
- HashSet<String> foundOvmFiles = new HashSet<String>();
+ Collections.sort(filenames, new Comparator<FilenameTask>() {
+ public int compare(FilenameTask o1, FilenameTask o2) {
+ if (!o1.getFilename().endsWith(".img") || !o2.getFilename().endsWith(".img"))
+ return o1.getFilename().compareTo(o2.getFilename());
+
+ // Both end in .img
+ try {
+ int id1 = FileInfo.getFileInfo(o1.getFilename()).getHexname();
+ int id2 = FileInfo.getFileInfo(o2.getFilename()).getHexname();
+ if (id1 == id2)
+ return 0;
+ else if (id1 < id2)
+ return -1;
+ else
+ return 1;
+ } catch (FileNotFoundException ignored) {
+ }
+ return 0;
+ }
+
+ });
+
+ // will contain img files for which an additional ovm file was found
+ HashSet<String> foundOvmFiles = new HashSet<>();
// try OverviewBuilder with special files
if (tdbBuilderAdded){
for (FilenameTask file : filenames) {
@@ -535,7 +568,7 @@
try {
String fileName = file.getFilename();
- if (fileName.endsWith(".img") == false)
+ if (!fileName.endsWith(".img"))
continue;
fileName = OverviewBuilder.getOverviewImgName(fileName);
log.info(" " + fileName);
@@ -547,7 +580,7 @@
if (c instanceof OverviewBuilder)
c.onMapEnd(fileInfo);
}
- } catch (FileNotFoundException e) {
+ } catch (FileNotFoundException ignored) {
}
}
}
_______________________________________________
mkgmap-dev mailing list
[email protected]
http://www.mkgmap.org.uk/mailman/listinfo/mkgmap-dev