TweetFollow Us on Twitter

Feb 91 Letters
Volume Number:7
Issue Number:2
Column Tag:Letters

Enough Bus Errors

By Kirk Chase, Editor

Mr. Bus Error

David Dunham

Seattle, WA

Aargh! I’ve had it! Enough bus errors! As a developer, I like to reduce my number of bugs, so I keep Mr. Bus Error running (more later). As a user, I like to run programs. I don’t like them generating bus errors, having to reboot without Mr. Bus Error and rerunning the program. I’ve had to do this with software from Aldus, Apple, Ashton-Tate, and Microsoft (to name just a few large companies).

With the Macintosh’s double-pointer memory handles, it’s easy to dereference a NIL handle. Consider this code:

/* 1 */

h = NewHandle(sizeof(dataStruct));
(**h).field = 0;

The problem, as should be obvious, is that NewHandle() may fail if the heap is too full or fragmented. Before we use a handle, we should test it:

/* 2 */

if (h != NIL)  /* Is it valid? */

But we may have a lot of NewHandle()s (or GetResource()s) in our program. It’s easy to miss one. What happens if we do? Both NewHandle() and GetResource() return NIL (0L) if they can’t return a valid handle. We then try to double-dereference this. *h is *(0L), the contents of location 0. We have no way of knowing what’s there (it’s usually set by Finder when an application starts, but of course the Macintosh is a multi-tasking machine, with other applications, drivers, and GetNextEvent() patches, any of which could change it on purpose or through their own bug). **h is **(0L), or whatever location 0 points to. We really have no idea what location 0 points to. So (**h).field = 0; has just trashed some unknown address. This may never hurt us (since there are so many possible addresses), which is why so many errors of this type are released. But this is just gambling that location 0 will always contain some benevolent value. I wouldn’t bet my data on that.

How can we catch dereferencing a NIL handle? We end up using the contents of location 0 as an address, so the simple solution is to put an invalid address value at location 0. Mr. Bus Error is a fine INIT that does just this (once per VBL interrupt, if my memory’s correct). The value it uses is 0xF0F0F1. If used as an address, this generates a bus error on 68020 and 68030 machines. On a 68000, it generates an odd address exception. Simple. Easy. No work on your part (other than to locate Mr. Bus Error; it’s on any developer CD-ROM from Apple and no doubt many other places). No more will you forget to test for NIL handles and make my life miserable (and your own, as you try to find those intermittent crashes -- the ones from f = (**h).field are really fun).

Peter Polash came up with a technique that’s even better, though it does involve actual work. Each time through your event loop, test what’s at location 0. If it’s not what you set it to, you know you’ve changed it. Otherwise, you set it to a value like 0xF0F0F1. This gives you exactly the same error-finding functionality as Mr. Bus Error, with the added bonus of being able to tell you if you ever set something in a purged handle ((**h).field = 0; since *h is NIL for a purged handle) or NIL pointer, and (to within one event) when you set it. You may have minor compatibility problems during testing with this technique, since you’ll probably uncover other tasks changing location 0 on you.

Please use NIL handle discipline (which brings up the point that many debuggers can help you, too). Other error schemes aren’t sufficient (one unrunnable program was written with MacApp).

A Small Error

Allen Stenger

Gardena, CA

Thank you for publishing the interesting and clearly-written article by Dennis R. Cohen on LZW compression (October 1990). MacTutor needs more short articles like this one, that illustrate a technique without trying to develop a full-blown application.

I would like to point out a small error in the code which may trouble your readers: the compression program produces incorrect results if it overwrites an existing file. The format of the output file is a 56-byte header, followed by the compressed data. When opening a new output file, the routine GetOutputFile writes a dummy block for the header, which will later be filled in with the real header data; in the meantime the compressed data will be written following the dummy header. But when opening an existing file, no dummy header is written, so the compressed data is written from the very beginning of the file and then the first part is overwritten with the header.

