Vincent Gable’s Blog

May 14, 2008

NSAlert + Sheets + Threads = Inexplicable Bugs

Filed under: Bug Bite,Cocoa,Interface Builder,MacOSX,Objective-C,Programming | , ,
― Vincent Gable on May 14, 2008

UPDATED 2008-12-26: in general, all AppKit code should be called on the main thread.

Problem:
When using an NSAlert to display a sheet in a multi-threaded application, unexpected badness can happen.

I was using
beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo:
To display an NSAlert as a sheet.

But when the sheet appeared, the window it was attached to disappeared and got into some weird broken state where it would appear iff the application was not frontmost.

Fortunately, I remembered having encountered weirdness with NSAlert sheets before. The symptoms were different (previously the alert didn’t have focus), but the same solution still worked.

Solution: make sure the message to display the sheet is sent by the main thread. To do this, put the call to beginSheetModalForWindow:modalDelegate:didEndSelector:contextInfo: inside another method, showMyAlert, then use performSelectorOnMainThread:withObject:waitUntilDone: to make sure showMyAlert is called on the main thread.

Work around use runModal to display the alert as a modal dialog instead of a sheet. runModal Does not appear to have any problems when called from other threads.

Just like last time:

The whole incident feels funny to me. I suspect there may be some deeper issue at work that I am not aware of. When I have time to investigate further I shall update this post. Unfortunately I don’t have time to look into ‘solved’ bugs today.

UPDATED 2008-12-26: in general, all AppKit code should be called on the main thread.

May 13, 2008

Fixing Blurry Images

Filed under: Bug Bite,MacOSX,Programming
― Vincent Gable on May 13, 2008

I had an issue today where an image (A .png at 72 DPI with transparency, inside an NSImageView — if that makes any difference) in a window was blurry. The image was perfectly sharp in Interface Builder’s library panel, but when I placed it in a window, it turned blurry. Maddening!

A (mysterious) workaround: put the image where you want it. Then move it, then hit undo. When it snaps back to where you want it, it should be sharp.

I have absolutely no idea why this worked, or why the images were blurred by Interface Builder/XCode in the first place. (And yes, the images were blurry when the application was built and run. It wasn’t just a display bug in Interface Builder). It was purely coincidence that I stumbled across this “solution”.

May 12, 2008

Trademarking Shape

Filed under: Design,Quotes
― Vincent Gable on May 12, 2008

The Wall Street Journal on Apple trademarking the shape of the iPod (emphasis mine):

These nontraditional marks are difficult to obtain. But unlike more commonly used utility and design patents, which exist to cover functions and the ornamental look and feel of products and expire after a set number of years, trademarks can remain in force potentially forever.

…While competitors may eventually appropriate the iPod’s inner workings, as utility patents expire, they will risk litigation if their products come too close to the trademarked shape of the iPod, including its popular circular-touchpad interface.

Moreover, trademark law allows the holder to sue not only manufacturers but also distributors of competing products whose attributes so resemble those of the protected mark that they create the likelihood of confusion in the marketplace.

…The key to obtaining nontraditional trademarks is to convince an examiner in the U.S. Patent and Trademark Office that the average consumer associates the design attribute in question exclusively with the company seeking the trademark; in Apple’s case, this meant proving that the average shopper for a media player identifies the shape of an iPod with Apple.

That sounds like a pretty big sue-stick.

Intellectual-property laws haven’t interested me much. Partly because the zelots and freetards are such a turn off. But mostly because it turns out that patent law hasn’t actually been a barrier to me writing code (*gasp*). I just don’t see evidence that what we have today is an irredeemably broken system (although there are compelling historical anecdotes worth reading that says differently). Maybe that’s just my ignorance talking, but at least it’s been bliss so far.

It’s a little sad to read that the “design” in “design patents” apparently means “the ornamental look and feel of products” to most business folks.

Most people make the mistake of thinking design is what it looks like. People think it’s this veneer — that the designers are handed this box and told, ‘Make it look good!’ That’s not what we think design is. It’s not just what it looks like and feels like. Design is how it works.

–Steve Jobs, CEO, chairman and co-founder of Apple Inc. in a 2003 New York Times magazine interview.

Early Cybernetics in Baseball

Filed under: Quotes | , , , ,
― Vincent Gable on May 12, 2008

Much of Improvement in Baseball Is Attributed to Evolution and Steady Progress of Mechanics and Invention

WHEN Babe Ruth hits three home runs in one game or the home team cracks out a barrage of base hits to score seven or eight times in one inning, it does not necessarily mean that long-distance hitting in modern baseball comes from superiority of today’s players over those of years past. The truth is that much of the improvement in the game itself and in the proficiency of its players has come from evolution and progress in science and invention.

Popular Mechanics, May, 1924

May 10, 2008

Richard Stallman Does Bizarre Things

Filed under: Design,Quotes,Usability
― Vincent Gable on May 10, 2008

