Skip to content

Commit

Permalink
Simplifies the "old" sync strategy and prevents an error in the "new"
Browse files Browse the repository at this point in the history
  • Loading branch information
AlexisDrogoul committed Aug 9, 2021
1 parent 8e31eaa commit 1e5d50d
Showing 1 changed file with 17 additions and 22 deletions.
Expand Up @@ -51,7 +51,7 @@
public abstract class LayeredDisplayView extends GamaViewPart
implements IToolbarDecoratedView.Pausable, IToolbarDecoratedView.Zoomable, IGamaView.Display {

private static boolean OLD_SYNC_STRATEGY = false;
private static boolean OLD_SYNC_STRATEGY = true;

protected int realIndex = -1;
protected SashForm form;
Expand All @@ -60,7 +60,6 @@ public abstract class LayeredDisplayView extends GamaViewPart
protected volatile boolean disposed;
Semaphore viewLock = new Semaphore(1);
Thread updateThread;
private volatile boolean lockAcquired = false;

@Override
public void setIndex(final int index) {
Expand Down Expand Up @@ -284,26 +283,22 @@ public IStatus runInUIThread(final IProgressMonitor monitor) {
}

@Override
public void update(final IDisplayOutput output) {

public void update(final IDisplayOutput out) {
LayeredDisplayOutput output = (LayeredDisplayOutput) out;
final boolean isSync = output.isSynchronized();
final boolean inInitPhase = output.isInInitPhase();
final boolean autoSave = output.isAutoSave();
// Fix for issue #1693
final boolean oldSync = output.isSynchronized();
if (output.isInInitPhase()) { output.setSynchronized(false); }
if (inInitPhase) { output.setSynchronized(false); }
// end fix
initUpdateThread(output, oldSync);
initUpdateThread(output, isSync);

if (output.isSynchronized()) {
final IDisplaySurface surface = getDisplaySurface();
surface.updateDisplay(false);
if (getOutput().getData().isAutosave() && surface.isRealized()) {
if (autoSave && surface.isRealized()) {
SnapshotMaker.getInstance().doSnapshot(surface, WorkbenchHelper.displaySizeOf(surfaceComposite));
}
// // Fix for issue #1693
// if (output.isInInitPhase()) {
// output.setInInitPhase(false);
// output.setSynchronized(oldSync);
// // end fix
// }
if (OLD_SYNC_STRATEGY) {
while (!surface.isRendered() && !surface.isDisposed() && !disposed) {
try {
Expand Down Expand Up @@ -374,16 +369,13 @@ void releaseViewLock() {
}

synchronized void acquireLock() {
while (lockAcquired) {
try {
wait();
} catch (final InterruptedException e) {}
}
lockAcquired = true;
try {
wait();
} catch (final InterruptedException e) {}
// }
}

private synchronized void releaseLock() {
lockAcquired = false;
notify();
}

Expand All @@ -398,7 +390,10 @@ public void removeOutput(final IDisplayOutput output) {
if (output == getOutput() && isFullScreen()) { WorkbenchHelper.run(this::toggleFullScreen); }
output.dispose();
outputs.remove(output);
if (outputs.isEmpty()) { close(GAMA.getRuntimeScope()); }
if (outputs.isEmpty()) {
releaseViewLock();
close(GAMA.getRuntimeScope());
}
}

@Override
Expand Down

0 comments on commit 1e5d50d

Please sign in to comment.