This may touch on a question of style. The compression and decompression programs use an “economical” approach of reusing an existing file, rather than the “brute force” approach of deleting an existing file and always starting from scratch. Which is better? Because the economical approach splits the processing into two paths, it may be more error-prone (as shown by the error that did occur, above; also note that the file creator and file type of the existing file are left unchanged, rather than being set to the values for new files). Does the economical approach have any advantages?

Revised DrawMyStuff.c

Chip Zempel

Fair Oaks, CA

Note: Source code files accompanying this letter are located on MacTech CD-ROM or source code disks.

Thanks for Mark B. Kauffman’s introduction to using the THINK C Class Library in the September ‘90 issue. It finally made me get off my butt and get my feet wet in OOP, if I can mix my metaphors a bit.

I made some changes to his code that illustrate one of OOP’s best features -- polymorphism, or the ability of a subclass to override an ancestor’s methods -- and I thought you might like to share them with your other readers who are just learning OOP.

Kauffman’s DrawMyStuff() sets up a line, an array of four rectangles, and an array of four ovals. Then he sends them various messages to set their locations and draw and erase themselves. In a “real world” drawing program, of course, you wouldn’t know beforehand what type of objects the user would want to create. Your program would probably allocate a big array of pointers to CShapes (the parent class) and then stuff in whatever specific shapes the user selected at run time.

My revised DrawMyStuff() has just one big generic array of CShapes, and sends them all generic locate, draw, and erase messages. Note that the only part of my code that “knows” whether each shape is a rectangle, line, or oval is the section that initializes each object. (The user would do this in a real program.) Everything else -- setting locations, drawing, erasing, and deleting -- is done “blind.” My version doesn’t know what object is there, and it doesn’t need to. It just says “draw yourself,” or whatever, and the object responds to the message it receives with the method implemented for its subclass.

The final result looks identical to the original when the screen is drawn. (Note however, that I drew and erased the line object in a different order, so that I could send all nine objects their Draw() message in the same “for” loop.) Here’s the code (and please keep running more THINK Class Library tutorials!):

/* 3 */

/*
 * Source  - DrawMyStuff.c
 * based on Mark B. Kauffman’s article
 * in the 9/90 MacTutor
 *
 * revised to demonstrate polymorphism
 * -- the way a subclass can override
 * its ancestor’s methods  
 */
#include “oops.h”
#include “CShape.h”

void DrawMyStuff()
{
   int  i;
 
   /* set up a big generic array */
   CShape *myShape[9];
   
   /* let’s create 4 rectangles... */
   for (i=0; i<4; i++)
   myShape[i] = new(CRectangle);
   /* ... one line...     */
   myShape[4] = new(CLine);
   /* ... and 4 ovals     */
   for (i=5; i<9; i++)
   myShape[i] = new(COval);

   /* place the rectangles  */
   myShape[0]->SetShapeLoc(200,100,300,200);
   myShape[1]->SetShapeLoc(210,110,290,190);
   myShape[2]->SetShapeLoc(220,120,280,180);
   myShape[3]->SetShapeLoc(230,130,270,170);

   /* place the line */
   myShape[4]->SetShapeLoc(100,50,300,50);

   /* place the ovals     */
   myShape[5]->SetShapeLoc(100,100,200,200);
   myShape[6]->SetShapeLoc(110,110,190,190);
   myShape[7]->SetShapeLoc(120,120,180,185);
   myShape[8]->SetShapeLoc(130,130,170,170);

   /* here’s the fun part! send each shape */
   /* a Draw() message, generically         */
   for (i=0; i<9; i++)
   myShape[i]->Draw();
   
   /* relocate the line and Erase() */
   myShape[4]->SetShapeLoc(210,110,290,110);
   myShape[4]->Erase();
   
   /* delete everything, again generically */
   for (i=0; i<9; i++)
   {
   delete(myShape[i]);
   }
}
/* end of listing - DrawMyStuff.c */

