开发者

Calling [self setNeedsDisplay] in UIView crashes every time

开发者 https://www.devze.com 2023-01-27 07:47 出处:网络
This just started happening when I tested on my iPad using the new 4.2.1 firmware using the iOS 4.2 final SDK, however I\'ve changed a lot of code since the last time I tested on my device so I can\'t

This just started happening when I tested on my iPad using the new 4.2.1 firmware using the iOS 4.2 final SDK, however I've changed a lot of code since the last time I tested on my device so I can't be 100% sure it's 4.2.1 related though it seems very likely. I was previously testing on 4.2 beta3 with 4.2 beta3 SDK with no problems.

I have a view that does some Quartz 2D drawing. Every time I call [self setNeedsDisplay] on it to update the drawing, the application crashes with a Signal 0. I've never had a problem with this before and was always using that call to redraw the view without issue.

Has anyone run into this before or has any info on what the cause could be? The crash is happening before drawRect: is called, so I'm not sure how to debug this.

It does not crash in the simulator, only on the actual device.

No crash logs are generated on the device and the exact error that is displayed in the debugger is this:

Program received signal:  “0”.
Data Formatters temporarily unavailable, will re-try after a 'continue'. (Unknown error loading shared library "/Developer/usr/lib/libXcodeDebuggerSupport.dylib")

Also, before anyone suggests that it's an issue with using too much memory as signal 0 errors often are, the app is using only 1.4mb of ram when the crash ha开发者_Python百科ppens (viewed in Instruments) and I don't see a big spike of allocations or anything before it crashes. It crashes with just over 1.4mb used.


Update: I've been working on this more, here's what I've found so far.

  1. There seem to be some issue with the 4.2 final SDK and iOS 4.2.1 but they don't seem related to this particular issue.
  2. I've downgraded to 4.2 beta 3 that was previously working for me, and it is still crashing the same way
  3. If I don't override the drawRect: method in my class and I call setNeedsDisplay is DOESN'T crash.
  4. If I override drawRect: even if I keep it empy (just calling [super drawRect:] or even leaving it completely empty) it DOES crash.

So for some reason, just implementing drawRect: at all is causing this problem. It makes no sense though as I've implemented this code this same way since I started this project and am only now experiencing this issue.


Update: It turned out to be a memory issue after all related to the size of the view that I'm doing the drawing in. Although the Instruments tool seems to not be displaying it for some reason, according to this post: iPhone + UIView. Enormous memory consumption during drawRect. Any strategies for reducing this? when using setNeedsDisplay: on a large view there is a huge memory spike and the only real way to fix it is to use smaller tiled views and draw in each separately.

I removed a bunch of images from my scrollview and was able to see the memory warnings without the crash. I found if I lower the size of my drawing view in the scroll view, I no longer get memory errors. I had the drawing view at almost 4000x4000 before. Lowered it to 3000x2000 and no more crashes.

Now the issue for me is I need one contiguous drawing view, due do the nature of what I'm drawing I'm not sure it's possible to tile it. But that's a question for another post.


Try this Other Answer/Solution Basically it is likely a memory problem.

0

精彩评论

暂无评论...
验证码 换一张
取 消