beginSheetForDirectory fails, plus EXC_BAD_ACCESS


#1

Ok, I’m totally baffled.

I’ve built the ImageFun project as per the book, up to the point where you add the code to load an image onto the StretchView. All works fine.

Once I add in the image loading, it all goes pear shaped. The project compiles and runs, it draws the white lines on the green StretchView.

When I choose File -> Open, the sheet appears briefly. As soon as I move the mouse, the sheet vanishes. The program continues to run, minus the image loading functionality. When I quite the program, it spits out the following error to the console and freezes:

[quote]Program received signal: “EXC_BAD_ACCESS”.
sharedlibrary apply-load-rules all
(gdb)[/quote]

I read up on EXC_BAD_ACCESS. The suggestion is that objects are being released when the ought not to be.

I’ve compared my code to the book very closely and see nothing wrong. I ditched the project and re-wrote it from scratch, same problem.

I downloaded the sample code from the website and that works fine. I compared it with my own code (i.e. that from the book). I did notice the odd difference here and there - most notably that there are a few less calls to [image release] in the code from the website than in the book. I removed the extra [image release] calls thinking I’d cracked it, but no banana.

Struggling to find any other differences that might cause the issue (there are plenty of differences in variable names and indentation styles, but these didn’t look suspicious), I started copying and pasting functions from the website sample code and replacing their counter parts in my project. No joy.

I eventually completely replaced ALL of the code in my versions StretchView.h, StretchView.m, AppController.h and AppController.m with that from the website sample code. The problem still happens!!

With the knowledge that it wasn’t a coding bug, I started to look elsewhere. The sample project uses a NIB instead of an XIB, but I don’t think that matters. There’s an erroneous link in the NIB from the sample project (the NSSlider is linked to a slider variable in AppController that doesn’t exist), but as the sample project actually works I’m going to ignore that. There are a few project settings which differ (because the sample project was created much earlier), stuff like the project targeting i386 instead of x86_64 and OS X 10.5 instead of 10.6. Everywhere I could see a difference I changed my project to match. I still get the same problem.

So I’m stumped. Admittedly I’m a newbie, but I can’t see any good reason why the project I created fails and the one from the website works.

It’s not a huge issue, I can just move on to the next chapter and pretend that it worked, but I’d like to know, for future reference.

I’ve uploaded a copy of my version of the project to the following location. Note that it has the code copied and pasted from the the website sample project.

mralston.com/ImageFun.zip

If anyone can see what the problem is then I’d love to hear it. I bet it works just fine for everyone else! :slight_smile:


#2

I’d say it’s crashing because (in Interface Builder) App Controller’s StretchView-Outlet is not connected to your StretchView


#3

[quote=“whoami”][ul]
[li] missing @synthesize opacity;[/li]
[li] missing [image release]; in dealloc[/li][/ul][/quote]

From memory, I think that these were in the code I wrote (copying from the book), but not in the example code I downloaded from the BNR website (which is what I attached to this thread).

Good spot, but these don’t seem to be causing the problem. I guess not releasing the image is trivial in this small example program (I realise it could quickly become an issue in larger programs that run for longer).

I’m guessing the missing @synthesize opacity would just cause this property to be ignored (something I’d have spotted later on, once the image was actually being rendered).

That’s it! As soon as I made that connection, everything became hunky-dorey.

I must say that I didn’t expect a missing connection to produce such a cryptic error message, but obviously it does. I’ll have to bear that in mind in the future.

Thanks whoami! Who are you, by the way?


#4

Heh heh. You changed your post on me. Now my reply looks silly. Cheat!

Thanks for the help.


#5

Heh heh. You changed your post on me. Now my reply looks silly. Cheat!

Thanks for the help.[/quote]

Yeah I’m sorry, I was comparing your code with my own… Guess I had a @synthesize opacity; in there because I was too lazy to write the opacity-getter and the [image release]; was only minor (i.e. not related to your crash)

Anyway, I’m glad it works now (and yes, IB connections can be a PITA :slight_smile:)

PS: [quote=“mralston”]Who are you, by the way?[/quote] just someone who tries to help :slight_smile:


#6

Oh well, I choose to call you “Bob”. Thanks Bob.