yeahdongcn / RSBarcodes

1D and 2D barcodes scanner and generators for iOS7 with delightful controls.
MIT License
383 stars 59 forks source link

EXC_BAD_ACCESS in [RSCornersView drawRect:] #12

Closed Pretz closed 10 years ago

Pretz commented 10 years ago
Crashed: com.apple.main-thread
EXC_BAD_ACCESS KERN_INVALID_ADDRESS at 0x9bff0008

Thread : Crashed: com.apple.main-thread
0  libobjc.A.dylib                0x3b66b652 objc_msgSend + 49 countByEnumeratingWithState:objects:count:
1  Toolkit2                       0x001f6d39 -[RSCornersView drawRect:] (RSCornersView.m:221)
2  UIKit                          0x337794a9 -[UIView(CALayerDelegate) drawLayer:inContext:] + 372
3  QuartzCore                     0x333a5189 -[CALayer drawInContext:] + 100
4  QuartzCore                     0x3338ec5b CABackingStoreUpdate_ + 1858
5  QuartzCore                     0x3346ac1d ___ZN2CA5Layer8display_Ev_block_invoke + 52
6  QuartzCore                     0x3338e50b x_blame_allocations + 82
7  QuartzCore                     0x3338e1bf CA::Layer::display_() + 1118
8  QuartzCore                     0x33371d41 CA::Layer::display_if_needed(CA::Transaction*) + 208
9  QuartzCore                     0x333719d9 CA::Layer::layout_and_display_if_needed(CA::Transaction*) + 24
10 QuartzCore                     0x333713e5 CA::Context::commit_transaction(CA::Transaction*) + 228
11 QuartzCore                     0x333711f7 CA::Transaction::commit() + 314
12 QuartzCore                     0x3336af1d CA::Transaction::observer_callback(__CFRunLoopObserver*, unsigned long, void*) + 56
13 CoreFoundation                 0x30e96039 __CFRUNLOOP_IS_CALLING_OUT_TO_AN_OBSERVER_CALLBACK_FUNCTION__ + 20
14 CoreFoundation                 0x30e939c7 __CFRunLoopDoObservers + 286
15 CoreFoundation                 0x30e93d13 __CFRunLoopRun + 738
16 CoreFoundation                 0x30dfe769 CFRunLoopRunSpecific + 524
17 CoreFoundation                 0x30dfe54b CFRunLoopRunInMode + 106
18 GraphicsServices               0x35d6b6d3 GSEventRunModal + 138
19 UIKit                          0x3375d891 UIApplicationMain + 1136

This crash is happening pretty regularly for users of my app. The crash is on the line

    for (NSArray *corners in self.cornersArray) {

which leads me to believe it has to do with synchronization/multithreading around the cornersArray property. I haven't been able to reproduce it directly myself, but I intend to do some further testing.

yeahdongcn commented 10 years ago

Start digging this.

yeahdongcn commented 10 years ago

I think you are right, although I didn't reproduced this, add the following locks any way.

@synchronized(self.cornersArray) {
        for (NSArray *corners in self.cornersArray) {
            [self __drawCorners:corners];
        }
    }

@synchronized(self.borderRectArray) {
    for (NSArray *borders in self.borderRectArray) {
        [self __drawCorners:borders];
    }
}