P.S. I found a terrific book on OOP -- Object Oriented Program Design, With Examples in C++ by Mark Mullin, from Addison-Wesley. The reader gets to look over his shoulder as he develops a inventory-personnel-accounting database application using object-oriented techniques. He explains why he makes the choices he makes, presents the special features of OOP languages (such as abstraction, encapsulation, and polymorphism) as they become useful, and lays out general rules (and some exceptions!) for good OOP practice. Definitely worth a look!

HyperDA II and HyperEngine 2.0

Symmetry Software

SCOTTSDALE, AZ

HyperDA II , Symmetry Software’s HyperCard stack access desk accessory, begins shipping in December. HyperDA II will support major HyperCard™ 2.0 features such as stylized text, multiple, scrollable, resizable windows, “Hot Text”, visual effects and sound. Support for selection tools that allow users to copy graphics and text to the clipboard are built in also. HyperDA II will support either HyperCard 1.x or 2.0 file formats, and you can even have both running in seperate windows on the desktop at the same time.

Using HyperDA II, the enduser gains immediate access to stacks via the Apple DA menu, while bypassing the large memory requirements of MultiFinder and HyperCard. Users enjoy the same browse, edit and print tools found in HyperCard.

Registered users of HyperDA version 1.x can obtain an update for $29 (includes s/h) by calling Symmetry’s Customer Service department. The upgrade is FREE (with proof of purchase plus $5 shipping), if HDA 1.x was purchased on or after November 10, 1990. HyperDA II’s manufacturer’s suggested retail is $129.

Supporting the enhanced HyperCard™ 2.0 command set, HyperEngine 2.0, Symmetry Software’s stack access development tool, is due for release Q1’91. HyperEngine will support major features such as stylized text, multiple, scrollable, resizable windows, “Hot Text”, visual effects and sound. Support for selection tools that allow users to copy graphics and text to the clipboard are built in also. The technology is based on Symmetry’s HyperDA II Software and has been licensed to other developers since 1988.

Supporting MPW, Think C and Assembly languages, HyperEngine allows the developer to build stack access into their applications. The enduser gains immediate access to stacks while bypassing the large memory requirements of MultiFinder and HyperCard.

A HyperEngine developer’s tool kit is sold by Symmetry that provides developers with the resources to add stack access in their own applications. Help, tutorial or reference stacks can be designed with the HyperCard environment, saving developers the need to use valuable programming resources. You can obtain the developer kit for $125 USD, plus shipping and handling direct from Symmetry Software.

Symmetry Software Corporation can be reached at 8603 East Royal Palm Road, Ste 110, Scottsdale, Arizona, 85258. 602-998-9106.

TextWare Technology Now Available

TextWare Corporation

P.O. Box 3267

Park City, UT 84060

(801) 645-9600

(801) 645-9610 (FAX)

TextWare Corporation has now released its technology for the Macintosh. TextWare brings full text indexing and retrieval capabilities to the Macintosh. It is fully compatible with TextWare for PC and LAN platforms for those working in a mixed environment. TextWare is ideal for indexing large volumes of information such as those found on servers or CD-ROMs. The TextWare Toolkit is available to developers for those wishing to add TextWare capability to their products. Contact TextWare for more information.

 

Community Search:
MacTech Search:

Software Updates via MacUpdate

