Puzzle 2: What's on the menu?
Volume Number: 19 (2003)
Issue Number: 8
Column Tag: Puzzle Page
John and Pals' Puzzle Page
Puzzle 2: What's on the menu?
by John A. Vink
Try to solve this programming puzzle before the score drops to zero. The puzzle is presented as a discussion among engineers in a chat room. As the engineers gather information and make suggestions, see if you can find the solution. If you solve the problem before you get to the end of the puzzle, you get the score in the left hand column.
SDK: I love the monotony of a steady paycheck.
Argus: Tell me about it, SDK.
100 ChrisE: OK, under what circumstances does GetNewMBar return nil?
95 BMA: No MBAR resource?
ChrisE: It's there.
90 SDK: Out of memory? Like, really out?
ChrisE: Mac OS X
SDK: Heh, mine runs out of memory all the time.
SDK: I can tell because it gets slower and console gets really talkative.
85 BMA: What's ResError and MemError have to say about it?
80 ChrisE: ResError() is 0; MemError() is 0.
BMA: Your computrons are leaking out of the bottom of the case, you need to plug it up with silicone fittings.
BMA: Is this Tuttle's machine? It's cursed, I tells you!
75 Argus: Resource not linked in?
70 Argus: Can you use GetResource on the MBAR?
ChrisE: Whaddya mean "not linked in"?
Argus: What are you really trying to do? Is the resource really available to your app?
BMA: When you said "it's there", did you look in the executable or in the project to verify?
65 ChrisE: OK, I have one project, two targets. The targets build slightly different ways, but with identical source, resources, etc.
ChrisE: One target builds and runs fine.
60 ChrisE: The other (mostly identical) target gets nil from GetNewMBar.
BMA: You got Resorcerer handy?
55 KeithS: Maybe one target requires a MDEF that isn't present in the other?
Pie R. Square: Why is ResError() 0?
50 ChrisE: I DeRez the .rsrc files in both packages and they're identical.
BMA: Bit for bit?!
45 Argus: Throw in a GetResource('MBAR', x) and see if you get a resource back.
Pie R. Square: They link to the same set of libraries?
ChrisE: OK, what's hex for MBAR? I'm in gdb.
JAV: BaseMaster says: 4D424152
BMA: For the record, print/x "MBAR" in gdb does what you want.
40 BMA: Do you load any other resources before loading the MBAR?
35 KeithS: gdb ; br GetMenuBar(); call (int) GetResource ( 'MBAR', 128 ) and see if it works.
ChrisE: GetResource returns 0.
Pie R. Square: And ResErr() is 0?
ChrisE: ResError is 0.
30 Argus: ResError is volatile and can get reset quickly.
25 BMA: Your plist is hosed and your resource file is not being opened at all.
BMA: Diff the plists.
20 KeithS: call (void) PrintResourceChain(1)
BMA: Do the resource files match the app names?
15 ChrisE: Plists differ only in the name of the app, but in the one that's broken, the plist name differs from the name of its app.
BMA: There you go.
ChrisE: In the one that works they match.
ChrisE: Bravo, guys. JAV, write this up.
ChrisE: PrintResourceChain shows my .rsrc isn't there, probably because the plist has the wrong name.
10 KeithS: So CFBundle is failing to open your resource file because it's got your exectuable wrong.
BMA: Well, in your case the file itself has the wrong name, but yes.
5 ChrisE: The file has the same name as the executable, but the plist entry is different. I had changed the name in the target editor but an old name persisted in the plist.
BMA: Oh I see, I got it backwards.
ChrisE: Executes correctly now.
ChrisE: Thanks! Score:
85-100 That was pretty good. 65-80 You must have called a friend on the inside. 45-60 You've been carbonizing your apps like a good developer. 25-40 You see, GetMenuResource is a classic Mac OS API.
85-100 That was pretty good.
65-80 You must have called a friend on the inside.
45-60 You've been carbonizing your apps like a good developer.
25-40 You see, GetMenuResource is a classic Mac OS API.
0-20 Stick to Cocoa and command line apps.
John A. Vink (aka "JAV") is a software engineer for Apple Computer, Inc. He takes a break in the summer to follow INXS on tour. His pals are a bunch of smart friends scattered throughout the Mac programming landscape. You can contact him at firstname.lastname@example.org. (The pals reference makes sense with the "John And Pals' Puzzle Page" title)