]> hydra-www.ietfng.org Git - acmetensortoys-watchviz/commitdiff
NPEs can happen
authorNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Thu, 9 Jun 2016 17:45:01 +0000 (13:45 -0400)
committerNathaniel Wesley Filardo <nwf@cs.jhu.edu>
Thu, 9 Jun 2016 17:45:01 +0000 (13:45 -0400)
Boo, hiss; the ordering of onStop and the canvas being destroyed appear
to be nondeterministic.  Just check for null in cycler thread.

app/src/main/java/com/acmetensortoys/watchviz/MainActivity.java

index d1d947b78a13e8ff5cede239f68854f823c6e28b..a2b5806bb34d54796899d0f8c1973279916c2140 100644 (file)
@@ -105,9 +105,6 @@ public class MainActivity extends WearableActivity
                     while (!Thread.interrupted()) {
                         final RenderCB rcb;
                         ar.read(samples, 0, samples.length, AudioRecord.READ_BLOCKING);
-                        synchronized(this) {
-                            rcb = cyclercb;
-                        }
                         /*
                          * Debug: triangle wave
                          */
@@ -119,7 +116,16 @@ public class MainActivity extends WearableActivity
                         */
                         fft.realForward(samples);
 
+                        synchronized(this) {
+                            rcb = cyclercb;
+                        }
+
                         Canvas cv = h.lockCanvas();
+                        if (cv == null) {
+                            // the surface must have been destroyed out from under us;
+                            // just stop here.
+                            break;
+                        }
                         cv.drawColor(Color.BLACK);
                         rcb.render(cv,samples);
                         h.unlockCanvasAndPost(cv);