We are simply trying to get a property of a RLMObject and compare it to another int:
// Crashes inside the IF statement when trying to access the message.saleId
// message is of type RLMObject
// saleId is of type int
if(message.saleId == 0)
{
}
No crash, just fetch the RLMObjects property
In development, this works for us and we havent been able to replicate the issue. In production, we have received crashes from over 400 devices all of which appear in random locations throughout the app, but always seem to be when trying to access a RLMObjects int property.
This is one of the stack traces we have received:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x18c5211b8 __exceptionPreprocess + 124 (NSException.m:165)
1 libobjc.A.dylib 0x18af5855c objc_exception_throw + 56 (objc-exception.mm:521)
2 PixelStarships 0x1005dcda4 long long get<long long>(RLMObjectBase*, unsigned long) + 164 (RLMObject_Private.hpp:45)
3 PixelStarships 0x1005dcde0 ___ZL17RLMAccessorGetterP11RLMProperty15RLMAccessorCode_block_invoke_3 + 24 (RLMAccessor.mm:313)
4 PixelStarships 0x100176900 -[ChatMessageLayer addMessage:] + 304 (ChatMessageLayer.m:304)
5 PixelStarships 0x100175420 -[ChatMessageLayer newMessage:] + 356 (ChatMessageLayer.m:122)
6 CoreFoundation 0x18c4bab10 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 20 (CFNotificationCenter.c:650)
7 CoreFoundation 0x18c4ba214 _CFXRegistrationPost + 400 (CFNotificationCenter.c:164)
8 CoreFoundation 0x18c4b9f90 ___CFXNotificationPost_block_invoke + 60 (CFNotificationCenter.c:1031)
9 CoreFoundation 0x18c529b8c -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1504 (CFXNotificationRegistrar.m:163)
10 CoreFoundation 0x18c3fbe64 _CFXNotificationPost + 376 (CFNotificationCenter.c:1028)
11 Foundation 0x18cf30e0c -[NSNotificationCenter postNotificationName:object:userInfo:] + 68 (NSNotification.m:482)
12 PixelStarships 0x1000d7a48 __29-[MessageManager newMessage:]_block_invoke + 228 (MessageManager.m:126)
13 libdispatch.dylib 0x18b3aa1fc _dispatch_call_block_and_release + 24 (init.c:947)
14 libdispatch.dylib 0x18b3aa1bc _dispatch_client_callout + 16 (object.m:455)
15 libdispatch.dylib 0x18b3aed68 _dispatch_main_queue_callback_4CF + 1000 (inline_internal.h:2424)
16 CoreFoundation 0x18c4ce810 __CFRUNLOOP_IS_SERVICING_THE_MAIN_DISPATCH_QUEUE__ + 12 (CFRunLoop.c:1793)
17 CoreFoundation 0x18c4cc3fc __CFRunLoopRun + 1660 (CFRunLoop.c:3004)
18 CoreFoundation 0x18c3fa2b8 CFRunLoopRunSpecific + 444 (CFRunLoop.c:3113)
19 GraphicsServices 0x18deae198 GSEventRunModal + 180 (GSEvent.c:2245)
20 UIKit 0x19243a7fc -[UIApplication _run] + 684 (UIApplication.m:2650)
21 UIKit 0x192435534 UIApplicationMain + 208 (UIApplication.m:4092)
22 PixelStarships 0x10023eadc main + 56 (main.m:14)
23 libdyld.dylib 0x18b3dd5b8 start + 4
At this time we are unable to reproduce this issue ourselves but when we do we'll update this thread
Realm version: v2.0.4
Xcode version: 8.2.1
iOS/OSX version: IOS 10+
Dependency manager + version: CocoaPods 1.1.1
Hi @twomedia. Sorry to hear you've ran into this problem. Would you be able to show us the entire model object itself as well as how message from message.saleId is created prior to using it? With that information, we'll be able to get to the bottom of this better.
This is how we are creating the object and populating it:
[[RLMRealm defaultRealm] transactionWithBlock:^{
// Create Object and mapFrom
PSMessage *theMessage = [[PSMessage alloc] init];
[theMessage mapFrom:attributeDict];
[realm addOrUpdateObject:theMessage];
// Set Last Object
lastMessage = theMessage;
}];
We then post a NSNotification which executes the following:
-(void)newMessage:(NSNotification *)aNotification
{
PSMessage *message = [[MessageManager shared] lastMessage];
if(displayType == MessageTypeSystem && message.activityType == ActivityType_RewardCollected)
{
return;
}
[self addMessage: message];
}
We then populate the UI, this is when we are experiencing the crash.
- (void) addMessage: (PSMessage*) message
{
if(message.activityType == ActivityType_MarketSold)
{
for(MessageEntity* thisMessageEntity in contentArray)
{
if(thisMessageEntity.messageModel.saleId == message.saleId)
{
[thisMessageEntity displaySoldMessageWithNewModel:message];
break;
}
}
return;
}
}
PSMessage.h & PSMessage.m
.h:
//
// PSMessage.h
// PixelStarships
#import <Foundation/Foundation.h>
#import "PixelSpaceShipsEnum.h"
#if TODAY_EXTENSION
@interface PSMessage : NSObject
#else
#import <Realm/Realm.h>
@interface PSMessage : RLMObject
#endif
@property NSString *activityArgument;
@property int activityType;
@property int allianceId;
@property NSString *allianceName;
@property int allianceSpriteId;
@property int channelId;
@property NSString *message;
@property NSTimeInterval messageDate;
@property int messageId;
@property int messageType;
@property int toUserId;
@property int userId;
@property NSString *userName;
@property int userSpriteId;
@property int trophy;
@property int shipDesignId;
@property int saleId;
- (void) mapFrom: (NSDictionary*) attributeDic;
@end
.m:
//
// PSMessage.m
// PixelStarships
#import "PSMessage.h"
@implementation PSMessage
+ (NSString *)primaryKey
{
return @"messageId";
}
- (void) mapFrom: (NSDictionary*) attributeDic
{
self.messageId = [[attributeDic valueForKey:@"MessageId"] intValue];
self.message = [attributeDic valueForKey:@"Message"];
self.userName = [attributeDic objectForKey:@"UserName"];
self.userSpriteId = [[attributeDic objectForKey:@"UserSpriteId"]intValue];
self.userId = [[attributeDic objectForKey:@"UserId"]intValue];
self.toUserId = [[attributeDic objectForKey:@"ToUserId"]intValue];
self.saleId = [[attributeDic objectForKey:@"SaleId"]intValue];
if ([[attributeDic objectForKey:@"MessageType"] isEqualToString:@"Public"])
{
self.messageType = MessageTypePublic;
}
else if ([[attributeDic objectForKey:@"MessageType"] isEqualToString:@"Private"])
{
self.messageType = MessageTypePrivate;
}
else if ([[attributeDic objectForKey:@"MessageType"] isEqualToString:@"Alliance"])
{
self.messageType = MessageTypeClan;
}
else if ([[attributeDic objectForKey:@"MessageType"] isEqualToString:@"System"])
{
self.messageType = MessageTypeSystem;
}
else if ([[attributeDic objectForKey:@"MessageType"] isEqualToString:@"Moments"])
{
self.messageType = MessageTypeMoments;
}
else if ([[attributeDic objectForKey:@"MessageType"] isEqualToString:@"Catalog"])
{
self.messageType = MessageTypeCatalog;
}
else if ([[attributeDic objectForKey:@"MessageType"] isEqualToString:@"Market"])
{
self.messageType = MessageTypeMarket;
}
if ([attributeDic objectForKey:@"MessageDate"])
{
NSDateFormatter *dateFormatter = [NSDateFormatter new];
dateFormatter.calendar = [[NSCalendar alloc] initWithCalendarIdentifier:NSGregorianCalendar];
[dateFormatter setTimeZone: [NSTimeZone timeZoneWithName:@"UTC"]];
[dateFormatter setDateFormat:@"yyyy-MM-dd'T'HH:mm:ss"];
dateFormatter.locale = [NSLocale localeWithLocaleIdentifier:@"en"];
self.messageDate = [[dateFormatter dateFromString: [attributeDic valueForKey:@"MessageDate"]] timeIntervalSinceReferenceDate];
}
if ([attributeDic objectForKey:@"AllianceName"]) {
self.allianceName = [attributeDic valueForKey:@"AllianceName"];
self.allianceSpriteId = [[attributeDic objectForKey:@"AllianceSpriteId"]intValue];
self.allianceId = [[attributeDic objectForKey:@"AllianceId"]intValue];
}
NSString* activityType = [attributeDic objectForKey:@"ActivityType"];
if([activityType isEqualToString:@"None"])
{
self.activityType = ActivityType_None;
}
else if([activityType isEqualToString:@"Replay"])
{
self.activityType = ActivityType_Replay;
}
else if ([activityType isEqualToString:@"Joined"])
{
self.activityType = ActivityType_Joined;
}
else if ([activityType isEqualToString:@"Application"])
{
self.activityType = ActivityType_Application;
}
else if ([activityType isEqualToString:@"MembershipChanged"])
{
self.activityType = ActivityType_ChangeMembership;
}
else if ([activityType isEqualToString:@"Invited"])
{
self.activityType = ActivityType_Invited;
}
else if ([activityType isEqualToString:@"Donated"])
{
self.activityType = ActivityType_Donated;
}
else if ([activityType isEqualToString:@"Reward"])
{
self.activityType = ActivityType_Reward;
}
else if ([activityType isEqualToString:@"RewardCollected"])
{
self.activityType = ActivityType_RewardCollected;
}
else if ([activityType isEqualToString:@"DeviceLogin"])
{
self.activityType = ActivityType_DeviceLogIn;
}
else if ([activityType isEqualToString:@"MarketSold"])
{
self.activityType = ActivityType_MarketSold;
}
self.activityArgument = [attributeDic objectForKey:@"ActivityArgument"];
self.trophy = [[attributeDic objectForKey:@"Trophy"] intValue];
}
@end
Hmm, that all looks fine to me. Short of some kind of really obscure edge case bug that's occurring, it would seem to imply that the objects being managed by contentArray might be getting invalidated somehow.
How exactly is that array being set up and stored?
I faced with similar crash on my new project. It happens when the app tries access to the property of realm object like this:
game!.name!
Definitely should add guard there, but probably it could be a reason. I hope it will help you.
@okulak Your problem seems force unwrapping nil value, it isn't same this issue. Can you please give more details?
@okulak Just to point out as well, this issue involves Realm Objective-C, which doesn't feature the optional unwrapping concepts that Swift incorporates. :)
It might be better if you create a new GitHub issue if you're still having problems. :)
@kishikawakatsumi, here my crash report:
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Last Exception Backtrace:
0 CoreFoundation 0x24dcb916 __exceptionPreprocess + 122 (NSException.m:162)
1 libobjc.A.dylib 0x24566e12 objc_exception_throw + 34 (objc-exception.mm:531)
2 Realm 0x56fefc long long get<long long>(RLMObjectBase*, unsigned int) (RLMObject_Private.hpp:45)
3 Realm 0x56ff1c ___ZL17RLMAccessorGetterP11RLMProperty15RLMAccessorCode_block_invoke_3 (RLMAccessor.mm:313)
4 My App 0x4dc60 BaseGameViewController.backButtonPressed() -> () (BaseGameViewController.swift:477)
5 My App 0x4f61c @objc BaseGameViewController.backButtonPressed() -> () (BaseGameViewController.swift:0)
6 CoreFoundation 0x24d7d730 __CFNOTIFICATIONCENTER_IS_CALLING_OUT_TO_AN_OBSERVER__ + 8 (CFNotificationCenter.c:674)
7 CoreFoundation 0x24d7d13a _CFXRegistrationPost + 386 (CFNotificationCenter.c:171)
8 CoreFoundation 0x24d7cf18 ___CFXNotificationPost_block_invoke + 36 (CFNotificationCenter.c:1017)
9 CoreFoundation 0x24dd3c66 -[_CFXNotificationRegistrar find:object:observer:enumerator:] + 1330 (CFXNotificationRegistrar.m:163)
10 CoreFoundation 0x24cdd07e _CFXNotificationPost + 482 (CFNotificationCenter.c:1014)
11 Foundation 0x2551e5da -[NSNotificationCenter postNotificationName:object:userInfo:] + 70 (NSNotification.m:497)
12 Foundation 0x2552310e -[NSNotificationCenter postNotificationName:object:] + 26 (NSNotification.m:490)
13 My App 0x5dc48 specialized BaseViewController.back(sender : UIBarButtonItem) -> () (BaseViewController.swift:105)
14 My App 0x5cdc4 @objc BaseViewController.back(sender : UIBarButtonItem) -> () (BaseViewController.swift:0)
15 UIKit 0x2937e750 -[UIApplication sendAction:to:from:forEvent:] + 76 (UIApplication.m:4265)
16 UIKit 0x294ffb8c -[UIBarButtonItem(UIInternal) _sendAction:withEvent:] + 136 (UIBarButtonItem.m:1595)
17 UIKit 0x2937e750 -[UIApplication sendAction:to:from:forEvent:] + 76 (UIApplication.m:4265)
18 UIKit 0x2937e6dc -[UIControl sendAction:to:forEvent:] + 60 (UIControl.m:612)
19 UIKit 0x293666ce -[UIControl _sendActionsForEvents:withEvent:] + 462 (UIControl.m:694)
20 UIKit 0x293667fa -[UIControl _sendActionsForEvents:withEvent:] + 762 (UIControl.m:702)
21 UIKit 0x2937e000 -[UIControl touchesEnded:withEvent:] + 600 (UIControl.m:446)
22 UIKit 0x2937dc7a -[UIWindow _sendTouchesForEvent:] + 642 (UIWindow.m:2135)
23 UIKit 0x2937668a -[UIWindow sendEvent:] + 638 (UIWindow.m:2257)
24 UIKit 0x29347120 -[UIApplication sendEvent:] + 200 (UIApplication.m:12645)
25 UIKit 0x293456ce _UIApplicationHandleEventQueue + 5006 (UIApplication.m:10454)
@TimOliver, we use RealmSwift. I can't reproduce the issue. It happens randomly.
Looking at the stack trace, it looks like the exception being thrown is due to the object having been deleted from the Realm: https://github.com/realm/realm-cocoa/blob/v2.0.4/Realm/RLMObject_Private.hpp#L45
@okulak Since you seem to be experiencing the same error, but from a different cause, I'd instead recommend you create a new issue from scratch so we can better examine it (and minimize the number of people getting notifications from this issue. :) )
Please copy over that stack trace, and provide as much sample code as you can. :)
Why was this closed? Was there any conclusion?
Unfortunately I can't reproduce it either, but I just got a crash report with a similar error (I think):
Exception Type: EXC_CRASH (SIGABRT)
Exception Codes: 0x0000000000000000, 0x0000000000000000
Exception Note: EXC_CORPSE_NOTIFY
Triggered by Thread: 0
Last Exception Backtrace:
0 CoreFoundation 0x1879e6fe0 __exceptionPreprocess + 124 (NSException.m:165)
1 libobjc.A.dylib 0x186448538 objc_exception_throw + 56 (objc-exception.mm:521)
2 Realm 0x10070bbbc long long (anonymous namespace)::get<long long>(RLMObjectBase*, unsigned long) + 164 (RLMObject_Private.hpp:45)
3 Leio 0x10014e950 _TFC4Leio4Bookg14addedToArchiveSb + 36 (Book+ComputedProperties.swift:79)
4 Leio 0x10014e908 _TToFC4Leio4Bookg14addedToArchiveSb + 28 (Book+ComputedProperties.swift:0)
5 Leio 0x10014e830 _TFC4Leio4Bookg8finishedSb + 36 (Book+ComputedProperties.swift:69)
6 Leio 0x10014e7e8 _TToFC4Leio4Bookg8finishedSb + 28 (Book+ComputedProperties.swift:0)
7 Leio 0x100072a90 _TTSf4d_n_n___TFC4Leio27BookInfoTableViewController9tableViewfTCSo11UITableView24heightForHeaderInSectionSi_V12CoreGraphics7CGFloat + 76 (BookInfoTableViewController.swift:592)
What's happening there is that the height for my table view headers depends on whether a book is finished, which depends on whether a book was added to the archive:
var addedToArchive: Bool {
return firstPage == 0 && lastPage == 0 && archived && readingSessions.isEmpty
}
That's where the crash happens.
firstPage, lastPage and archived are realm stored properties and readingSessions is a LinkingObjects.
open class Book: Object {
let readingSessions = LinkingObjects(fromType: ReadingSession.self, property: "book")
//...
dynamic var title: String = ""
dynamic var author: String = ""
dynamic var firstPage: Int = 0
dynamic var lastPage: Int = 0
dynamic var archived: Bool = false
dynamic var date: Date?
So there really isn't much happening there. I don't know what's causing it to crash.
Facing this crash randomly
Crash:
RLMObject_Private.hpp - Line 45
invocation function for block in objc_object* (anonymous namespace)::makeBoxedGetter
Line of code:
self.bookingDetailNotif = self.appDelegate.bookingInfoSatate.bookingNotification
bookingInfoState is realm object and bookingNotification is property
Any Help????
I am facing this issue
crash report :
Fatal Exception: RLMException
0 CoreFoundation 0x2386d298c __exceptionPreprocess
1 libobjc.A.dylib 0x2378ab9f8 objc_exception_throw
2 Realm 0x1013afd80 invocation function for block in objc_object* (anonymous namespace)::makeBoxedGetter
3
Can anyone help me?
I have stopped using realm!
@indraneel-coditas This issue was closed a long time ago. Please create a new issue using the provided template and all details filled in. Thanks!
@yasirIqbal11 Sorry to hear but thanks for the feedback! Another time please don't expect support when commenting on closed issues. They are not necessarily monitored. Better to create a new issue.
Most helpful comment
I have stopped using realm!