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
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.
If anyone can see what the problem is then I’d love to hear it. I bet it works just fine for everyone else!