Skip to content

Commit 3852151

Browse files
authored
Merge pull request #481 from schlimme-gegend/fixing-dangling-animation-threads
Fixing dangling animation threads
2 parents 26c981f + ed0d1b4 commit 3852151

File tree

4 files changed

+40
-11
lines changed

4 files changed

+40
-11
lines changed

core/src/processing/android/PWallpaper.java

Lines changed: 8 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@
3232
import android.graphics.Point;
3333
import android.graphics.Rect;
3434

35+
3536
public class PWallpaper extends WallpaperService implements AppComponent {
3637
private Point size;
3738
private DisplayMetrics metrics;
@@ -119,12 +120,16 @@ public Engine onCreateEngine() {
119120
@Override
120121
public void onDestroy() {
121122
super.onDestroy();
122-
if (engine != null) engine.onDestroy();
123+
124+
if (engine != null){
125+
//engine.sketch = null;
126+
engine.onDestroy();
127+
}
123128
}
124129

125130

126131
public class WallpaperEngine extends Engine implements ServiceEngine {
127-
private PApplet sketch;
132+
PApplet sketch;
128133
private float xOffset, xOffsetStep;
129134
private float yOffset, yOffsetStep;
130135
private int xPixelOffset, yPixelOffset;
@@ -205,7 +210,7 @@ public void onSurfaceDestroyed(SurfaceHolder holder) {
205210
// surface. If you have a rendering thread that directly accesses the
206211
// surface, you must ensure that thread is no longer touching the Surface
207212
// before returning from this function.
208-
super.onSurfaceDestroyed(holder);
213+
super.onSurfaceDestroyed(holder);
209214
}
210215

211216

core/src/processing/core/PSurfaceNone.java

Lines changed: 14 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -434,7 +434,7 @@ public boolean stopThread() {
434434
if (thread == null) {
435435
return false;
436436
}
437-
thread = null;
437+
thread.interrupt();
438438
return true;
439439
}
440440

@@ -451,15 +451,11 @@ public void setFrameRate(float fps) {
451451
}
452452

453453

454-
protected void checkPause() {
454+
protected void checkPause() throws InterruptedException {
455455
// if (paused) {
456456
synchronized (pauseObject) {
457457
while (paused) {
458-
try {
459-
pauseObject.wait();
460-
} catch (InterruptedException e) {
461-
// waiting for this interrupt on a start() (resume) call
462-
}
458+
pauseObject.wait();
463459
}
464460
}
465461
}
@@ -499,7 +495,17 @@ public void run() { // not good to make this synchronized, locks things up
499495

500496
while ((Thread.currentThread() == thread) &&
501497
(sketch != null && !sketch.finished)) {
502-
checkPause();
498+
if (Thread.currentThread().isInterrupted()) {
499+
finish();
500+
return;
501+
}
502+
try {
503+
checkPause();
504+
} catch (InterruptedException e) {
505+
finish();
506+
return;
507+
}
508+
503509
callDraw();
504510

505511
// wait for update & paint to happen before drawing next frame

studio/apps/wallpaper/src/main/AndroidManifest.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,5 +10,11 @@
1010
<meta-data android:name="android.service.wallpaper" android:resource="@xml/wallpaper"/>
1111
</service>
1212
<activity android:name="processing.android.PermissionRequestor"/>
13+
<activity android:name=".DebuggerEntryPointActivity">
14+
<intent-filter>
15+
<action android:name="android.intent.action.MAIN" />
16+
<category android:name="android.intent.category.LAUNCHER" />
17+
</intent-filter>
18+
</activity>
1319
</application>
1420
</manifest>
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
package wallpaper;
2+
3+
import android.app.Activity;
4+
import android.os.Bundle;
5+
import android.support.annotation.Nullable;
6+
7+
public class DebuggerEntryPointActivity extends Activity {
8+
@Override
9+
protected void onCreate(@Nullable Bundle savedInstanceState) {
10+
super.onCreate(savedInstanceState);
11+
}
12+
}

0 commit comments

Comments
 (0)