views:

449

answers:

4

In method viewForZoomingInScrollView: of the delegate to my scrollview I do the seemingly innocent:

// scrollView is the parameter passed to this method

float foo = scrollView.zoomScale

Boom! Crash, hello gdb.

Is this a known bug? Should I submit it?

Cheers, Doug

A: 

It would be helpful to see the output in xcode's debugger console window. Usually when you get a crash, there is some extra information available from the debugger console (open with command-shift-R, or Run > Console in the menu). If there was an exception that caused the crash, it will say which one. In any case, you can type bt (for backtrace) right after a crash and see the call stack when the crash occurs.

In your particular case, it's possible that you've accidentally released the UIScrollView object, but still have a pointer to where the old deallocated object was. This would give you a crash on the next call to any method in UIScrollView, and since zoomScale is a getter accessor, it counts as a method call. The most obvious symptom of this problem would be an EXC_BAD_ACCESS exception in the debugger console when the crash occurs.

Tyler
Tyler, I am sending a message to one of the parms passed to a ScrollViewDelegate method:- (UIView *)viewForZoomingInScrollView:(UIScrollView *)scrollView;I successfully use various properties of scrollView such as scrollView.contentSize and scrollView.contentOffset I can work around this bug by observing changes to scrollView.contentSize and forming a ratio of: scrollView.contentSize/self.unzoomedContentSize.This is not really a show stopper for me. It just worries me a bit about what other buggish bits are lying under rocks in the UIScrollView garden.-Doug
dugla
+2  A: 

I get this and I thought it was because accessing zoomScale ends up calling viewForZoomingInScrollView, resulting in infinite recursion.

But I'm just speculating...

moshy
You're the winner moshy. For some inscrutable reason. scrollView.zoomScale involves a call to viewForZoomingInScrollView: so making the call within that methods recurses. In fact my debugger is currently trying to show me the output of 104684 stack frames. Oy. I'm thinkin' I'll keep my distance from this method.Good lookin' out. Cheers.
dugla
A: 

Doug thanks for that fix. Why didn't I think of that? >_<

And just as the OP said, grabbing the zoomScale property fires viewForZoomingInScrollView everytime.

Pretty much, don't use the zoomScale property inside viewForZoomingInScrollView, if you do? CRASH!!!!

JD
A: 

Doug, thanks for that workaround. It worked great!!

JD