[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Too many menus ?



In one of my programs I have noticed that when I have a large number of pop
up menus on the screen, some of the last ones created never appear, or,
when pulled-down, turn out to contain the menu items of another menu
entirely. I had thought that this was a low-memory problem, but increasing
heap size and total allocation haven't stopped the problem. Here's some
code that produces this behavior on a couple of machines here:

(in-package :cl-user)

(defparameter *num-menus* 7)
(defparameter *submenus-per-level* 6)
(defparameter *max-depth* 2)

(defvar *w*)

(defun build-submenus (root-num depth)
    (if (>= depth *max-depth*)
       (list (make-instance 'menu-item
                     :menu-item-title (format nil "root #~s, depth ~s"
root-num depth)
                     :menu-item-action #'(lambda () 
																		(message-dialog (format nil "root #~s,  depth ~s"
root-num depth)))))
         (let ((menus))
            (dotimes (j *submenus-per-level* menus)
                (format t "making submenus for root ~s,  menu ~s, depth
~s~%" root-num j depth)
                (push (make-instance 'menu 
                                 :menu-title (format nil "menu #~s" j)
                                 :menu-items (build-submenus root-num (1+
depth)))
                            menus)
                ))))

(setf *w* (make-instance 'window 
                       :view-size #@(150 250)
                       :window-title "menu test"))

(gc)
(room)

(dotimes (i *num-menus*)
    (add-subviews (find-window "menu test")
    (make-instance 'pop-up-menu 
          :menu-title (format nil "menu #~s" i)
          :menu-items (build-submenus i 0)
          :view-position (make-point 20 (* 25 i))
          :item-display i
          )))

(room)

Run this code and then take a look at the menus produced. On my machine,
the first four are OK, the fifth is mostly OK, except for some of the items
in menu #0, and the sixth is almost completely screwed up.

Inspecting the resulting objects makes them all seem to be valid. All the
menus are there and have non-zero mac handles.

Any ideas anyone?

--Jeff