Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
42 changes: 31 additions & 11 deletions gui/src/main/java/proguard/gui/splash/SplashPanel.java
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public class SplashPanel extends JPanel
private final Sprite sprite;
private final double sleepFactor;

private long startTime = Long.MAX_VALUE;
private volatile long startTime = Long.MAX_VALUE;
private final long stopTime;

private volatile Thread animationThread;
Expand Down Expand Up @@ -88,7 +88,7 @@ public void mouseClicked(MouseEvent e)
/**
* Starts the animation.
*/
public void start()
public synchronized void start()
{
// Go to the beginning of the animation.
startTime = System.currentTimeMillis();
Expand All @@ -107,11 +107,12 @@ public void start()
*/
public void stop()
{
// Go to the end of the animation.
startTime = 0L;

// Let the animation thread stop itself.
animationThread = null;
synchronized (this)
{
// Go to the end of the animation and let the old thread stop itself.
startTime = 0L;
animationThread = null;
}

// Repaint the SplashPanel one last time.
try
Expand Down Expand Up @@ -147,15 +148,24 @@ private class MyAnimator implements Runnable
{
public void run()
{
Thread worker = Thread.currentThread();
try
{
while (animationThread != null)
while (true)
{
// Check if we should stop the animation.
long time = System.currentTimeMillis();
if (time > startTime + stopTime)
synchronized (SplashPanel.this)
{
animationThread = null;
if (animationThread != worker)
{
return;
}

if (time > startTime + stopTime)
{
animationThread = null;
}
}

// Do a repaint and time it.
Expand All @@ -174,12 +184,22 @@ public void run()
}
catch (InterruptedException ex)
{
// Nothing.
worker.interrupt();
}
catch (InvocationTargetException ex)
{
// Nothing.
}
finally
{
synchronized (SplashPanel.this)
{
if (animationThread == worker)
{
animationThread = null;
}
}
}
}
}

Expand Down