Path: utzoo!attcan!uunet!lll-winken!ames!hc!lanl!opus!ksitze From: ksitze@nmsu.edu (Kevin Sitze) Newsgroups: comp.sys.mac.programmer Subject: Re: Installing a CODE as a VBL Message-ID: Date: 24 May 89 19:46:46 GMT References: <5586@hubcap.clemson.edu> Sender: news@nmsu.edu Organization: NMSU Computer Science Lines: 58 In article: Michael writes: >I am trying to install a precompiled LSP unit as a VBL task. I compiled it >as a CODE resource and all it does is a sysbeep(1). > >In the calling program i declare: > >HCode : Handle; > >HCode := GetResource('OUR ',100); { the type and number of the code rsrc} >DetachResource(HCode); > >then i set the vblAddr field of the vblTask to be ProcPtr(HCode^). > >This crashes the machine every time. What's up? You might want to lock the handle, if the memory manager is in the middle of moving that handle and the VBL occures, then your task suddenly finds itself running off into nowheres-ville. To prevent fragmenting of the heap, find the size of the resource like this: ... {Previous code} SetResLoad(False); {Don't want to load in the resource as of yet} HCode := GetResource('OUR ', 100); {Get a (empty) handle to the resource} ResrvMem(SizeResource(HCode)); {Get enough space for the resource} {as low in the heap as possible (ResrvMem is used when} {allocating ptrs)} SetResLoad(True); LoadResource(HCode); {Load the resource info into memory} HLock(HCode); {Lock it in place so it'll stay valid for VBL} DetachResource(HCode); ... {Rest of installation code here} If you don't want to do the previous, then the answer is simple. Just set the ResLock flag (Using ResEdit) on the resource you want in memory and then the program reverts back to: ... HCode := GetResource('OUR ', 100); DetachResource(HCode); ... This is because all the rest of the calls given in the first example are made automatically by the resource manager. Pretty fun eh? If your problem of crashing the machine persists, then you'll have to go back to your VBL code and make sure that you aren't trying to use handles anywhere in it's code. Have fun.... -Kelesi -- +--------------------------------------------------------------------+ | From the Macintosh of: Kevin L. Sitze. This is ME: ksitze@NMSU.edu | +------------------------------------------------------+-------------+ | The difference between intelligence and stupidity is | Is this | | that intelligence has a limit. -- anonymous | better? | +------------------------------------------------------+-------------+