diff --git a/collects/2htdp/private/world.rkt b/collects/2htdp/private/world.rkt index cb31063e18..3d15a16eda 100644 --- a/collects/2htdp/private/world.rkt +++ b/collects/2htdp/private/world.rkt @@ -226,6 +226,11 @@ ;; Any ... -> Boolean (begin (define/public (name arg ...) + (define (last-draw) + (define draw0 draw) + (dynamic-wind (lambda () (set! draw last-picture)) + (lambda () (pdraw)) + (lambda () (set! draw draw0)))) (queue-callback (lambda () (with-handlers ([exn? (handler #t)]) @@ -245,8 +250,7 @@ (begin (set! nw (stop-the-world-world nw)) (send world set tag nw) - (when last-picture - (set! draw last-picture)) + (when last-picture (last-draw)) (when draw (pdraw)) (callback-stop! 'name) (enable-images-button)) @@ -270,9 +274,7 @@ [else (set! draw# (- draw# 1))])) (when (pstop) - (when last-picture - (set! draw last-picture) - (pdraw)) + (when last-picture (last-draw)) (callback-stop! 'name) (enable-images-button)) changed-world?)))))))) diff --git a/collects/2htdp/tests/record-stop-when.rkt b/collects/2htdp/tests/record-stop-when.rkt new file mode 100644 index 0000000000..de3c676ed9 --- /dev/null +++ b/collects/2htdp/tests/record-stop-when.rkt @@ -0,0 +1,40 @@ +#lang racket + +(require 2htdp/universe 2htdp/image (only-in lang/imageeq image=?)) + +(define (draw-number n) + (place-image (text (number->string n) 44 'red) + 50 50 + (empty-scene 100 100))) + +(define (draw-stop n) + stop) +(define stop (text "STOP" 44 'red)) + +;; -> Nat +;; make the clock tick n times, expected expected-n files in dir +(define (create-n-images) + (define dir "images0") + (unless (directory-exists? dir) + (make-directory dir)) + (parameterize ([current-directory dir]) + (for-each delete-file (directory-list))) + (with-output-to-file (format "./~a/index.html" dir) + (lambda () + (displayln "