Unknown resources persist after window is closed
Closed this issue · 3 comments
I ran into this when using BdvFunctions.show(...)
in a standalone app noticing that the app does not terminate. The below app does not terminate when the main window is closed:
import java.util.concurrent.Callable;
import bdv.util.BdvFunctions;
import bdv.util.BdvOptions;
import net.imglib2.position.FunctionRealRandomAccessible;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.util.Intervals;
import picocli.CommandLine;
import picocli.CommandLine.Command;
@Command()
public class CommandTest implements Callable<Void> {
public static void main(final String... args) {
new CommandLine(new CommandTest()).execute(args);
}
@Override
public Void call() throws Exception {
final FunctionRealRandomAccessible<DoubleType> function = new FunctionRealRandomAccessible<>(
2,
(x, y) -> y.setReal(x.getDoublePosition(0)),
DoubleType::new);
BdvFunctions
.show(
function,
Intervals.createMinMax(0, 0, 1, 1),
"x ramp",
BdvOptions.options().is2D())
.setDisplayRange(0, 1);
return null;
}
}
This 'fixes' the behavior of the app, but I am not sure if it only does it by exiting the app or by freeing all pending resources.
final BdvStackSource<DoubleType> bdv = BdvFunctions
.show(
function,
Intervals.createMinMax(0, 0, 1, 1),
"x ramp",
BdvOptions.options().is2D());
bdv.setDisplayRange(0, 1);
((JFrame)SwingUtilities.getWindowAncestor(bdv.getBdvHandle().getViewerPanel())).setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
If this is ok, we should probably add an option BdvOptions.exitOnClose()
that implements this?
Thanks to @remkop for pushing me in the right direction!
@axtimwalde Which version of vistools and bdv-core is this?
I tried the following example (same as yours...)
import bdv.util.BdvFunctions;
import bdv.util.BdvOptions;
import net.imglib2.position.FunctionRealRandomAccessible;
import net.imglib2.type.numeric.real.DoubleType;
import net.imglib2.util.Intervals;
public class Example
{
public static void main( final String[] args )
{
final FunctionRealRandomAccessible<DoubleType> function = new FunctionRealRandomAccessible<>(
2,
(x, y) -> y.setReal(x.getDoublePosition(0)),
DoubleType::new);
BdvFunctions.show(
function,
Intervals.createMinMax(0, 0, 1, 1),
"x ramp",
BdvOptions.options().is2D())
.setDisplayRange(0, 1);
}
}
I ran this directly in the current vistools master and it terminates after I close the window.
Are you sure that the behaviour you see is not an artefact of the picocli.CommandLine
stuff?
I was using the managed version of bigdataviewer-vistools-1.0.0-beta-20
. When I put the code into the main method, it does not terminate on window close. With master, it works, but it took me some time to track everything that moved from net.imglib2.ui
to bdv.viewer
, sorry.
Solved in current master.