[comp.sys.mac.programmer] Hanging due to repeated modaldialog call

tarr-michael@CS.YALE.EDU (michael tarr) (08/29/90)

Any suggestions as to why calling this more than 4 or 5 times with 4 or
5 TE windows open hangs the system (not even a bomb)?

#define	SAVE_WIDTH		250
#define SAVE_HEIGHT		110

int HandleQuitOrSaveDialog(void)
{
    Handle      itemList;
    DialogPtr   saveDialog;
    Rect        boundsRect;
    int         itemHit;

    SetCursor(&arrow);
    itemList = GetResource( 'DITL', SAVE_DITL_ID );
    
    SetRect ( &boundsRect, (screenBits.bounds.right - SAVE_WIDTH) / 2,
                           (screenBits.bounds.bottom - SAVE_HEIGHT) / 2,
                           (screenBits.bounds.right + SAVE_WIDTH) / 2,
                           (screenBits.bounds.bottom + SAVE_HEIGHT) / 2 );
    
    saveDialog = NewDialog( NIL_POINTER, &boundsRect, NIL_TITLE, TRUE,
                dBoxProc, MOVE_TO_FRONT, NO_GO_AWAY, NIL_REF_CON, itemList );

    FrameDItem( saveDialog, SAVE_BUTTON );

    ModalDialog( NIL_POINTER, &itemHit );
    
    DisposDialog( saveDialog );
    ReleaseResource( itemList );
    return( itemHit );
}
-- 
 * Mike Tarr                                    The Human Neuron Project  *
 * tarr@cs.yale.edu                             Department of Psychology  *
 * "My opinions are always my own."             Yale University           *
 **************************************************************************

jackiw@cs.swarthmore.edu (Nick Jackiw) (08/29/90)

tarr-michael@CS.YALE.EDU (michael tarr) writes:
> Any suggestions as to why calling this more than 4 or 5 times with 4 or
> 5 TE windows open hangs the system (not even a bomb)?
>     itemList = GetResource( 'DITL', SAVE_DITL_ID );
>     saveDialog = NewDialog( NIL_POINTER, &boundsRect, NIL_TITLE, TRUE,
>                 dBoxProc, MOVE_TO_FRONT, NO_GO_AWAY, NIL_REF_CON, itemList );
>     ModalDialog( NIL_POINTER, &itemHit );
>     DisposDialog( saveDialog );
>     ReleaseResource( itemList );

Doesn't DisposDialog release the memory for the item list as well as for
the dialog record itself?  ReleaseResource is then being called on already
released/disposed data.  ReleaseResource's behavior in this case isn't
strictly documented, and may be your problem.



-- 

------------------------
Nick Jackiw		jackiw@cs.swarthmore.edu  "We are what we think,
Visual Geometry Project	jackiw@swarthmr.bitnet     having become what we