kopia lustrzana https://github.com/JOSM/MapWithAI
Fix JOSM-18578 -- crash when adding MapWithAI layer multiple times.
The test looks at the last errors and warnings from the Logger, since the issue was not being raised. Signed-off-by: Taylor Smock <taylor.smock@kaart.com>pull/1/head
rodzic
51dc46d2c1
commit
70b624452d
|
@ -309,13 +309,15 @@ public final class MapWithAIDataUtils {
|
|||
}
|
||||
|
||||
final MapWithAILayer tLayer = layer;
|
||||
if (SwingUtilities.isEventDispatchThread() && create) {
|
||||
MainApplication.getLayerManager().addLayer(tLayer);
|
||||
} else if (create) {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(() -> MainApplication.getLayerManager().addLayer(tLayer));
|
||||
} catch (InvocationTargetException | InterruptedException e) {
|
||||
Logging.error(e);
|
||||
if (!MainApplication.getLayerManager().getLayers().contains(tLayer)) {
|
||||
if (SwingUtilities.isEventDispatchThread() && create) {
|
||||
MainApplication.getLayerManager().addLayer(tLayer);
|
||||
} else if (create) {
|
||||
try {
|
||||
SwingUtilities.invokeAndWait(() -> MainApplication.getLayerManager().addLayer(tLayer));
|
||||
} catch (InvocationTargetException | InterruptedException e) {
|
||||
Logging.error(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -3,6 +3,7 @@ package org.openstreetmap.josm.plugins.mapwithai.backend;
|
|||
|
||||
import static com.github.tomakehurst.wiremock.core.WireMockConfiguration.options;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
import static org.junit.jupiter.api.Assertions.assertNotNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertNull;
|
||||
import static org.junit.jupiter.api.Assertions.assertTrue;
|
||||
|
||||
|
@ -38,6 +39,7 @@ import org.openstreetmap.josm.gui.mappaint.MapPaintStyles;
|
|||
import org.openstreetmap.josm.gui.mappaint.StyleSource;
|
||||
import org.openstreetmap.josm.spi.preferences.Config;
|
||||
import org.openstreetmap.josm.testutils.JOSMTestRules;
|
||||
import org.openstreetmap.josm.tools.Logging;
|
||||
|
||||
import com.github.tomakehurst.wiremock.WireMockServer;
|
||||
|
||||
|
@ -220,6 +222,16 @@ public class MapWithAIDataUtilsTest {
|
|||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleAddLayer() {
|
||||
Logging.clearLastErrorAndWarnings();
|
||||
assertNull(MapWithAIDataUtils.getLayer(false));
|
||||
assertNotNull(MapWithAIDataUtils.getLayer(true));
|
||||
assertNotNull(MapWithAIDataUtils.getLayer(true));
|
||||
assertTrue(Logging.getLastErrorAndWarnings().stream().filter(str -> !str.contains("Failed to locate image"))
|
||||
.collect(Collectors.toList()).isEmpty());
|
||||
}
|
||||
|
||||
private static int getExpectedNumberOfBBoxes(BBox bbox) {
|
||||
double width = MapWithAIDataUtils.getWidth(bbox);
|
||||
double height = MapWithAIDataUtils.getHeight(bbox);
|
||||
|
|
Ładowanie…
Reference in New Issue