[comp.sys.mac.programmer] What's wrong with this picture?

mithomas@bsu-cs.bsu.edu (Michael Thomas Niehaus) (07/18/89)

Can someone tell me why this section of code causes problems:

CreateNew()
{

    extern int              i;
    extern StructHandle     test[];
                           /*  This is a dummy name.  The structure contains
                               a field called theWindow which points to the
                               window for this record.  */

    test[i] = (StructHandle) NewHandle( sizeof(StructHandle) );
    HLock(test[i]);
    (**(test[i])).theWindow = GetNewWindow(130, 0 , -1);
    HUnlock(test[i]);

}

It appears to work OK, but my inDrag routine suddenly started crashing when
I implemented this: any time I click in the drag region, it bombs.  I first
thought that the dereferencing was causing problems, so I put in the HLock.
Then I thought maybe I needed more master handles.  So I did that in the
initialization module.  Still no luck.  (By the way, this is Lightspeed C,
and looking at the debugger leads me to believe that the window in properly
initialized -- no nil values.)

If I change the code to assign the WindowPtr to some temporary variable before
I store it in the structure, I don't seem to have any problems.

Thanks for any advice.

-Michael

-- 
Michael Niehaus        UUCP: <backbones>!{iuvax,pur-ee}!bsu-cs!mithomas
Apple Student Rep      ARPA:  mithomas@bsu-cs.bsu.edu
Ball State University  AppleLink: ST0374 (from UUCP: st0374@applelink.apple.com)