Ticket #446 (closed defect: fixed)

Opened 12 years ago

Last modified 12 years ago

Crashes when using text-fields without label

Reported by: mimmottos@… Owned by: williams
Priority: major Milestone:
Component: williams/table-panel.plt Keywords:
Cc: Version: (1 1)
Racket Version: 5.3.0.16--2012-07-19(9413b30/a) [3m].

Description

The following code crashes:

#lang racket/gui

;;;
;;;

;(require (planet williams/table-panel/table-panel))
(require "table-panel.ss")

;; The top-level frame
(define frame

(instantiate frame%

("Editor Grid")))

;; The table panel
(define table-panel

(instantiate table-panel%

(frame)
(alignment '(center center))
(dimensions '(2 1))))

;; Now lets populate it
(for ((i (in-range 2)))

(let* ((rows (if (zero? i) 5 1))

(cols 2)
(child (instantiate table-panel%

(table-panel)
(style '(border))
(dimensions (list rows cols))
(column-stretchability #t)
(row-stretchability #f))))

(for* ((k (in-range rows))

(j (in-range cols)))

;(printf "k,j: ~a,~a~n" k j)
(if (zero? i)

(new text-field%

;((format "~a ~a" k j) child)
(parent child)
;(label "ab")
(label #f)
(stretchable-width #t)
(stretchable-height #f)
(callback

(lambda (tf event)

(printf "~a~n" (send tf get-value)))))

(instantiate button%

((format "Button ~a" j) child)
(stretchable-width #t)
(stretchable-height #f)
(callback

(lambda (button event)

(printf "You clicked button ~a~n" (send button get-label)))))))))

; Show the top-level frame.
(send frame show #t)
=============================================
The cause of the error is division by zero when calculating ratio in (on or near line 280):

(vector-for-each

(lambda (i stretchable? width)

(when stretchable?

(let* ((ratio (/ width total-column-stretchable-width))

(quota (round (* ratio delta-width))))

(vector-set! column-widths i

(+ (vector-ref column-widths i) quota))

(set! total-column-stretchable-width

(- total-column-stretchable-width width))

(set! delta-width (- delta-width quota)))))

column-stretchabilities? column-widths)

======================================
If I replace the line:

(when stretchable?

with the line:

(when (and stretchable? (positive? total-column-stretchable-width))

at least my code starts to do what I expected. Still I'm not sure whether this is the right way to handle the crash since I'm a Racket novice and thus can't claim to understand your code completely.

Jussi Salmela

Change History

Changed 12 years ago by williams

  • status changed from new to closed
  • resolution set to fixed

The problem was that because of rounding, we could run out of available expansion space when stretching widgets. This has been fixed and a new version (1.2) pushed to PLaneT.

Note: See TracTickets for help on using tickets.