iOS 8.1 with ZXING error ARC forbids explicit message send of 'autorelease' - ios

I developed a DataMatrix Reader for Android with ZXING, and works fine, now I'm working in the version of iOS, but I have this errors when I want to use the library inside my project:
iOS SDK 8.1 and Library
ZXING: https://github.com/TheLevelUp/ZXingObjC
I use the COCOAPODS:
platform :ios, '7.0'
pod 'ZXingObjC', '~> 3.0'
I implemented the library in my project with Cocoapods, now I want to use in my App like this:
#import "ViewController.h"
#import "ZXingObjC.h"
#interface ViewController ()
#end
#implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
- (IBAction)scanBarcode:(id)sender {
CGImageRef imageToDecode; // Given a CGImage in which we are looking for barcodes
ZXLuminanceSource *source = [[[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode] autorelease];
ZXBinaryBitmap *bitmap = [ZXBinaryBitmap binaryBitmapWithBinarizer:[ZXHybridBinarizer binarizerWithSource:source]];
NSError *error = nil;
// There are a number of hints we can give to the reader, including
// possible formats, allowed lengths, and the string encoding.
ZXDecodeHints *hints = [ZXDecodeHints hints];
ZXMultiFormatReader *reader = [ZXMultiFormatReader reader];
ZXResult *result = [reader decode:bitmap
hints:hints
error:&error];
if (result) {
// The coded result as a string. The raw data can be accessed with
// result.rawBytes and result.length.
NSString *contents = result.text;
// The barcode format, such as a QR code or UPC-A
ZXBarcodeFormat format = result.barcodeFormat;
} else {
// Use error to determine why we didn't get a result, such as a barcode
// not being found, an invalid checksum, or a format inconsistency.
}
}
#end
but I have this error:
DataMatrixReader/ViewController.m:32:99: ARC forbids explicit message
send of 'autorelease'
DataMatrixReader/ViewController.m:32:99: 'autorelease' is unavailable:
not available in automatic reference counting mode
concretly in this line:
ZXLuminanceSource *source = [[[ZXCGImageLuminanceSource alloc]
initWithCGImage:imageToDecode] autorelease];
Help from "iamnichols"...and after the change the line:
ZXLuminanceSource *source = [[[ZXCGImageLuminanceSource alloc]
initWithCGImage:imageToDecode] autorelease];
to
ZXLuminanceSource *source = [[ZXCGImageLuminanceSource alloc]
initWithCGImage:imageToDecode];
Error:
: CGBitmapContextGetData: invalid context 0x0. This is a
serious error. This application, or a library it uses, is using an
invalid context and is thereby contributing to an overall degradation
of system stability and reliability. This notice is a courtesy: please
fix this problem. It will become a fatal error in an upcoming update.
2014-12-15 12:12:36.122 DataMatrixReader[18838:412778] * Terminating
app due to uncaught exception 'NSInvalidArgumentException', reason:
'Both dimensions must be greater than 0'
* First throw call stack: ( 0 CoreFoundation 0x0000000102626f35 exceptionPreprocess + 165 1 libobjc.A.dylib
0x00000001022bfbb7 objc_exception_throw + 45 2 DataMatrixReader
0x0000000100f09507 -[ZXBitMatrix initWithWidth:height:] + 231 3
DataMatrixReader 0x0000000100f51b7d
-[ZXGlobalHistogramBinarizer blackMatrixWithError:] + 141 4 DataMatrixReader 0x0000000100f530b0
-[ZXHybridBinarizer blackMatrixWithError:] + 816 5 DataMatrixReader 0x0000000100f068ab -[ZXBinaryBitmap blackMatrixWithError:] + 139 6
DataMatrixReader 0x0000000100fa43b2
-[ZXQRCodeReader decode:hints:error:] + 130 7 DataMatrixReader 0x0000000100f63d04 -[ZXMultiFormatReader decodeInternal:error:] + 548
8 DataMatrixReader 0x0000000100f62ade
-[ZXMultiFormatReader decode:hints:error:] + 142 9 DataMatrixReader 0x0000000100ef1df2 -[ViewController scanBarcode:] + 322 10 UIKit
0x0000000102a148be -[UIApplication sendAction:to:from:forEvent:] + 75
11 UIKit 0x0000000102b1b410
-[UIControl _sendActionsForEvents:withEvent:] + 467 12 UIKit 0x0000000102b1a7df -[UIControl touchesEnded:withEvent:] + 522 13
UIKit 0x0000000102a5a308 -[UIWindow
_sendTouchesForEvent:] + 735 14 UIKit 0x0000000102a5ac33 -[UIWindow sendEvent:] + 683 15 UIKit
0x0000000102a279b1 -[UIApplication sendEvent:] + 246 16 UIKit
0x0000000102a34a7d _UIApplicationHandleEventFromQueueEvent + 17370 17
UIKit 0x0000000102a10103
_UIApplicationHandleEventQueue + 1961 18 CoreFoundation 0x000000010255c551
__CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE0_PERFORM_FUNCTION + 17 19 CoreFoundation 0x000000010255241d
__CFRunLoopDoSources0 + 269 20 CoreFoundation 0x0000000102551a54 __CFRunLoopRun + 868 21 CoreFoundation
0x0000000102551486 CFRunLoopRunSpecific + 470 22 GraphicsServices
0x0000000104bc09f0 GSEventRunModal + 161 23 UIKit
0x0000000102a13420 UIApplicationMain + 1282 24 DataMatrixReader
0x0000000100ef2343 main + 115 25 libdyld.dylib
0x00000001058a3145 start + 1 ) libc++abi.dylib: terminating with
uncaught exception of type NSException (lldb)
Now the question is somebody tried to integrate the ZxingObjC in iOS 8.1?

I think your project is using ARC but ZXING library isn't. In that case go to path 'Target -> Build Phases -> Compile Sources' in ZXING library. Double click on each .m file and enter '-fno-objc-arc' in popped dialog box. In this way those files will be excluded from ARC

If you project is using ARC (Automatic Reference Counting) then you don't need to make autorelease calls as it is done for you.
Change
ZXLuminanceSource *source = [[[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode] autorelease];
to
ZXLuminanceSource *source = [[ZXCGImageLuminanceSource alloc] initWithCGImage:imageToDecode];
Further information about ARC can be found on the iOS Developer Library

This works perfectly for me:
Getting Started in the readme.md didn’t work so I had to do the following steps to make it work.
copy the whole folders into your working project’s sub-folder.
and drag/add ZXingObjC.xcodeproj file to “<your working project>”.
make sure tick create folder references for any added folders option when prompted.
then, go to your project’s Target > Build Phases
under Target Dependencies, add ZXingObjC-iOS (ZXingObjC)
under Link Binary With Libraries, add libZXingObjC-iOS.a
under the same category, add the following 6 frameworks
AVFoundation.framework
CoreGraphics.framework
CoreMedia.framework
CoreVideo.framework
ImageIO.framework
QuartzCore.framework
Source in: http://sagage.com/?p=55
My test in a direct device Iphone 4s were good, perhaps is not the best device to test that, Iphone 4s has not a "AutoFocus" feature, very important for work with this barcodes.
hope this saves your day.

Related

Crashlytics Crash with NSOperationQueue (QOS: UNSPECIFIED)

I'm getting a crash, reported in Crashlytics, and I have no idea how to reproduce the error, It happens randomly so it's hard to debug it with Xcode. Any ideas?
Crashed: NSOperationQueue 0x280419200 (QOS: UNSPECIFIED)
0 libobjc.A.dylib 0x22c471430 objc_retain + 16
1 CoreFoundation 0x22d2b5888 __CFBasicHashAddValue + 1480
2 CoreFoundation 0x22d1e64ac CFDictionarySetValue + 260
3 Foundation 0x22dd04888 _encodeObject + 732
4 myAPI 0x1062b44b0 -[DataCore encodeWithCoder:] (DataCore.m:236)
5 myAPI 0x1062909c4 -[DataHandle encodeWithCoder:] (DataHandle.m:53)
6 Foundation 0x22dd04aa8 _encodeObject + 1276
7 Foundation 0x22dc69c6c +[NSKeyedArchiver archivedDataWithRootObject:] + 168
8 myAPI 0x106288a34 __77+[CachableObject addObjectToCache:withCacheName:withTTL:withCompletionBlock:]_block_invoke (CachableObject.m:162)
9 Foundation 0x22dd198bc NSBLOCKOPERATION_IS_CALLING_OUT_TO_A_BLOCK + 16
10 Foundation 0x22dc21ab8 -[NSBlockOperation main] + 72
11 Foundation 0x22dc20f8c -[__NSOperationInternal _start:] + 740
12 Foundation 0x22dd1b790 __NSOQSchedule_f + 272
13 libdispatch.dylib 0x22ccc16c8 _dispatch_call_block_and_release + 24
14 libdispatch.dylib 0x22ccc2484 _dispatch_client_callout + 16
15 libdispatch.dylib 0x22cc6582c _dispatch_continuation_pop$VARIANT$mp + 412
16 libdispatch.dylib 0x22cc64ef4 _dispatch_async_redirect_invoke + 600
17 libdispatch.dylib 0x22cc71a18 _dispatch_root_queue_drain + 376
18 libdispatch.dylib 0x22cc722c0 _dispatch_worker_thread2 + 128
19 libsystem_pthread.dylib 0x22cea517c _pthread_wqthread + 472
20 libsystem_pthread.dylib 0x22cea7cec start_wqthread + 4
Here is what the code in DataCore.m looks like
- (void)encodeWithCoder:(NSCoder *)coder {
[super encodeWithCoder:coder];
[coder encodeObject:programFormatPlayInfo forKey:#"ProgramFormatPlayInfo"];
[coder encodeObject:bigScreenPlayInfo forKey:#"BigScreenPlayInfo"];
[coder encodeObject:pivotHandle forKey:#"PivotHandle"];
[coder encodeInteger:pivotDataLinkId forKey:#"PivotDataLinkId"];
[coder encodeInteger:viewContextId forKey:#"ViewContextId"];
[coder encodeBool:suppressImagePivot forKey:#"SuppressImagePivot"];
[coder encodeObject:attributeIds forKey:#"AttributeIds"];
[coder encodeObject:self.overflow forKey:#"Overflow"];
[coder encodeObject:self.cacheNameWithUser forKey:#"CacheNameWithUser"];
[coder encodeObject:self.metaData forKey:#"Metadata"];
}
and here is where I try to add an object to the cache,
not sure if it's failing to decode or something related to the background queue.
+ (void)addObjectToCache:(CachableObject*)object withCacheName:(NSString*)cacheName withTTL:(CacheTime)cacheTimeSeconds withCompletionBlock:(void(^)()) block {
CachableObject* theObject = object;
[_backgroundQueue addOperationWithBlock:^{
#autoreleasepool {
#try {
NSString * path = [CachableObject pathForCachedObject:cacheName];
NSDate * date = [NSDate date];
[object setCacheDate:date];
[object setTtlSeconds:[NSNumber numberWithInteger:cacheTimeSeconds]];
[object setApiVersion:APIVERSION];
// Add to NSCache
[[CachableObject objectCache] setObject:theObject forKey:cacheName];
// Add to file system
NSError* err = nil;
NSData * data = [NSKeyedArchiver archivedDataWithRootObject:theObject];
if (data) {
[data writeToFile:path options:NSDataWritingAtomic error:&err];
}
// Add to dynamic cache
unwrapObjectAndComplyWithClass(object, [DataHandle class], ^(id unwrappedObject) {
DataHandle *objectUnwrapped = unwrappedObject;
DataFrame *objectFrame = objectUnwrapped.frame;
for (NSString *eachDependencyName in objectFrame.dependencies) {
[[VVIDynamicCacheManager sharedManager]addDependencyToStore:eachDependencyName withCacheName:cacheName];
}
}, ^{
/*Not a data handle*/
});
} #catch (NSException* ex) {
NSLog(#"CachableObject: got an exception %#", ex);
} #finally {
if (block) {
block();
}
}
}
}];
}
Some thoughts here.
First, you're using #try/#catch. I believe that NSKeyedArchiver throws exceptions when it should actually return NSError objects. So, perhaps that's why you are doing it. But, you have to keep in mind that none of Apple's frameworks are guaranteed to be exception-safe. This means that catching exceptions can leave Apple's code (and, of course, your own) in inconsistent states that will prevent it from working correctly in the future.
I would strongly recommend either removing the #catch, or scoping it extremely tightly around the NSKeyedArchiver code, if that's why you are using it. This could be unintentionally introducing a variety of other bugs into your app.
Now, on to the specific crash. It's occurring in the runtime's memory management code. This points very strongly at heap corruption. This means you've got a pointer that doesn't point to a valid Objective-C object in memory. This can happen for many reasons, and is extremely common. The most common cause is known as a dangling pointer. However, it could also be caused by an over-release. And, I wouldn't be at all surprised if it is possible to use an #catch to trigger an over-release. (I know, I'm harping, but I've seen so many issues caused by this pattern)
What I generally recommend in these situations:
Look for other crashes that look heap-corruption-related
Try out Zombies in Instruments
Try malloc scribble, or guardmalloc, two other good memory debugging tools
It's hard, and often even impossible, to reason about heap corruption. Replicating the bug can also be impossible, as memory corruption is typically not deterministic.
So, just try to find and fix as many issues as you can. It's totally possible that one of them is responsible for a variety of crashes, one of which could be this one.

Watch app starts with error clientIdentifier for interfaceControllerID not found

I'm having a smartwatch app on watchos2. The app always worked but now when it starts I immediately get this error:
Lop_WatchKit_Extension[17535:7854201] *********** ERROR -[SPRemoteInterface _interfaceControllerClientIDForControllerID:] clientIdentifier for interfaceControllerID:447E0002 not found
I found some topics here on stackoverflow but nothing solved the problem.
In my case, this was due to a retain cycle in one InterfaceController of mine.
If you get the logs similar to:
[default] -[SPRemoteInterface
_interfaceControllerClientIDForControllerID:]:0000: ComF: clientIdentifier for interfaceControllerID:XXXXXXXX not found
&/or...
[default] _SendRecordedValues:000: ComF:<-Plugin controller ID
XXXXXXXX has no client identifier
First, figure out which InterfaceController has the controller ID XXXXXXXX.
Have this in awake(withContext:)
override func awake(withContext context: Any?) {
//...
if let id = self.value(forKey: "_viewControllerID") as? NSString {
let strClassDescription = String(describing: self)
print("\(strClassDescription) has the Interface Controller ID \(id)")
}
//...
}
This logs:
[Target.Classname: 0xYYYYYYYY] has the Interface Controller ID
XXXXXXXX
Once you identify the InterfaceController causing these logs, you can continue to debug.
It could be different in your case but in mine I had created a retain cycle with self in one of my closures within which took awhile to locate but I eventually broke the retain cycle with a [weak self] capture.
Basically, the error logs appear when an InterfaceController is trying to execute some code but it has already been released.
What I already had:
DispatchQueue.main.async {
self.doSomethingThatDoesSomethingAsync()
}
What I fixed:
DispatchQueue.main.async { [weak self] in
self?.doSomethingThatDoesSomethingAsync()
}
If you use didSet on any IBOutlets it will also throw this error in the logs.
class MyInterfaceController: WKInterfaceController {
#IBOutlet var myLabel: WKInterfaceLabel! {
didSet {
myLabel.setTitle("Test")
}
}
How #nickromano sad, it's happens when you use didSet with IBOutlets. Cause it's calls before awake(withContext context: Any?)
We can suppress this error if wrap it in DispatchQueue.main.async
#IBOutlet var statusLabel: WKInterfaceLabel! {
didSet {
DispatchQueue.main.async {
self.statusLabel.setHidden(true)
}
}
This has happened to me a few times and more times than not, it is because of a timer that is still firing in a just-previously dismissed WKInterfaceController that I did not catch.
Best thing to do aside from comparing ID's like in #staticVoidMan's answer is to read the call stack. In my case I was able to identify that the old timer was still firing based off these hints:
8 Foundation 0x00007fff214be867 __NSFireTimer + 67
9 CoreFoundation 0x00007fff207a8e3f __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
10 CoreFoundation 0x00007fff207a8912 __CFRunLoopDoTimer + 926
Here is the original call stack (for reference):
<MyApp.InterfaceController: 0x7fb3e4d2d020> has the Interface Controller ID 1EB00002
2021-05-26 14:44:06.632758-0600 MyApp WatchKit Extension[73392:3546879] [default] -[SPRemoteInterface _interfaceControllerClientIDForControllerID:]:2464: ComF: clientIdentifier for interfaceControllerID:1EB00007 not found. callStack:(
0 WatchKit 0x00007fff38d1a268 -[SPRemoteInterface _interfaceControllerClientIDForControllerID:] + 220
1 WatchKit 0x00007fff38d1bfff __54+[SPRemoteInterface setController:key:property:value:]_block_invoke + 340
2 WatchKit 0x00007fff38d12323 spUtils_dispatchAsyncToMainThread + 30
3 WatchKit 0x00007fff38d1be60 +[SPRemoteInterface setController:key:property:value:] + 179
4 WatchKit 0x00007fff38d057af -[WKInterfaceObject _sendValueChanged:forProperty:] + 706
5 WatchKit 0x00007fff38d2a5f8 -[WKInterfaceObject _setImage:forProperty:] + 50
6 MyApp WatchKit Extension 0x000000010955531d $s26MyApp_WatchKit_Extension25ActivityIndicatorDelegateC06handleE5TimeryyF + 813
7 MyApp WatchKit Extension 0x000000010955537a $s26MyApp_WatchKit_Extension25ActivityIndicatorDelegateC06handleE5TimeryyFTo + 42
8 Foundation 0x00007fff214be867 __NSFireTimer + 67
9 CoreFoundation 0x00007fff207a8e3f __CFRUNLOOP_IS_CALLING_OUT_TO_A_TIMER_CALLBACK_FUNCTION__ + 20
10 CoreFoundation 0x00007fff207a8912 __CFRunLoopDoTimer + 926
11 CoreFoundation 0x00007fff207a7ec5 __CFRunLoopDoTimers + 265
12 CoreFoundation 0x00007fff207a2546 __CFRunLoopRun + 1949
13 CoreFoundation 0x00007fff207a18be CFRunLoopRunSpecific + 567
14 GraphicsServices 0x00007fff25b49fd3 GSEventRunModal + 139
15 UIKitCore 0x00007fff43290f24 -[UIApplication _run] + 917
16 UIKitCore 0x00007fff43295c0b UIApplicationMain + 101
17 WatchKit 0x00007fff38d0de65 WKExtensionMain + 800
18 libdyld.dylib 0x00007fff20202db5 start + 1
19 ??? 0x0000000000000001 0x0 + 1
)
Have you changed the name of your module? If this is the case then you have to go through your storyboard and update it manually for all the Interfaces you have.
Edit with steps to fix:
Go to the storyboard and for each interface open the Identity inspector, then delete what's in Module and press enter, the new module should get auto-filled.

GMSPolygon array iOS crash

I Have an extremely strange issue with the GMSPolygon object.
Just out of nowhere my code crashes with the error "Unrecognized selector send to instance 0x...."
(Yes it worked all day, and suddenly it starts crashing)
I am using an array of Polygons (to keep track of them and update them dynamically) and I initialize them as follows in my -viewDidLoad:
GMSPolygon *myPoly[50];
--
GMSMutablePath *path = [[GMSMutablePath alloc] init];
// set some fake coordinates, initializing a Polygon with an empty path seems to crash as well...
[path addCoordinate:CLLocationCoordinate2DMake(1,0)];
[path addCoordinate:CLLocationCoordinate2DMake(-1,0)];
[path addCoordinate:CLLocationCoordinate2DMake(0,1)];
for (int i=0;i<50;i++) {
myPoly[i] = [GMSPolygon polygonWithPath:path];
myPoly[i].map = nil;
}
Later on in my program I try to acces the object again in the same way, first set it to nil so it will be removed from the map, and then update and if necessary display it again
for (int i=0;i<50;i++) {
myPoly[i] = [GMSPolygon polygonWithPath:path];
myPoly[i].map = nil; <--------- CRASH
// Do other stuf here, update the Polygon data and if needed
// display again as follows:
myPoly[i].map = mapView_;
}
But it seems to crash..
Same thing happens if I put the GMSPolygon in an NSMutable array. Initializing the array is fine, but getting the GMSPolygon out of the array and setting the .map property gives the same crash..
UPDATE:
It seems be caused by the object Memory locations.. If it works fine, memory locations are as follows:
[0] GMSPolygon * 0x1558ed750 0x00000001558ed750 <--- viewDidLoad for-loop
[0] GMSPolygon * 0x1558ed750 0x00000001558ed750 <--- other function for-loop
When it crashes
[0] GMSPolygon * 0x12e7cbf30 0x000000012e7cbf30 <--- viewDidLoad for-loop
[0] GMSPolygon * 0x129d36630 0x0000000129d36630 <--- other function for-loop
The object is only initialized once in the viewDidLoad, nowhere else!
It obviously explains the crash if the objects memory location are different.. but what's happening here?
Any one an idea why?
UPDATE 2, Got Crash log now:
2016-04-14 15:16:49.618 myApp[1130:240689] -[GMSMutablePath setMap:]: unrecognized selector sent to instance 0x1540bb560
2016-04-14 15:16:49.627 myApp[1130:240689] void uncaughtExceptionHandler(NSException *__strong) [Line 354] CRASH: -[GMSMutablePath setMap:]: unrecognized selector sent to instance 0x1540bb560
2016-04-14 15:16:49.688 myApp[1130:240689] void uncaughtExceptionHandler(NSException *__strong) [Line 355] Stack Trace: (
0 CoreFoundation 0x0000000182ebee50 <redacted> + 148
1 libobjc.A.dylib 0x0000000182523f80 objc_exception_throw + 56
2 CoreFoundation 0x0000000182ec5ccc <redacted> + 0
3 CoreFoundation 0x0000000182ec2c74 <redacted> + 872
4 CoreFoundation 0x0000000182dc0d1c _CF_forwarding_prep_0 + 92
5 myApp 0x00000001001115a0 -[mapViewController plotPoly] + 2028
6 myApp 0x000000010012c944 -[mapViewController mapView:didChangeCameraPosition:] + 556
7 CoreFoundation 0x0000000182ec4ae0 <redacted> + 144
8 CoreFoundation 0x0000000182dbc548 <redacted> + 284
9 CoreFoundation 0x0000000182dc0e70 <redacted> + 60
10 myApp 0x0000000100203370 -[GMSDelegateForward forwardInvocation:] + 108
11 CoreFoundation 0x0000000182ec2aa4 <redacted> + 408
12 CoreFoundation 0x0000000182dc0d1c _CF_forwarding_prep_0 + 92
13 myApp 0x0000000100188fec -[GMSMapView updateWithCamera:] + 176
14 Foundation 0x0000000183893ffc <redacted> + 340
15 CoreFoundation 0x0000000182e75124 <redacted> + 24
16 CoreFoundation 0x0000000182e74bb8 <redacted> + 540
17 CoreFoundation 0x0000000182e728b8 <redacted> + 724
18 CoreFoundation 0x0000000182d9cd10 CFRunLoopRunSpecific + 384
19 GraphicsServices 0x0000000184684088 GSEventRunModal + 180
20 UIKit 0x0000000188069f70 UIApplicationMain + 204
21 myApp 0x000000010013dd3c main + 124
22 libdyld.dylib 0x000000018293a8b8 <redacted> + 4)
2016-04-14 15:16:49.700 myApp[1130:240689] *** Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: '-[GMSMutablePath setMap:]: unrecognized selector sent to instance 0x1540bb560'
*** First throw call stack:
(0x182ebee38 0x182523f80 0x182ec5ccc 0x182ec2c74 0x182dc0d1c 0x1001115a0
0x10012c944 0x182ec4ae0 0x182dbc548 0x182dc0e70 0x100203370 0x182ec2aa4
0x182dc0d1c 0x100188fec 0x183893ffc 0x182e75124 0x182e74bb8 0x182e728b8
0x182d9cd10 0x184684088 0x188069f70 0x10013dd3c 0x18293a8b8)
libc++abi.dylib: terminating with uncaught exception of type NSException
I am stunned now.
The initial initialization works fine, the Polygons are drawn as the should, but as soon as I call the function to redraw the polygons, the crash happens.. and strange enough now I see why it crashes, but I don't understand.. It changes the first 5 array entry's to GMSMutablePath and GMSPolyLine , instead of GMSPolygon ?!, see link to picture below.. And have no idea why, because I am 100% sure the array of GMSPolygon is not touched anywhere else in the mean time..
Picture of of change in Array type
I can't post a comment yet due to my reputation. Just like what Dan said, use NSArray or NSMutableArray to store your objects. Then do your stuff.
UPDATE:
Here are my suggestions:
Add All Exceptions to your breakpoint navigator.
Try testing your code without loop.
Try adding float values as your coordinates.
See example code below:
GMSMutablePath *prettyPoly = [GMSMutablePath path];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.506191, 1.83197)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.05249, 1.650696)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(51.92225, 1.321106)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(51.996719, 1.219482)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.049112, 1.244202)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.197507, 1.334839)];
[prettyPoly addCoordinate:CLLocationCoordinate2DMake(52.519564, 1.801758)];
GMSPolygon *polygon = [GMSPolygon polygonWithPath: prettyPoly];
polygon.fillColor = [UIColor colorWithRed:0 green:0.25 blue:0 alpha:0.3];
polygon.strokeColor = [UIColor greenColor];
polygon.strokeWidth = 5;
polygon.map = self.googleMap;
If everything failed:
- Refer to this doc: https://developers.google.com/maps/documentation/ios-sdk/reference/interface_g_m_s_polygon#properties
How about you try Polyline class and see this example: https://developers.google.com/maps/documentation/ios-sdk/shapes#add_a_polyline
Last, try seeking help from Google Forum, or from the repo of that library you are using.

How can a CCMenu have a SIGSEV crash error?

cocos2d-iphone 1.0.1. I am receiving several SIGSEV crash reports on two parts:
CCMenu.m:
-(void) ccTouchEnded:(UITouch *)touch withEvent:(UIEvent *)event {
NSAssert(state_ == kCCMenuStateTrackingTouch, #"[Menu ccTouchEnded] -- invalid state");
[selectedItem_ unselected];
[selectedItem_ activate]; // <--- Here
state_ = kCCMenuStateWaiting;
}
CCMenuItem.m:
-(void) activate {
if(isEnabled_)
[invocation_ invoke]; // <--- Here
}
I have several backtraces, but they don't provide useful insight on my code - they all refer to cocos2d, CoreFoundation or UIKit libraries. A sample one:
0 MyGame 0x002609f0 testflight_backtrace
1 MyGame 0x002602d8 TFSignalHandler
2 libsystem_platform.dylib 0x3bdfa062 _sigtramp
3 CoreFoundation 0x312e4da2 -[NSInvocation invoke]
4 MyGame 0x000ee9f2 -[CCMenuItem activate] in CCMenuItem.m on Line 128
5 MyGame 0x000ed9be -[CCMenu ccTouchEnded:withEvent:] in CCMenu.m on Line 201
6 MyGame 0x0010e26a -[CCTouchDispatcher touches:withEvent:withTouchType:] in CCTouchDispatcher.m on Line 268
7 MyGame 0x0010e67e -[CCTouchDispatcher touchesEnded:withEvent:] in CCTouchDispatcher.m on Line 337
8 MyGame 0x0010f5d8 -[EAGLView touchesEnded:withEvent:] in EAGLView.m on Line 330
9 UIKit 0x33b3ddd8 -[UIWindow _sendTouchesForEvent:]
10 UIKit 0x33b38e64 -[UIWindow sendEvent:]
...
I'm still trying to replicate this myself. What I DO know is that selectedItem_ is probably a zombie object because I did manage to replicate it very long ago. This didn't help me much though.
My game has several CCMenu instances everywhere, and I'm under the impression that many of those menus are culprits, not just one. I must be doing something funny with them, but I can't figure out what.
Instead, I would like to know, what kind of code could possibly cause a SIGSEV error on a CCMenu?

Xcode 4 and "SIGABRT" error? (only for iphone though)

I'm new to ios development and to stackoverflow. I did try searching both stackoverflow and google before posting.
I built a simple little app, originally just left it an iphone only app, but decided to make it universal in the end. I, stupidly, was messing around when i was getting to know xcode 4 and switched it to universal and then back again so i had to recopy the project and do it again. This time i started it with a universal app. (Not when i created it but after i went to project and selected it there) It created the ipad folder and mainwindow-ipad.xib file but was empty of course since i didn't do anything yet. I had it set up as a tabbed based app so my iphone version had firstview and secondview nib files also, but the ipad version didn't. I set it all up in iphone version first and it worked fine. I then went and laid down the ipad version (i did eliminate the second tab from mainwindow-ipad because i didn't need it)
i then went and created a new nib file and placed it in the ipad folder along with "main-ipad.h" and "main-ipad.m". I copied my code and connected everything and it runs fine on ipad simulator but now when i try and run iphone simulator i get "SIGABRT error. I took a screen shot of it. I don't fully understand objective-c so i was hoping someone can help me? I can post any code or whatever you might need to help me with this error so just ask.
Appreciate any help and suggestions you may have!
Thanks!
[Okay i would have posted image but I can't since I'm a new user, instead i posted the line highlighted and the output from xcode]
Code for file with error:
int main(int argc, char *argv[])
{
NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, nil); //ERROR IS ON THIS LINE <-----
[pool release];
return retVal;
}
[OUTPUT]
2011-06-18 17:32:43.980 Price Assist[445:207] *** Terminating app due to uncaught exception 'NSUnknownKeyException', reason: '[<UIViewController 0x4e09cc0> setValue:forUndefinedKey:]: this class is not key value coding-compliant for the key finallabel.'
*** Call stack at first throw:
(
0 CoreFoundation 0x00dc35a9 __exceptionPreprocess + 185
1 libobjc.A.dylib 0x00f17313 objc_exception_throw + 44
2 CoreFoundation 0x00dc34e1 -[NSException raise] + 17
3 Foundation 0x00795677 _NSSetUsingKeyValueSetter + 135
4 Foundation 0x007955e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
5 UIKit 0x0021130c -[UIRuntimeOutletConnection connect] + 112
6 CoreFoundation 0x00d398cf -[NSArray makeObjectsPerformSelector:] + 239
7 UIKit 0x0020fd23 -[UINib instantiateWithOwner:options:] + 1041
8 UIKit 0x00211ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
9 UIKit 0x000c7628 -[UIViewController _loadViewFromNibNamed:bundle:] + 70
10 UIKit 0x000c5134 -[UIViewController loadView] + 120
11 UIKit 0x000c500e -[UIViewController view] + 56
12 UIKit 0x00038d42 -[UIWindow addRootViewControllerViewIfPossible] + 51
13 Foundation 0x007955e5 -[NSObject(NSKeyValueCoding) setValue:forKey:] + 285
14 UIKit 0x00048ff6 -[UIView(CALayerDelegate) setValue:forKey:] + 173
15 UIKit 0x0021130c -[UIRuntimeOutletConnection connect] + 112
16 CoreFoundation 0x00d398cf -[NSArray makeObjectsPerformSelector:] + 239
17 UIKit 0x0020fd23 -[UINib instantiateWithOwner:options:] + 1041
18 UIKit 0x00211ab7 -[NSBundle(UINSBundleAdditions) loadNibNamed:owner:options:] + 168
19 UIKit 0x0001717a -[UIApplication _loadMainNibFile] + 172
20 UIKit 0x00017cf4 -[UIApplication _runWithURL:payload:launchOrientation:statusBarStyle:statusBarHidden:] + 291
21 UIKit 0x00022617 -[UIApplication handleEvent:withNewEvent:] + 1533
22 UIKit 0x0001aabf -[UIApplication sendEvent:] + 71
23 UIKit 0x0001ff2e _UIApplicationHandleEvent + 7576
24 GraphicsServices 0x00ffc992 PurpleEventCallback + 1550
25 CoreFoundation 0x00da4944 __CFRUNLOOP_IS_CALLING_OUT_TO_A_SOURCE1_PERFORM_FUNCTION__ + 52
26 CoreFoundation 0x00d04cf7 __CFRunLoopDoSource1 + 215
27 CoreFoundation 0x00d01f83 __CFRunLoopRun + 979
28 CoreFoundation 0x00d01840 CFRunLoopRunSpecific + 208
29 CoreFoundation 0x00d01761 CFRunLoopRunInMode + 97
30 UIKit 0x000177d2 -[UIApplication _run] + 623
31 UIKit 0x00023c93 UIApplicationMain + 1160
32 Price Assist 0x000029a9 main + 121
33 Price Assist 0x00002925 start + 53
)
terminate called after throwing an instance of 'NSException'
iPhone FirstView nib file .h code:
#interface FirstViewController : UIViewController {
IBOutlet UITextField *dollarinput;
IBOutlet UITextField *centsinput;
IBOutlet UIButton *combinevalue;
IBOutlet UITextField *percentoffinput;
IBOutlet UILabel *discountlabel;
IBOutlet UILabel *finallabel;
}
- (IBAction)calculate:(id)sender;
- (IBAction)backgroundTouched:(id)sender;
- (IBAction)autonext:(id)sender;
iPhone FirstView nib file .m code:
//
// FirstViewController.m
// Price Assist
//
// Created by Dustin Schreiber on 6/15/11.
// Copyright 2011 TheTechSphere.com. All rights reserved.
//
#import "FirstViewController.h"
#implementation FirstViewController
/*
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
[super viewDidLoad];
}
*/
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
return (interfaceOrientation == UIInterfaceOrientationPortrait);
}
- (void)didReceiveMemoryWarning
{
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc. that aren't in use.
}
- (void)viewDidUnload
{
[percentoffinput release];
percentoffinput = nil;
[discountlabel release];
discountlabel = nil;
[finallabel release];
finallabel = nil;
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)dealloc
{
[percentoffinput release];
[discountlabel release];
[finallabel release];
[super dealloc];
}
- (IBAction)calculate:(id)sender {
if ([centsinput.text length] == 0){
centsinput.text = #"00";
}
if ([dollarinput.text length] == 0){
dollarinput.text = #"00";
}
if ([percentoffinput.text length] == 0){
percentoffinput.text = #"00";
}
double cDollars = [dollarinput.text doubleValue];
double cCents = [centsinput.text doubleValue];
double percentoff = [percentoffinput.text doubleValue] / 100;
NSString *ccDollars = [[NSNumber numberWithFloat:cDollars] stringValue];
NSString *ccCents = [[NSNumber numberWithFloat:cCents] stringValue];
NSString *placeholder = [NSString stringWithFormat:#"%#.%#", ccDollars, ccCents];
double combined = [placeholder doubleValue];
double discount = combined * percentoff;
NSString *discountholder2 =[NSString stringWithFormat:#"%.2f", discount];
discountlabel.text = discountholder2;
double newprice = (combined - discount);
NSString *str = [NSString stringWithFormat:#"%.2f", newprice];
finallabel.text = str;
dollarinput.text = ccDollars;
centsinput.text = ccCents;
percentoffinput.text = [[NSNumber numberWithFloat:percentoff] stringValue];
}
-(IBAction)backgroundTouched:(id)sender
{
[dollarinput resignFirstResponder];
[centsinput resignFirstResponder];
[percentoffinput resignFirstResponder];
}
- (IBAction)autonext:(id)sender {
if ([centsinput.text length ] >= 2) {
if ([centsinput.text length] > 2) {
centsinput.text = #"";
} else {
//next field
}
}
}
#end
Thanks again! If anyone has any suggestions for my code i'd love to here them! Like I said, I'm new to it and thats the only way i know to do this.
------------> If anyone wants, I'll upload the entire project folder. Just ask. Thank you guys for all the help. i'm a n00b with xcode so i haven't got it all down yet.
Project Zipped
Post some code where you use finallabel and try to debug your app so you can tell me the line just before the app crashes.
Option 2:
Try to set a BreakPoint in malloc_error_break so we can have more info about the error.
In XCode go to Run -> Show -> BreakPoints (or just cmd + option + B). Then double click to add a new symbol (symbolic breakpoint) and type in malloc_error_break then press enter.
Now run your app and paste your console text.
UPDATE If you need help http://developer.apple.com/library/mac/#recipes/xcode_help-breakpoint_navigator/articles/adding_a_symbolic_breakpoint.html
Check your connections inside your InterfaceBuilder, you may have it wrong with fianllabel.
Also check your Custom Class -> Class in your iphone XIB in your InterfaseBuilder
UPDATE
Go to Product -> Clean. Then Run.
The line UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class])); just means that an exception was thrown during the running of your program. This could range from a memory problem, to a simple runtime error. Look in the target debugger console; it will tell you where the error occurred.
Open "iOS Simulator" Menu in the upper left->Reset Content and Settings. Then quit the iOS simulator and Xcode, and then restart your computer. This will get rid of the other instance of the process.
This May work it's work for me...........
The problem is with your XIB file. This error generally occurs when your finalLabel is incorrectly hooked up or doesn't exist anymore. Check your connections in the Interface Builder once.
I also had this error. After spending so much time, I found how to fix it. First of all go the console and see where is the error (mine was related to storyboards and its code) The way I fixed my error was by going in story board. Below the iPhone screen, there will be small yellow button. Right click on it and you will see that is causing error. Delete(x) it if there is yellow error sign.
If this does not fix your error then try to make new project and then replace its blank files with old files of your old project. I had same error in very beginning and by doing this program run without any error.
Other people suggests by restarting your laptop and running it again, reseting the iOS simulator, or changing iOS debugger (however this does not work in latest x code since there is only one debugger)
Hope this helps

Resources