Skip to content

Commit e5bae17

Browse files
committed
fix #20799 - fix performance/memory issues while scrolling across many geolocated images
git-svn-id: https://josm.openstreetmap.de/svn/trunk@18150 0c6e7542-c601-0410-84e7-c038aed88b3b
1 parent b748d90 commit e5bae17

File tree

3 files changed

+18
-7
lines changed

3 files changed

+18
-7
lines changed

src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
import java.awt.image.BufferedImage;
2222
import java.io.IOException;
2323
import java.util.Objects;
24+
import java.util.concurrent.Future;
2425

2526
import javax.swing.JComponent;
2627
import javax.swing.SwingUtilities;
@@ -634,13 +635,12 @@ public void destroy() {
634635
/**
635636
* Sets a new source image to be displayed by this {@code ImageDisplay}.
636637
* @param entry new source image
637-
* @since 13220
638+
* @return a {@link Future} representing pending completion of the image loading task
639+
* @since 18150
638640
*/
639-
public void setImage(ImageEntry entry) {
641+
public Future<?> setImage(ImageEntry entry) {
640642
LoadImageRunnable runnable = setImage0(entry);
641-
if (runnable != null) {
642-
MainApplication.worker.execute(runnable);
643-
}
643+
return runnable != null ? MainApplication.worker.submit(runnable) : null;
644644
}
645645

646646
protected LoadImageRunnable setImage0(ImageEntry entry) {

src/org/openstreetmap/josm/gui/layer/geoimage/ImageViewerDialog.java

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import java.util.Collections;
1919
import java.util.List;
2020
import java.util.Optional;
21+
import java.util.concurrent.Future;
2122

2223
import javax.swing.AbstractAction;
2324
import javax.swing.Box;
@@ -72,6 +73,7 @@ public final class ImageViewerDialog extends ToggleDialog implements LayerChange
7273
() -> Collections.singleton(imageryFilterSettings));
7374

7475
private final ImageDisplay imgDisplay = new ImageDisplay(imageryFilterSettings);
76+
private Future<?> imgLoadingFuture;
7577
private boolean centerView;
7678

7779
// Only one instance of that class is present at one time
@@ -204,6 +206,7 @@ public void destroy() {
204206
imageRemoveAction.destroy();
205207
imageRemoveFromDiskAction.destroy();
206208
imageZoomAction.destroy();
209+
cancelLoadingImage();
207210
super.destroy();
208211
dialog = null;
209212
}
@@ -466,9 +469,10 @@ public void displayImages(ImageData data, List<ImageEntry> entries) {
466469
btnCopyPath.setEnabled(true);
467470

468471
if (imageChanged) {
472+
cancelLoadingImage();
469473
// Set only if the image is new to preserve zoom and position if the same image is redisplayed
470474
// (e.g. to update the OSD).
471-
imgDisplay.setImage(entry);
475+
imgLoadingFuture = imgDisplay.setImage(entry);
472476
}
473477
setTitle(tr("Geotagged Images") + (!entry.getDisplayName().isEmpty() ? " - " + entry.getDisplayName() : ""));
474478
StringBuilder osd = new StringBuilder(entry.getDisplayName());
@@ -627,6 +631,13 @@ private void showLayer(Layer newLayer) {
627631
}
628632
}
629633

634+
private void cancelLoadingImage() {
635+
if (imgLoadingFuture != null) {
636+
imgLoadingFuture.cancel(false);
637+
imgLoadingFuture = null;
638+
}
639+
}
640+
630641
@Override
631642
public void selectedImageChanged(ImageData data) {
632643
displayImages(data, data.getSelectedImages());

src/org/openstreetmap/josm/gui/progress/swing/ProgressMonitorExecutor.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public void afterExecute(final Runnable r, Throwable t) {
4848
try {
4949
((Future<?>) r).get();
5050
} catch (CancellationException cancellationException) {
51-
t = cancellationException;
51+
Logging.debug("Thread {0} raised {1}", Thread.currentThread().getName(), cancellationException);
5252
} catch (ExecutionException executionException) {
5353
Logging.trace(executionException);
5454
t = executionException.getCause();

0 commit comments

Comments
 (0)