[comp.sys.mac.programmer] my driver stalls!

rcook@eagle.wesleyan.edu (11/12/90)

I am currently working on a driver that gets installed by an init and plays
a sound every Friday at 6pm (don't ask why--it's for a friend :-).  The init
apparently works, and receives noErr from the OpenDriver call.  The problem is
that the system crashes when the Finder is launched.  The usual problem is a
line 1111 error.  When I install the driver from within an application, there
is no problem as long as the application is running, but, again, when the
application quits and the finder starts up (or even when control is returned to
LSP 3.0) the system crashes.

The driver has a delay of 600 (every 10 seconds) and is marked 'locked' and
'system heap'.  To check if it was any of the code in the driver, I pared it
down so that it does nothing but return noErr on all calls and still the system
crashes.  I suspect is is not some sort of heap problem, because it isn't even
using local variables, let alone globals or making toolbox calls.

I need to know if there is some trick to having drivers remain installed and
running when you switch applications.  The driver is written using THINK Pascal
3.0.  I've read every tech note and every page of IM I could find relating to
this, and fond nothing.  Please e-mail or post anything you know on this
subject.  Thanks,

Randall Cook
rcook@eagle.wesleyan.edu

stevec@Apple.COM (Steve Christensen) (11/13/90)

rcook@eagle.wesleyan.edu writes:
>I am currently working on a driver that gets installed by an init and plays
>a sound every Friday at 6pm (don't ask why--it's for a friend :-).  The init
>apparently works, and receives noErr from the OpenDriver call.  The problem is
>that the system crashes when the Finder is launched.  The usual problem is a
>line 1111 error.  When I install the driver from within an application, there
>is no problem as long as the application is running, but, again, when the
>application quits and the finder starts up (or even when control is returned to
>LSP 3.0) the system crashes.

More than likely what's happening is that you didn't detach the driver.  When
resource files are closed (like your INIT's file), all resources belonging to
that file are purged from the heap (even if they're in the system heap).
So in your case, the system goes to call your driver, but the pointers are
invalid, so it jumps off into the weeds and goes boom.

To fix it, try adding the following (you did say Pascal, didn't you?):

	driverHandle := GetResource('DRVR', itsID);
	IF driverHandle<>NIL THEN BEGIN
	  HLock(driverHandle);	{if it's already locked you don't need this}
	  DetachResource(driverHandle);	{it's no longer a resource}
	END;

steve

-- 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  whoami?     Steve Christensen
  snail:      Apple Computer, 20525 Mariani Ave, MS-81CS, Cupertino, CA 95035
  internet:   stevec@apple.com
  AppleLink:  stevec
  CompuServe: 76174,1712