home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / comp / sys / mac / programm / 18627 < prev    next >
Encoding:
Text File  |  1992-11-18  |  5.3 KB  |  124 lines

  1. Newsgroups: comp.sys.mac.programmer
  2. Path: sparky!uunet!ornl!rsg1.er.usgs.gov!darwin.sura.net!news.udel.edu!chopin.udel.edu!kurisuto
  3. From: kurisuto@chopin.udel.edu (Sean J. Crist)
  4. Subject: Summary: THINK Pascal and stand-alone crashes
  5. Message-ID: <Bxy2Iz.1w7@news.udel.edu>
  6. Sender: usenet@news.udel.edu
  7. Nntp-Posting-Host: chopin.udel.edu
  8. Organization: University of Delaware
  9. Date: Thu, 19 Nov 1992 03:47:23 GMT
  10. Lines: 112
  11.  
  12. In a recent posting, I described a crash which is happening in a 
  13. stand-alone application but which isn't happening in the THINK 
  14. Pascal run environment.  I've had several requests for the 
  15. responses that I've gotten; since this topic seems to be of 
  16. general interest, I'm summarizing what I've gotten here.
  17.  
  18. Some have suggested that my problem is that I'm not initializing 
  19. the Toolbox:
  20.  
  21. (Person A wrote)
  22. > Is your program doing all of the Mac initialization stuff at the start?
  23. > When running in ThinkP these calls are done for you, but when you build the
  24. > standalone they aren't.  I mean stuff like:  InitGraf, InitWindows,
  25. > InitDialogs... etc.  Look up these calls in InsideMac or in any listing of
  26. > a complete Mac program!
  27.  
  28. However, others have correctly pointed out that you should NOT 
  29. initialize the Toolbox, since this is done for you both in the 
  30. Pascal environment and in the stand-alone application:
  31.  
  32. (Person B wrote)
  33. > Let me guess--your program explictly calls InitGraf, InitFonts, InitWindows,
  34. > etc.
  35. > If so, this is the cause of your crash.  THINK Pascal automatically adds
  36. > glue initializing a whole bunch of Toolbox managers.  Any explicit calls
  37. > from within your program are ignored when executed in the TP environment,
  38. > but cause crashes when you run in standalone mode.  (See pp. 150 and
  39. > pp. 211 of the TP User Manual.)
  40. > Basically, you have two choices: 1) you can remove the explicit
  41. > initializations from your program, or 2) you can compile with the {$I-}
  42. > compiler directive (which suppresses the automatic initialization).
  43. > If this is not your problem, then it beats me...
  44.  
  45. Several people have suggested that I'm not managing my grafPorts 
  46. properly:
  47.  
  48. (Person C wrote)
  49. > QuickDraw dies horribly if there is no valid port set when it's called.
  50. > Inside TP, if you haven't changed the port explicitly, one of TP's windows
  51. > will be a valid port; outside TP, it's a problem. Do a SetPort to your
  52. > window after you create it and every time you receive an activate event
  53. > for that window.
  54.  
  55. Some have spoken about things not being initialized, but I would like 
  56. to hear more specifics:
  57.  
  58. (Person D wrote)
  59. > It might be some pointer or other variable that is not initialised. The
  60. > debugger does this automatically.
  61.  
  62. (Person E wrote)
  63. > TP does several things for you in the runtime environment: local (stack)
  64. > vars are initialized to zero; your explicit stack and memory allocations
  65. > get set up; there are lots of subtle differences having to do with TP
  66. > sitting between you and the system; your code executes in a heap zone
  67. > in TP's heap zone; etc.
  68. > You won't know the real answer until you track down the bug and see how
  69. > it could slip through in one environment and not in the other. Sorry.
  70.  
  71. (Person F wrote)
  72. > The THINK Environment is a bit kinder regarding nil pointers, dereferenced
  73. > handles and initial values. Check that you aren't using any variables before
  74. > setting them and that all your handles are locked before dereferencing.
  75.  
  76. Other miscellaneous suggestions:
  77.  
  78. (Person G wrote)
  79. > I've experienced this twice: once a memory leak, once a NewHandle
  80. > call with a bad parameter to the SizeOf function.
  81. > These are frustrating bugs to track down. If it's not apparent from
  82. > inspecting the code, you may have to run the built app under MacsBug
  83. > (with Names on in the compiled app). You'll have to do this eventually
  84. > to make sure your app survives heap scrambling.
  85. > Check your SIZE -1 resource to be sure your built app has as much memory
  86. > as you've allocated in TP's compiler option dialog.
  87.  
  88. (Person H wrote)
  89. > It is probably something not properly initialized. I've had to resort to
  90. > rewriting the application. I've corrected three problems in the new version:
  91. > - proper handling of update events. I think I might have been trying to write
  92. > to windows which weren't mine. At least my application crashed whenever I
  93. > tried to resize my window (stand-alone, not in the Think environment).
  94. > - opening a open-file-dialog with 0 as the number of types specified in the
  95. > type-list. In system 7 this worked ok (showed all files), but in system 6 it
  96. > showed zero files, only folders.
  97. > - pointer arithmetic. I am used to programming on a PC with Turbo Pascal,
  98. > which doesn't make a difference between PACKED and UNPACKED ARRAY's. Well,
  99. > Think most certainly does :-(.
  100.  
  101. (Person I wrote)
  102. > Welcome to the real world. The odds are that your problem is caused by
  103. > improper management of GrafPorts, but that aside, you should become
  104. > proficient in the use of Macsbug to debug your code. It's a requirement
  105. > for doing any sort of Mac programming.
  106.  
  107. Several people have recommended that I obtain Macsbug to determine 
  108. exactly where the crash is happening.  I have done this, and I'm 
  109. learning to use it (and I like it very much).  I have succeeded 
  110. in isolating the code where this particular crash is occuring, but 
  111. I don't know *why* it's happening.  I'm going to post that problem 
  112. separately.
  113.  
  114. Thanks to all who responded!
  115.  
  116. --Kurisuto
  117.  
  118.