Newsgroups: comp.sys.mac.programmer Path: utzoo!utgpu!news-server.csri.toronto.edu!rpi!think.com!zaphod.mps.ohio-state.edu!caen!umich!terminator!usenet From: potts@itl.itd.umich.edu (Paul Potts) Subject: Objects in Code Resources - HELP! Message-ID: <1991May22.011618.27337@terminator.cc.umich.edu> Sender: usenet@terminator.cc.umich.edu (usenet news) Organization: Instructional Technology Laboratory, University of Michigan Date: Wed, 22 May 91 01:16:18 GMT Help! I have been working with an object library for handling sounds, written in THINK C with object extensions (but not the Class Library). The first object, called CDispatcher, creates the data structures and other objects in the chain. CDispatcher gets passed strings, which it breaks up, tokenizes, and uses to call the other objects in the heirarchy. It all works great, when these objects are built into an application, with a simple front end that uses the C console window to ask for commands and pass them to CDispatcher. I've been doing this, though, in the hopes that I could eventually use this object heirarchy in an XCMD/XFCN setting. I converted the project to create a code resource of type XFCN, changed ANSI to ANSI-A4, OOP to OOP-A4, etc. I *think* that I've done the obvious things. I've built XCMDs and XFCNs before, though it has been awhile, and I've never tried one so elaborate. It is a large code resource, but still fits in a single segment, even though I have to check "Multi-Segment Code Resource" or the compiler complains. Below is the trial "front end" I gave my object heirarchy when I am compiled it as a code resource. Note that I am only including the first part of the file to save space. When I call my code resource from Hypercard, doing something like "put SoundPackage(OpenChannel, sampledSynth) into card field blah...", my MAIN gets called, the param block seems to be setup the way it should be, the first Debugger() line gets called, the second Debugger() line gets called, and then... BLOOEY! Right at the first object call, myDispatcher->Init I get a System Error ID = 28. It is happening in a JSR call, to somehwere inside my code resource. I'll try to get a Disassembler and track down what it is doing, but in the meantime, does anyone have any ideas? Are there any special things to watch out for when using objects in code resources? Thanks in advance, -Paul- potts@itl.itd.umich.edu #include #include #include #include #include "CDispatcher.h" SoundErrorPtr result; Handle CopyStrToHand(str) /* borrowed from Gary Bond */ char* str; { Handle newHndl; newHndl = (Handle) NewHandle ((long) strlen(str) + 1); strcpy ((char*)(*newHndl), str); return (newHndl); } pascal void main (XCmdPtr paramPtr); pascal void main (paramPtr) XCmdPtr paramPtr; { Str255 incoming, reply; static CDispatcher *myDispatcher; extern SoundErrorPtr result; Debugger(); myDispatcher = new (CDispatcher); Debugger(); myDispatcher->Init(); /* create the first object in the chain and tell it that it has been made */ Debugger(); if (paramPtr->paramCount == 1) { Debugger(); HLock(paramPtr->params[0]); strcpy((char*)incoming, (*(paramPtr->params[0]))); HUnlock(paramPtr->params[0]); Debugger(); Here is the assembly code generated by the first few lines of the above program. A System error 28 occurs in the call to JSR $4808(A4). Since it immediately follows the second Debugger() call, I think this corresponds to the first message-passing. MAIN +0000 0053B7B6 LINK A6,#$FE00 +0004 0053B7BA _Debugger ; A9FF +0006 0053B7BC PEA $47F2(A4) +000A 0053B7C0 JSR 'XFCN 0032 0874 SounI+4566 ; 0053BC5A +000E 0053B7C4 ADDQ.L #$4,A7 +0010 0053B7C6 MOVE.L D0,$57FC(A4) +0014 0053B7CA _Debugger ; A9FF +0016 0053B7CC *MOVE.L $57FC(A4),-(A7) /* CRASHING WITH AN ID=28 at the very next instruction */ +001A 0053B7D0 JSR $4808(A4) +001E 0053B7D4 ADDQ.L #$4,A7 +0020 0053B7D6 _Debugger ; A9FF +0022 0053B7D8 MOVEA.L $0008(A6),A0 +0026 0053B7DC CMPI.W #$0001,(A0) +002A 0053B7E0 BNE MAIN+00AA ; 0053B860 +002E 0053B7E4 _Debugger ; A9FF