Maintenance 2.9.9 - System maintenance u...
Maintenance is a system maintenance and cleaning utility. It allows you to run miscellaneous tasks of system maintenance: Check the the structure of the disk Repair permissions Run periodic scripts... Read more
Deeper 2.8.8 - Enable hidden features in...
Deeper is a personalization utility for macOS which allows you to enable and disable the hidden functions of the Finder, Dock, QuickTime, Safari, iTunes, login window, Spotlight, and many of Apple's... Read more
BetterTouchTool 3.9998 - Customize multi...
BetterTouchTool adds many new, fully customizable gestures to the Magic Mouse, Multi-Touch MacBook trackpad, and Magic Trackpad. These gestures are customizable: Magic Mouse: Pinch in / out (zoom)... Read more
OnyX 4.3.6 - Maintenance and optimizatio...
OnyX is a multifunction utility that you can use to verify the startup disk and the structure of its system files, to run miscellaneous maintenance and cleaning tasks, to configure parameters in the... Read more
Acorn 7.3.2 - Bitmap image editor.
Acorn is a new image editor built with one goal in mind - simplicity. Fast, easy, and fluid, Acorn provides the options you'll need without any overhead. Acorn feels right, and won't drain your bank... Read more
Google Chrome 109.0.5414.119 - Modern an...
Google Chrome is a Web browser by Google, created to be a modern platform for Web pages and applications. It utilizes very fast loading of Web pages and has a V8 engine, which is a custom built... Read more
ASPPPPP 1.3.99999999999 - Create cursor...
ASPPPPP brings Aperture Science's portal technology to your desktop. Avoid carpal canal syndrome and save millions of pixels of cursor moving. When launching the app, you first set the position of... Read more
beaTunes 5.2.31 - Organize your music co...
beaTunes is a full-featured music player and organizational tool for music collections. How well organized is your music library? Are your artists always spelled the same way? Any R.E.M. vs REM?... Read more
FotoMagico 6.3.3 - Powerful slideshow cr...
FotoMagico lets you create professional slideshows from your photos and music with just a few, simple mouse clicks. It sports a very clean and intuitive yet powerful user interface. High image... Read more
RoboForm 9.4.1 - Password manager; syncs...
RoboForm is a password manager that offers one-click login, mobile syncing, easy form filling, and reliable security. Password Manager. RoboForm remembers your passwords so you don't have to! Just... Read more

Latest Forum Discussions

See All

‘Railbound’ Massive 2.0 Update To Bring...
Railbound from Afterburn Games is set to get a massive update this week. Since its launch, Railbound has gotten a good amount of support already. Read about the most recent big update here. Afterburn Games will bring Railbound 2.0 to mobile and PC... | Read more »
TouchArcade Game of the Week: ‘Madness/E...
Sometimes a game comes along that feels so purely built for mobile, and its controls and mechanics come together so well on the touchscreen, I say that Apple should just pre-install it on every iPhone it sells. I very much feel that way about... | Read more »
SwitchArcade Round-Up: ‘ATONE’, ‘Dance o...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for January 27th, 2023. In today’s article, we mop up the remaining releases of the week. There are quite a few, thanks to some slipping out after I went home last night. There are... | Read more »
‘Prehistoric Isle 2 ACA NEOGEO’ Review –...
It’s somewhat surprising how clearly one can draw a line between SNK before NEOGEO’s launch and after. The likes of Psycho Soldier and Ikari were relegated to cameo appearances, and only a few lucky pre-NEOGEO IPs ever saw follow-ups on the multi-... | Read more »
Old School RuneScape announces landmark...
Jagex has announced some groundbreaking news for fans of its iconic MMORPG, Old School RuneScape. For the first time in the game's 15-year history, the player base has voted in favour of the implementation of a new skill to the retro masterpiece... | Read more »
Physics Puzzler ‘Squiggle Drop’ From Noo...
Noodlecake’s Squiggle Drop () featuring more than 100 puzzles is the final new Apple Arcade release of January 2023. When Apple revealed the games for the month, I was very curious to see how Squiggle Drop would turn out. It seemed like a game I’d... | Read more »
‘Of Two Minds’, a Psychoanalytical FMV G...
We are truly in the renaissance of full-motion video games since the genre first arrived in the late ’80s and early ’90s before dying an ugly death due to the poor quality of those gaming experiences as well as the poor quality of the actual video... | Read more »
SwitchArcade Round-Up: ‘Goldeneye’ Comin...
Hello gentle readers, and welcome to the SwitchArcade Round-Up for January 26th, 2023. The big news is that Goldeneye for Nintendo Switch Online finally has a release date, and it’s soon as it could be. We have a ton of new releases to go through... | Read more »
Previously Cancelled Co-Op City Builder...
Back in August of 2021 developer Supercell formally announced Everdale to the world, a cooperative city building game that had already been in a smaller form of beta testing under a different name for at least a year prior. That announcement kicked... | Read more »
Burgeon and Flourish are releasing an FM...
Game development can take a while, with bugs, reworks and good old-fashioned arguments delaying things. However, the upcoming FMV game Of Two Minds may have the longest source material to game delay of all time, being a huge 30 years in the making... | Read more »

