[comp.sys.mac.programmer] ModalDialog and out of memory

ola@romeo.cs.duke.edu (Owen L. Astrachan) (12/15/88)

I'm undoubtedly missing something simple, but I'm writing my first Mac
application and am having trouble with a Dialog.

I've retrieved a dialog resource with GetNewDialog passing a pointer to
a globally declared DialogTemplate for storage (e.g., won't use heap?).
The dialog has two buttons and an editable text field.  A certain menu
selection is supposed to cause the dialog to be displayed to allow the
user to enter some text (a number, but that's undoubtedly not relevant).
The code to do this looks something like (using LSP 2.0):

    ShowWindow(windowPtr(myDialogPtr));
    ModalDialog(nil,whatHit);
    if whatHit = ok then 
    	do appropriate thing;
    HideWindow(windowPTr(myDialogPtr));

The first time the relevant menu item is selected all goes well.  On
subsequent selections, however, the program generates an out of memory
error on the call to ModalDialog.  If I comment out the call to
ModalDialog the program runs fine but the dialog is only displayed the
first time.  Could somebody point out the error of my ways?

Thanks.

Owen

Owen L. Astrachan               CSNET: ola@duke        
Dept.of Computer Science        ARPA:  ola@cs.duke.edu
Duke University                 UUCP: {ihnp4!decvax}!duke!ola
Durham NC 27706                 Phone (919)684-5110 Ext. 229