Skip to content

Commit

Permalink
Merge pull request #896 from petebankhead/bf-fixes
Browse files Browse the repository at this point in the history
Fix image selector/Bio-Formats bug
  • Loading branch information
petebankhead committed Jan 21, 2022
2 parents dde612c + 8f37072 commit 842b04d
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 15 deletions.
8 changes: 8 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
## Version 0.4.0-SNAPSHOT

This is a work-in-progress.

### Bugs fixed
* Reading from Bio-Formats blocks forever when using multiple series outside a project (https://github.com/qupath/qupath/issues/894)


## Version 0.3.2

This is a *minor release* that aims to be fully compatible with v0.3.0 and v0.3.1 while fixing bugs.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -272,7 +272,7 @@ static BioFormatsImageServer checkSupport(URI uri, final BioFormatsServerOptions

BioFormatsImageServer(URI uri, final BioFormatsServerOptions options, String...args) throws FormatException, IOException, DependencyException, ServiceException, URISyntaxException {
super();

long startTime = System.currentTimeMillis();

// this.options = options;
Expand Down Expand Up @@ -1035,7 +1035,7 @@ private void createAdditionalReader(BioFormatsServerOptions options, final Class
if (isClosed)
return;
logger.debug("Requesting new reader for thread {}", Thread.currentThread());
var newReader = createReader(options, classList, id, new DummyMetadata(), args);
var newReader = createReader(options, classList, id, null, args);
if (newReader != null) {
additionalReaders.add(newReader);
queue.add(newReader);
Expand All @@ -1060,7 +1060,7 @@ private int getMaxReaders() {
* @param options options used to control the reader generation
* @param classList optionally specify a list of potential reader classes, if known (to avoid a more lengthy search)
* @param id file path for the image.
* @param store optional MetadataStore; this will be set in the reader if needed.
* @param store optional MetadataStore; this will be set in the reader if needed. If it is unspecified, a dummy store will be created a minimal metadata requested.
* @param args optional args to customize reading
* @return the {@code IFormatReader}
* @throws FormatException
Expand Down Expand Up @@ -1122,11 +1122,12 @@ private IFormatReader createReader(final BioFormatsServerOptions options, final
}


if (store != null) {
if (store != null)
imageReader.setMetadataStore(store);
}
else
else {
imageReader.setMetadataStore(new DummyMetadata());
imageReader.setOriginalMetadataPopulated(false);
}

var swapDimensions = args.getSwapDimensions();
if (swapDimensions != null)
Expand Down Expand Up @@ -1200,7 +1201,14 @@ private IFormatReader nextQueuedReader() throws InterruptedException {
task = ForkJoinPool.commonPool().submit(() -> createAdditionalReader(options, classList, id, args));
}
}
return queue.take();
if (isClosed)
return null;
try {
return queue.poll(60, TimeUnit.SECONDS);
} catch (InterruptedException e) {
logger.warn("Interrupted exception when awaiting next queued reader: {}", e.getLocalizedMessage());
return isClosed ? null : mainReader;
}
}


Expand Down Expand Up @@ -1415,10 +1423,9 @@ public void close() throws Exception {
logger.debug(e.getLocalizedMessage(), e);
}
}
// mainReader.close();
// for (var r : additionalReaders)
// r.close();
queue.clear();
// Allow the queue to be garbage collected - clearing could result in a queue.poll()
// lingering far too long
// queue.clear();
}


Expand Down
15 changes: 11 additions & 4 deletions qupath-gui-fx/src/main/java/qupath/lib/gui/ServerSelector.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,6 +180,9 @@ public ImageServer<BufferedImage> promptToSelectServer() {


Dialog<ButtonType> dialog = new Dialog<>();
var qupath = QuPathGUI.getInstance();
if (qupath != null)
dialog.initOwner(qupath.getStage());
dialog.setTitle("Open image");
ButtonType typeImport = new ButtonType("Open", ButtonData.OK_DONE);
dialog.getDialogPane().getButtonTypes().addAll(typeImport, ButtonType.CANCEL);
Expand Down Expand Up @@ -208,24 +211,28 @@ public void handle(MouseEvent click) {

Optional<ButtonType> result = dialog.showAndWait();

var selectedToReturn = listSeries.getSelectionModel().getSelectedItem();

try {
executor.shutdownNow();
} catch (Exception e) {
logger.warn(e.getLocalizedMessage(), e);
} finally {
selectedSeries = null;
try {
for (ImageServer<BufferedImage> server: serverList)
server.close();
for (ImageServer<BufferedImage> server: serverList) {
if (server != selectedToReturn)
server.close();
}
} catch (Exception e) {
logger.debug(e.getLocalizedMessage(), e);
}
selectedSeries = null;
}

if (!result.isPresent() || result.get() != typeImport || result.get() == ButtonType.CANCEL)
return null;

return listSeries.getSelectionModel().getSelectedItem();
return selectedToReturn;
}


Expand Down

0 comments on commit 842b04d

Please sign in to comment.