[comp.sys.mac.programmer] MacApp v2.0b5 problem / ModalDialogs

stathis@cs.qmc.ac.uk (Stathis Gikas) (07/23/89)

Hi there,

I'm developing a User Interface for a configurable
messaging system, whose semantic layer is implemented in C and
runs on a Sun, while its syntactic layers (UI) run on a number
of (different types of) remote hosts.
The syntactic layer talks to the semantic
layer via remote procedure cals. I'm coding the Mac UI.

The Problem:
============
I need to display a modal UserName/Password dialog before I
display the UI window(s). (The windows are the same for
all users, but what is displayed in them depends on the
particular user, as in a news/mail system)
So, the last line in my
        MyUIDocument.doMakeViews
method is a call to
        MyUIDocument.MakePaswdDialog
When I run the UI, the dialog is displayed ok, the edit text /
button items work fine, but when I hit the ok button, the
program crashes into MAcsBug with the message:
        "exception #4 Non-68K instruction"
Tracing the MacApp function TDialogView.PoseModaly shows that
before returning the dismisser has the right value ('ok' or 'cancel')
However, upon returning, it crashes with the above error message.

Additional Information
======================
I've allready implemented the UI in MPW 2.0.2/MacApp 1.1.1 and
everything worked fine. When we upgraded to MPW3.0/MacApp2.0b5
we thought we might as well take advantage of the new view
architecture, which makes life much easier in terms of changing
the appearance of windows/dialogs without having to recompile
the whole thing. However, MacApp2x doesn't seem to like
creating modal dialogs from its DoMakeViews method.
If I called the MyUIDocument.MakePaswdDialog procedure from a
menu (i.e from the .DoMenuCommand method) everything works
fine.
Checking the heaps shows that (usually) there is a bad
master pointer somewhere. But the program has only executed
MacApp-standard code up to this point (except the
MakePaswdDialog code, which is mine, and in any case is a copy
of the Cookbok code:

BEGIN
adWindow:=NewTemplateWindow(1512,NIL);
aDialog:=TDialogView(adWindow.FindSubView('DLOG'));
aDialog.SelectEditText('name',TRUE);
dismisser:=aDialog.PoseModally;     <----crashes here
END;
)

I have initialised  the UDialog an UPrinting Units, and I have
registered all my views.

Environment
===========
System  B1 6.0.3
Finder  B1 6.1
Mfinder 6.1b7
MPW     3.0
MacApp  2.0b5
Pascal  3.0

Any ideas? Has anybody implemented (in MAcApp2x) an application which
puts up a modal dialog before displaying its windows?
Solutions/ideas/comments greatly appreciated, as I'm getting
desperate, and I'm thinking of going back to good old
MacApp1.1.1... For people in the UK/London area: I might even
buy you a drink :-)

Thanks in advance.

PS. I've only been using MacApp2x for a month, so it might be
the case that I'm missing something really elementary/obvious.
No flames please...
-- 
====================================================================
Stathis Gikas,                  (gw: cs.ucl.edu)
Dep of Computer Science,        (ARPA) stathis@cs.qmc.ac.uk
Queen Mary College,             (UUCP) stathis@qmc-cs.UUCP
Mile End Rd, London E1 4NS,     (AppleLink) UK0087
UK.                             Tel 01-980 4811  x 5245

keith@Apple.COM (Keith Rollin) (07/25/89)

In article <1169@sequent.cs.qmc.ac.uk> stathis@cs.qmc.ac.uk (Stathis Gikas) writes:
>Hi there,
>
>I'm developing a User Interface for a configurable
>messaging system, whose semantic layer is implemented in C and
>runs on a Sun, while its syntactic layers (UI) run on a number
>of (different types of) remote hosts.
>The syntactic layer talks to the semantic
>layer via remote procedure cals. I'm coding the Mac UI.
>
>The Problem:

Sorry for deleting the problem, but it was rather lengthy. Essentially, it
concerned calling PoseModally and then crashing.

The problem here has to do with a variable called gEventLevel. This variable
is used to determine the nesting level for calls to PollEvent. If it is set
to 1, then we are supposed to be at the outer level, and a call to 
UnloadAllSegments is triggered to clean up memory. Normally, a call to
PoseModally will call PollEvent, which bumps gEventLevel to something greater
than 1, does the event stuff, and then decrements the level. In this
situation, UnloadAllSegments is not called.

HOWEVER, if MacApp is creating the initial untitled document, it does so before
the main event loop is ever entered. At this point, gEventLevel is still set
to zero. The first call to PoseModally and PollEvent set this to 1, the
segments are unloaded, and the segment that called PoseModally gets moved in
memory. Returning to it essentially returns to garbage.

This has been fixed in MacApp 2.0b9 (now available from APDA). In the meantime,
you may want to increment and decrement gEventLevel around your call to
PoseModally.

>buy you a drink :-)

OK!


------------------------------------------------------------------------------
Keith Rollin  ---  Apple Computer, Inc.  ---  Developer Technical Support
INTERNET: keith@apple.com
    UUCP: {decwrl, hoptoad, nsc, sun, amdahl}!apple!keith
"Argue for your Apple, and sure enough, it's yours" - Keith Rollin, Contusions