Skip to content

Commit

Permalink
Resolve racing condition
Browse files Browse the repository at this point in the history
Racing condition occurs when a command is programmatically invoked
immediately after a display is created, using swing ui. The racing
condition is resovled in a similar way to the LegacyImageDisplayViewer.

See scijava/scijava-ui-swing#18
  • Loading branch information
LeonYang5114 committed Nov 18, 2015
1 parent a54b96f commit ed5b661
Showing 1 changed file with 5 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@
import net.imagej.ui.viewer.image.AbstractImageDisplayViewer;

import org.scijava.display.Display;
import org.scijava.display.DisplayService;
import org.scijava.event.EventHandler;
import org.scijava.event.EventService;
import org.scijava.options.event.OptionsEvent;
Expand Down Expand Up @@ -77,6 +78,10 @@ public JHotDrawImageCanvas getCanvas() {
@Override
public void view(final DisplayWindow w, final Display<?> d) {
super.view(w, d);

// NB: resolve the racing condition when other consumer are looking up the
// active display
getContext().service(DisplayService.class).setActiveDisplay(getDisplay());

dispatcher = new AWTInputEventDispatcher(getDisplay(), eventService);

Expand Down

1 comment on commit ed5b661

@ctrueden
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Merging as a short-term solution. My intuition is that we can be somehow cleaner in the future, but I don't know how at the moment.

Please sign in to comment.