WeScheme errors, DrRacket happy

Run the animation below. Slowly move the mouse into the window from the bottom near the right. Get an error.

Maxmimum call stack size exceeded

I can't figure out what's wrong. Can anybody see the issue? Touching this made the error gp ai

; STORED FUNCTIONS

(define (posn-sub x y)
  (make-posn (- (posn-x x) (posn-x y)) (- (posn-y x) (posn-y y))))

(define (posn-scale x pt)
  (make-posn (* x (posn-x pt)) (* x (posn-y pt)) ))

(define(posn-add c v)
  (make-posn (+ (posn-x c) (posn-x v)) (+ (posn-y c) (posn-y v))))

(define (posn-dist c v)
  (sqrt (+ (expt (- (posn-x c) (posn-x v))2)
           (expt (- (posn-y c) (posn-y v))2))))

(define (posn-place x d c)
  (place-image d (posn-x x) (posn-y x) c))



(define (game-over? a)
  (= (posn-x a) 1000))

(define (end-screen a)
  (overlay (text "game over" 40 "red")
           (place-image (square 20 "solid" "green")
                        (posn-x a) (posn-y a)
                        (empty-scene 300 300))))

(define (mh a x y e)
  (local [(define d (posn-dist (make-posn x y) a))]
         (cond [(and(string=? e "move")
                    (> 20 d))  ;; the (> 20 d) could be (< d 20)
                (posn-add
                 (posn-scale (/ 1 d)
                             (posn-sub (make-posn x y) a))
                 a)]
               [else a])))

(define (dh a)
  (place-image (square 20 "solid" "red")
               (posn-x a) (posn-y a)
               (empty-scene 300 300)))
(big-bang
 (make-posn 150 150)
 ;(check-with posn?)
 (to-draw dh)
 (on-mouse mh)
 (stop-when game-over? end-screen))

I've tried in Safari and Chrome and I can't reproduce your error.

  1. go to WeScheme Editor
  2. paste in code
  3. run
  4. Slowly move the mouse into the window from the bottom near the right. Get an error.

Maxmimum call stack size exceeded

I have trouble doing exactly as I what you describe because the window always appears under the mouse for me:

Is the 'Maxmimum call stack size exceeded' error a WeScheme error or a browser error? (If I move the mouse just right I can get WeScheme to emit a div by zero at line 35. )

I sometimes open the console in browser dev tools, but don't know of that will help here.

Stephen

Is the problem in mh when d becomes 0?

Ah, inserting some debugging code in the mouse handler reveals that the mouse coordinates are (NaN, NaN) on the last mouse event when the mouse moves out of the window.

 (display (format "model: ~a, mouse: (~a, ~a) event: ~a~n" a x y e))

Results in this output:

 model: (posn 150 150), mouse: (190, 300) event: move
 model: (posn 150 150), mouse: (NaN, NaN) event: move

These are the input coordinates of the mouse, not something that could be the result of user code dividing by zero.

Thanks for being the sounding board.

Reproduction environment: Ubuntu linux, Chromium 143.0.7499.146 (Official Build) snap (64-bit)

1 Like

FWIW, I am also able to reproduce the bug on Firefox 146.0.1, where the error is "too much recursion".

Reproducing the bug requires that the initial model not move from (150,150). If the model posn has some inexact numbers, then even though the mouse coordinates are NaN, there is no "too much recursion" error. (Chromium and Firefox)

Now this is a bug I can understand how to trace.

Root cause of error: most operations work fine with NaN, but not sqrt.

Small reproduction program:


(define (mh model x y event)
  (begin 
   (display (format "model: ~a, mouse: (~a, ~a) event: ~a~n" model x y event))
   (if (< y 200)
       model 
       ;; if you remove the sqrt, there is no crash
       (sqrt
        (expt (- y model) 2)
        )
       )))

(define (dh m)
  (overlay (text (number->string m) 24 "black")
           (empty-scene 200 150)))

(big-bang 140
 (to-draw dh)
 (on-mouse mh))