Price Scanner via MacPrices.net

Apple may release high-end Reality Pro device...
Mark Gurman, in this weeks’s Power On newsletter, states that Apple may attempt to release a high-end, nearly $3000, Reality Pro device in an attempt to move the VR market forward. With potential... Read more
13″ M2 MacBook Pros available today at Apple...
Apple standard-configuration 13″ MacBook Pros with M2 CPUs in stock and available today starting at $1169, Certified Refurbished, and ranging up to $150 off original MSRP. These are the cheapest 13″... Read more
Get a 13″ M2 MacBook Air at Apple today for a...
Apple has standard-configuration 13″ M2 MacBook Airs in stock and on sale starting at only $1079, Certified Refurbished, and ranging up to $150 off MSRP. These are the cheapest M2-powered MacBooks... Read more
Apple Card special offers for January and Feb...
Apple Card is offering special offers for January & February, 2023 which include a $75 Daily Cash offer for customers who open a new Apple Card through February and a $55 Daily Cash offer for new... Read more
New low price: Clearance 14″ M1 Pro MacBook P...
B&H Photo has dropped prices on Apple’s previous-generation 14″ 8-Core M1 Pro MacBook Pros by $300 off original MSRP, now only $1699. Free 1-2 day shipping is available to most US addresses: – 14... Read more
Apple has clearance 27-inch 5K iMacs in stock...
Apple has a full line of Certified Refurbished 2020 27″ 5K iMacs available starting at only $1169 and ranging up to $810 off original MSRP. Apple’s one-year warranty is standard, shipping is free,... Read more
Price drop! Apple has M1 Mac mini in stock fo...
Apple has dropped prices on clearance M1-powered Mac minis in their Certified Refurbished section to a new low starting price of only $469. Each mini comes with Apple’s one-year warranty, and... Read more
The Latest Rumors and Potential Features of a...
The rumors are flying and speculation is running rampant around the possibility of a new Apple iMac Pro. It is expected to be a powerful computer in Apple’s lineup, and people are already asking what... Read more
New low price: Apple Studio Display for $1399...
Amazon has Apple Studio Displays on sale for $200-$150 off MSRP for a limited time. Shipping is free: – Studio Display (Standard glass): $1399.99 $200 off MSRP – Studio Display (Nano glass): $1749 $... Read more
Week’s Best Apple Deals: Clearance 14-inch M1...
With the introduction of new M2 Pro and M2 Max-powered 14″ MacBook Pros, Apple and its retailers have dropped prices on standard-configuration 14″ MacBook Pros with M1 Pro CPUs by as $570 off... Read more

Jobs Board

Wireless Device Portfolio Manager - *Apple*...
…in our Retail Wireless journey. The successful Device Portfolio Manager - Apple will work cross-functionally to develop, oversee and execute a device roadmap Read more
Bilingual Level 1 *Apple* Support Specialis...
…generous employee benefits! Our client is currently seeking a qualified Bilingual Level 1 Apple Support Specialist to join their team. This role can be hybrid / Read more
Security Officer - *Apple* Store - NANA Reg...
…security is our \#1 priority\. This is a public environment at the Apple Store and surrounding areas with the corresponding levels of traffic \(employees, visitors, Read more
Device Portfolio Manager - *Apple* - DISH (...
…in our Retail Wireless journey. The successful Device Portfolio Manager - Apple will work cross-functionally to develop, oversee and execute a device roadmap Read more
Senior STE / *Apple* / OTT / Streaming Serv...
…and perform tests to validate large-scale content operations and releases. As an Apple STE, you'll partner with the content and streaming teams to ensure smooth Read more
All contents are Copyright 1984-2011 by Xplain Corporation. All rights reserved. Theme designed by Icreon.