racket / drracket

DrRacket, IDE for Racket
http://www.racket-lang.org/
Other
445 stars 93 forks source link

Force close, no error. #483

Closed tylovejoy closed 3 years ago

tylovejoy commented 3 years ago

This is from Event Viewer on Windows 10.

Faulting application name: DrRacket.exe, version: 8.0.900.0, time stamp: 0x00000000
Faulting module name: libcairo-2.dll, version: 0.0.0.0, time stamp: 0x5ac882a2
Exception code: 0xc0000005
Fault offset: 0x0000000000064263
Faulting process id: 0x284e0
Faulting application start time: 0x01d7421a60460487
Faulting application path: C:\Program Files\Racket\DrRacket.exe
Faulting module path: C:\Program Files\Racket\lib\libcairo-2.dll
Report Id: 9be9519d-5208-4964-8c35-b12c5bcce078
Faulting package full name: 
Faulting package-relative application ID: 
#lang racket

(require racket/draw) ; graphics library
(require colors)

; basic vars
(define image_width 2048)
(define image_height 1152)
(define xWorldMin -50)
(define xWorldMax 50)
(define yWorldMin -30)
(define yWorldMax 30)
(define num_iterations 50000)
(define color_change (/ .999 num_iterations))
(define zoom_amount 0.43)

; display get-datum
(define (printPoly inPoly)
  (begin
    (define-values (whuh huh) (send inPoly get-datum))
    (display whuh)
    (newline)
    (display huh)
    (newline))
  )

; returns get-datum list(list(vector())) of location of polygon
(define (polyPoints inPoly)
  (begin
    (define-values (whuh huh) (send inPoly get-datum))
    whuh))

; center the fractal
(define xW2SScale (/ image_width (- xWorldMax xWorldMin)))
(define yW2SScale (/ image_height (- yWorldMax yWorldMin)))
(define xW2SOffset (* xW2SScale (- 0 xWorldMin)))
(define yW2SOffset (* yW2SScale (- 0 yWorldMin)))

; draw
(define (drawToScreen poly)
  (send poly scale xW2SScale yW2SScale)
  (send poly translate xW2SOffset yW2SOffset)
  (send dc draw-path poly)
  (send poly translate (* -1 xW2SOffset) (* -1 yW2SOffset))
  (send poly scale (/ 1 xW2SScale) (/ 1 yW2SScale))
  )

; variables to keep track of center of zoom
(define center_x 0)
(define center_y 0)

; margins to the left and right of off-center zoom
(define left_margin_x (abs (/ (- center_x xWorldMin) (- xWorldMax xWorldMin))))
(define right_margin_x (- 1 (abs (/ (- center_x xWorldMin) (- xWorldMax xWorldMin)))))
(define left_margin_y (abs (/ (- center_y yWorldMin) (- yWorldMax yWorldMin))))
(define right_margin_y (- 1 (abs (/ (- center_y yWorldMin) (- yWorldMax yWorldMin)))))

; create image base
(define entire_image (make-bitmap image_width image_height))
(define dc (new bitmap-dc% [bitmap entire_image]))

; black background
(send dc set-brush (make-color 0 0 0) 'solid)
(send dc draw-rectangle
      0 0
      image_width image_height)

(send dc set-pen (make-color 255 255 255) 1 'solid)
(send dc set-brush (make-color 100 100 100) 'solid)

; polygon define
(define poly1 (new dc-path%))
(send poly1 move-to -20 20)
(send poly1 line-to 20 20)
(send poly1 line-to 20 -20)
(send poly1 line-to -20 -20)
(send poly1 close)

; 600 frames for zoom animation
(for ([iter 602])
  ; create a new, fresh image
  ;(set! entire_image (make-bitmap image_width image_height))
  ;(set! dc (new bitmap-dc% [bitmap entire_image]))

  ; new background
  (send dc set-brush (make-color 0 0 0) 'solid)
  (send dc draw-rectangle
        0 0
        image_width image_height)

  (send dc set-brush (make-color 100 100 100) 'solid)

  ; new polygon
  (set! poly1 (new dc-path%))
  (send poly1 move-to -20 20)
  (send poly1 line-to 20 20)
  (send poly1 line-to 20 -20)
  (send poly1 line-to -20 -20)
  (send poly1 close)
  (send dc set-smoothing 'smoothed)

  ; translation amount
  (define translate_amount 40)

  (for ([i num_iterations])

    ;(send dc set-pen (hsv->color (hsv (abs (* .99 (cos (* i .0005)))) 1.0 1.0)) 1 'solid)
    (send dc set-brush (hsv->color (hsv (* i color_change) 0.75 0.75 0.25)) 'solid)

    ; translate fractal depending on which iteration
    (cond
      [(eq? 0 (modulo i 4))
       (send poly1 translate translate_amount 0)
       ]
      [(eq? 3 (modulo i 4))
       (send poly1 translate 0 translate_amount)
       ]
      [(eq? 2 (modulo i 4))
       (send poly1 translate (* -1 translate_amount) 0)
       ]
     [(eq? 1 (modulo i 4))
       (send poly1 translate 0 (* -1 translate_amount))
       ])    

    ; shrink the translation amount
    (set! translate_amount (* translate_amount (expt .99 (+ 1 iter))))

    (send poly1 rotate (/ pi 12))
    (send poly1 scale .99 .99)

    (drawToScreen poly1)
    )

  ; save the list(list(vector()) location of the last polygon (smallest)
  (define polyVector (polyPoints poly1))

  ; set variables to the (x,y) location of the polygon
  (set! center_x (vector-ref (list-ref (list-ref polyVector 0) 0) 0))
  (set! center_y (vector-ref (list-ref (list-ref polyVector 0) 0) 1))

  ; save images in proper format
  (cond
    [(< iter 10)
     (send entire_image save-file (string-append "00" (~a iter) "_lovejoy.png") 'png)
     ]
    [(< iter 100)
     (send entire_image save-file (string-append "0" (~a iter) "_lovejoy.png") 'png)]
    [(>= iter 100)
     (send entire_image save-file (string-append (~a iter) "_lovejoy.png") 'png)])

  ; zoom in
  (define newxWorldMin (- center_x (* left_margin_x (* (- xWorldMax xWorldMin) zoom_amount))))
  (define newxWorldMax (+ center_x (* right_margin_x (* (- xWorldMax xWorldMin) zoom_amount))))

  (set! xWorldMin newxWorldMin)
  (set! xWorldMax newxWorldMax)

  (define newyWorldMin (- center_y (* left_margin_y (* (- yWorldMax yWorldMin) zoom_amount))))  
  (define newyWorldMax (+ center_y (* right_margin_y (* (- yWorldMax yWorldMin) zoom_amount))))

  (set! yWorldMin newyWorldMin)
  (set! yWorldMax newyWorldMax)

  (set! xW2SScale (/ image_width (- xWorldMax xWorldMin)))
  (set! yW2SScale (/ image_height (- yWorldMax yWorldMin)))

  (set! xW2SOffset (* xW2SScale (- 0 xWorldMin)))
  (set! yW2SOffset (* yW2SScale (- 0 yWorldMin)))

  )
tylovejoy commented 3 years ago

This runs through 286 iterations out of 602 and force closes with no error messages.

jackfirth commented 3 years ago

It may be easier to diagnose this bug with a simpler test case. Could you reduce it to a minimal example that triggers the fault?

tylovejoy commented 3 years ago

I figured it out. The

(send dc set-smoothing 'smoothed)

line is what caused it.