For personal reasons, I do not browse the web from my computer. (I also have not[sic] net connection much of the time.) To look at page[sic] I send mail to a demon which runs wget and mails the page back to me. It is very efficient use of my time[sic], but it is slow in real time.

Richard Stallman, 15 Dec 2007

How in touch with regular people do you think that guy is? How well do you think a system he designed would server their needs? How well do you think it would serve your needs? (I mean I think it’s pretty fair to say you use the internet a bit more … shall we say … functionally.)

Apparently GNU/Linux can’t even meet a hardcore nerd’s needs.

May 9, 2008

The Back Button is Now #3

Filed under: Accessibility,Design,Quotes,Research,Usability
― Vincent Gable on May 9, 2008

Among other things, (this study) found that the Back button is now only the 3rd most-used feature on the Web. Clicking hypertext links remains the most-used feature, but clicking buttons (on the page) has now overtaken Back to become the second-most used feature. The reason for this change is the increased prevalence of applications and feature-rich Web pages that require users to click page buttons to access their functionality.

Jakob Nielsen’s Alertbox, May 6, 2008:

May 6, 2008

Do Your Dishes In The Tub

Filed under: Tips
― Vincent Gable on May 6, 2008

Most bath faucets move significantly more gallons per minute then sink-faucets. So if you need to rinse something out quickly, do it in the tub. I’ve been using the tub/shower to rinse out large blender carafes for years, and it’s worth the walk to/from the bathroom, because of how much more quickly I can fill a 2L container. More water/second usually means more force. So if you don’t like wasting your time, rise your dishes in the tub.

May 4, 2008

Getting Mac OS X Version Information

Filed under: MacOSX,Objective-C,Programming,Sample Code,UNIX | , ,
― Vincent Gable on May 4, 2008

Cocoa

For a human-readable string, use [[NSProcessInfo processInfo] operatingSystemVersionString]. It looks like “Version 10.5 (Build 9A581)”, but that format might change in the future. NSProcessInfo.h explicitly warns against using it for parsing. It will always be human-readable though.

For machine-friendly numbers, use the Gestalt function, with one of the selectors:
gestaltSystemVersionMajor (in 10.4.17 this would be the decimal value 10)
gestaltSystemVersionMinor (in 10.4.17 this would be the decimal value 4)
gestaltSystemVersionBugFix (in 10.4.17 this would be the decimal value 17)
Do not use gestaltSystemVersion unless your code needs to run on OS X 10.2 or earlier. It’s a legacy function that can’t report minor/bugfix versions > 9; meaning it can’t distinguish between 10.4.9 and 10.4.11. The CocoaDev wiki has example code that works in 10.0 if you need to go that route.

Here’s a simpler example of using Gestalt:

- (BOOL) usingLeopard {
  long minorVersion, majorVersion;
  Gestalt(gestaltSystemVersionMajor, &majorVersion);
  Gestalt(gestaltSystemVersionMinor, &minorVersion);
  return majorVersion == 10 && minorVersion == 5;
}

Scripts

For scripts and command-line work, there is the sw_vers command.
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.5
BuildVersion: 9A581
$ sw_vers -productName
Mac OS X
$ sw_vers -productVersion
10.5
$ sw_vers -buildVersion
9A581

Java

Check the value of:

System.getProperty("os.name");
System.getProperty("os.version");

Fallback

Finally, if you must, you can parse /System/Library/CoreServices/SystemVersion.plist — but I don’t like the idea of doing that. There’s a chance that the file could have been corrupted or maliciously altered. It seems safer, and less complicated, to directly ask the operating system it’s version.

Minimum OS Requirements

To enforce a minimum OS requirement for your application, you can set the LSMinimumSystemVersion key in the Info.plist file. Big Nerd Ranch has a more robust, user-friendly, but complicated solution for older legacy systems.

April 28, 2008

WARNING!

Filed under: Design |
― Vincent Gable on April 28, 2008

A collection of warning signs. Some are quite funny; my favorite so far.

There’s also a book (unrelated to the flickr group), but disappointingly it does not give bibliographical information on where the signs came from.

Here’s a blog of safety graphics.

Wikipedia vs Television

Filed under: Quotes,Research | , , , ,
― Vincent Gable on April 28, 2008

So if you take Wikipedia as a kind of unit, all of Wikipedia, the whole project–every page, every edit, every talk page, every line of code, in every language that Wikipedia exists in–that represents something like the cumulation of 100 million hours of human thought. I worked this out with Martin Wattenberg at IBM; it’s a back-of-the-envelope calculation, but it’s the right order of magnitude, about 100 million hours of thought.

And television watching? Two hundred billion hours, in the U.S. alone, every year. Put another way, now that we have a unit, that’s 2,000 Wikipedia projects a year spent watching television. Or put still another way, in the U.S., we spend 100 million hours every weekend, just watching the ads.

From one of more inspiring talks I’ve read in a long time.

« Newer PostsOlder Posts »

Powered by WordPress