In order to figure out the source of the crashes I was getting I quickly wrote a linux wrapper around the android code so it could run in a simpler-to-debug environment. This of course was running without any problems, so not much help, but it’ll come in useful anyway.
Next step, try it in the emulator – this exhibited the crash, but I couldn’t get a good stack trace from gdb. While investigating this I decided I could use a simpler method with the hardware, which is much faster than the emulator. addr2line is a program you can use for making sense out of crash reports, you take the address reported in the crash log (using adb logcat to read them from the android device), feed it to addr2line with the library and it tells you the corresponding line number in the source.
It turned out the crashes were down to something more fundamental as they were happening all over the place in the scheme interpreter – so I had a bit of a wider search and it came down to threads, I hadn’t noticed that Android’s GLSurfaceView uses a separate thread for rendering, so I was calling the scheme interpreter in the midst of other evaluations, not too great. A simple fix using java locks around the evaluations and rendering calls.
The next thing was implementing more fluxus features. One major improvement is using with-state to wrap push and pop so they are implicitly scoped. This means you can’t miss (or add extra) a pops or pushes to your state stack manipulations, so something like:
(push) (translate (vector 1 2 3)) (build-cube) (pop)
(with-state (translate (vector 1 2 3)) (build-cube))
To do this I had to learn TinyScheme’s macro language which is different to Racket’s, but this isn’t too complex a task:
(define-macro (with-state . args) `(begin (push) (let ((r (begin ,@args))) (pop) r)))
Here we call push then basically “paste” the code given to the with-state function into a begin block, and record it’s return before calling pop. Then we return the value. There is a very similar macro for with-primitive.
There are now quite a few commands ported – there is a new version packaged here, and this is the test script that I’m using:
(clear) (colour (vector 0 0.5 1 1)) (define cubes (map (lambda (p) (with-primitive p (apply-transform) (translate (vector -2.5 2 5)) (rotate (vector 45 0 0)) (translate (vector (quotient (- p 1) 6) 0 (modulo (- p 1) 6))) p)) (build-list (lambda (n) (with-state (scale (vector 0.5 0.05 0.5)) (build-cube))) 36))) (every-frame (for-each (lambda (p) (with-primitive p (rotate (vmul (vector (sin p) 0 (cos p)) 5)))) cubes))