[comp.sys.mac.programmer] Alert problems

adams3@unix.cis.pittsburgh.edu (Larry Adams) (06/05/89)

I'm a fairly novice mac programmer; in fact, the program i'm working
on is my first for the mac.  i seem to be having a problem with memory,
and would like the group's collective wisdom.

my program uses a "cursor" based linked list data structure. (no flames
please, it'll be changed to a dynamic structure, but i don't think that'll
affect the problem at hand.)
i initialize it by a call to NewHandle
(i.e., myHndl := structHndl(NewHandle(sizeof(structArray)))  )
the user can then create up to three lists (with windows which would display
them).  i used to pass NIL as the wStorage value, but kept getting the 
THINK pascal error "Address Error".  when i used a variable to store the
windows (actually, an array of three elements, i.e., @wStore[i] ), my
problem went away.
however, when the user has created their three lists ( ==> windows),
i want to put up an alert, saying that they must close one before opening
another.  i'm using StopAlert.  however, i again get "Address Error".
I'm assuming that if i use a dialog & use ModalDialog, then i won't have
the problem, since i can pass a pointer to storage for the dialog window.

my question is, why, when i have ~20 K free memory (as reported by
MemAvail), would i get an address error?  have i done anything
seriously wrong, or overlooked something that should be obvious?

if this is too trivial a question, please send your answer by e-mail.
your help is greatly appreciated, since i'm trying to learn, and i
don't know any mac hackers here at pitt.

	larry adams

siegel@endor.harvard.edu (Rich Siegel) (06/06/89)

In article <18282@unix.cis.pittsburgh.edu> adams3@unix.cis.pittsburgh.edu (Larry Adams) writes:

>them).  i used to pass NIL as the wStorage value, but kept getting the 
>THINK pascal error "Address Error".  when i used a variable to store the
>windows (actually, an array of three elements, i.e., @wStore[i] ), my
>problem went away.

	If you pass a pointer to NewWindow,  GetNewWindow,  NewDialog, or
GetNewDialog, it has to be a pointer to NON-relocatable storage. The
address of an element in a handled array is not such storage.

	If you're using StopAlert, be sure that the resource ID you're
passing is the ID of a real ALRT resource in your project's resource
file, and the the alert has a properly set up item list.

	Beyond that,  it's really hard to diagnose your problems without
seeing some of the code you wrote.

>my question is, why, when i have ~20 K free memory (as reported by
>MemAvail), would i get an address error?  have i done anything
>seriously wrong, or overlooked something that should be obvious?

	Address errors have nothing to do with allocation; an address
exception is raised by the 68000 when a word or longword fetch or store
is attempted from a numerically odd memory address.

		--Rich

~~~~~~~~~~~~~~~
 Rich Siegel
 Staff Software Developer
 Symantec Corporation, Language Products Group
 Internet: siegel@endor.harvard.edu
 UUCP: ..harvard!endor!siegel

 "She told me to make myself comfortable, so I pulled down my pants
 and sat in the pudding." -Emo Phillips
~~~~~~~~~~~~~~~

tim@hoptoad.uucp (Tim Maroney) (06/08/89)

I can't really diagnose your problem here.  However, I felt I should
mention that learning at least the basics of MacsBug (or TMON) is
critical to Mac programming.  If you install MacsBug, then you will be
able to see where in your code the address error occurs.  I assume that
Lightspeed Pascal puts out the neccessary end-of-function symbols that
will allow you to interpret your code.

And as Rich points out, an address error is an attempt to use an odd
pointer to access a two or four byte value.  Free memory doesn't come
into it.  Nor should it matter whether or not you pass NIL to wStorage
in a GetNewWindow call -- that is just "the straw that breaks the
camel's back".  Somewhere else in your code, you are corrupting the
application heap, most likely, and that is why GetNewWindow fails if it
has to allocate the storage itself (that is, if you pass wStorage =
NIL).  There are a number of commands, notably ATHC, in MacsBug that
will help you determine where the corruption happens.
-- 
Tim Maroney, Consultant, Eclectic Software, sun!hoptoad!tim
"Mere opinion without supporting argument is no more than the American
 Bandstand school of literary evaluation."  -- Tom Maddox