[comp.sys.atari.st] Strange

greg@sj.ate.slb.com (Greg Wageman) (02/01/90)

Opinions expressed are the responsibility of the author.

In article <90029.124246O12@PSUVM.BITNET> O12@psuvm.psu.edu writes:
>Hello Everyone,
>
>I have a rather strange problem, I have written a GEM application
>which uses AES and LINE-A calls, and suffice it to say, it runs
>perfectly fine but has trouble exiting to the desktop
>properly and displays 3 bombs.
>
>The really wierd thing is the application runs and exits fine when
>launched from a shell other than the desktop, but then causes the
>SHELL to crash when you try exiting it to the desktop with 3 or 4
>bombs. Other programs can be launched from the shell before exiting it
>without error, the shell only crashes upon attempting to exit to the desktop.

Do you malloc() memory and change screens via Setscreen()?  If you do,
you must be careful to save the original values of Logbase() and
Physbase(), and return to using them via another Setscreen() before
you exit.  Otherwise, when your program exits, the memory you
malloc()'ed for your screen is freed, allowing it to be allocated by
other processes.  If the desktop writes on the screen at the addresses
you left active, it can scribble all over the free-memory pool,
resulting in spectacular crashes.

As a general rule, one of the first things I create in each GEM
program is an initialization routine and a termination routine.  These
share certain globals, such as the original values of Logbase() and
Physbase(), the initial palette, and so forth.  Then I religiously
call my termination routine anywhere the program exits (such as within
fatal error handlers).  This assures that things are put back the way
they were previously.

(Four bombs is an "illegal instruction" error.  This suggests that
code in RAM is getting clobbered somehow.  In my experience this
usually results from wild pointer references (storing through a
dereferenced, uninitialized pointer).  Any code that does a malloc()
or close relative is suspect in that case.)

Copyright 1990 Greg Wageman	DOMAIN: greg@sj.ate.slb.com
Schlumberger Technologies	UUCP:   {uunet,decwrl,amdahl}!sjsca4!greg
San Jose, CA 95110-1397		BIX: gwage  CIS: 74016,352  GEnie: G.WAGEMAN
 Permission is granted for reproduction provided this notice is maintained.