Rightpoint / RZVinyl

Stack management, ActiveRecord utilities, and seamless importing for Core Data
Other
21 stars 6 forks source link

App Crashes in iOS11 while saving data. #92

Open JyothsnaRella opened 6 years ago

JyothsnaRella commented 6 years ago

Hello, We have used RZVinyl for using coredata in our app. It is crashing when I try to save the data. Updated my code with the latest version of framework. Its giving an exception. Please let us know if the framework supports iOS11.

Foundation 0x00000001834df538 NSKeyValueDidChange + 436 6 Foundation 0x0000000183597ae4 NSKeyValueDidChangeWithPerThreadPendingNotifications + 140 7 CoreData 0x00000001854107c8 -[NSManagedObject didChangeValueForKey:] + 120 8 CoreData 0x0000000185416358 -[NSManagedObject+ 844632 (_NSInternalMethods) _updateFromRefreshSnapshot:includingTransients:] + 692 9 CoreData 0x000000018542e054 -[NSManagedObjectContext+ 942164 (_NestedContextSupport) _copyChildObject:toParentObject:fromChildContext:] + 652 10 CoreData 0x000000018542e4bc -[NSManagedObjectContext+ 943292 (_NestedContextSupport) _parentProcessSaveRequest:inContext:error:] + 804 11 CoreData 0x000000018542f3f0 __82-[NSManagedObjectContext+ 947184 (_NestedContextSupport) executeRequest:withContext:error:]_block_invoke + 580 12 CoreData 0x0000000185431644 internalBlockToNSManagedObjectContextPerform + 92 13 libdispatch.dylib 0x0000000182569048 _dispatch_client_callout + 16 14 libdispatch.dylib 0x0000000182571ae8 _dispatch_queue_barrier_sync_invoke_and_complete + 56 15 CoreData 0x000000018541dd10 _perform + 232 16 CoreData 0x000000018542f0e4 -[NSManagedObjectContext+ 946404 (_NestedContextSupport) executeRequest:withContext:error:] + 172 17 CoreData 0x0000000185387ff8 -[NSManagedObjectContext save:] + 2580

ZevEisenberg commented 6 years ago

@JyothsnaRella what is the exception or crash you are getting? Not just the stack trace - the actual text of the error. RZVinyl has not received extensive testing on iOS 11, and I don't think it's been tested much or at all with the new simpler Core Data stack setup in iOS 10, but I've seen it work on at least one app on iOS 11, at least in very limited testing.

JyothsnaRella commented 6 years ago

I get the below assertion Assertion failed: (moreParameters->mostRecentEntry == CFArrayGetValueAtIndex(stack, stackCount - 1)), function NSKeyValuePopPendingNotificationPerThread, file /BuildRoot/Library/Caches/com.apple.xbs/Sources/Foundation_Sim/Foundation-1444.12/EO.subproj/NSKeyValueObserving.m, line 933.

JyothsnaRella commented 6 years ago

Crashing in both the functions

with the above stated assertion. BOOL isSaved = [currentContext save:&saveErr];

JyothsnaRella commented 6 years ago

Hello @ZevEisenberg, any clue on what the assertion is about? Need your suggestions...

ZevEisenberg commented 6 years ago

@JyothsnaRella sorry, I don't have a workaround. The assertion is in Apple's code, so it looks like Core Data is being asked to do something it doesn't want to do. If you can produce a sample project that reproduces the issue in minimal code, it may make it easier for someone to debug and fix it.

JyothsnaRella commented 6 years ago

Hi  @ZevEisenberg, I am in the process of building a sample code. Will share with you in couple of days. I have few doubts in Coredata. It would be helpful if you can clarify them. Can the ManagedObjectContext save the nil values? I have modified the rzv_saveToStoreWithCompletion function as below.

-(void)rzv_saveToStoreWithCompletion:(void (^)(NSError *))completion
{
    if ( !RZVAssert(self.concurrencyType != NSConfinementConcurrencyType, @"RZVinylSave 
    methods cannot be used on contexts with thread confinement.") ) {
        return;
    }

    [self performBlock:^{
        if ( ![self hasChanges] ) {
            RZVLogInfo(@"Managed object context %@ does not have changes, not saving", self);
            rzv_performSaveCompletionAsync(completion, nil);
            return;
        }

        NSArray *myObject = [[self registeredObjects] allObjects];
        for (NSManagedObject *obj in myObject) {

            NSArray *keys = [[[obj entity] attributesByName] allKeys];
            NSDictionary *dict = [obj dictionaryWithValuesForKeys:keys];
            NSManagedObjectContext *objContext = [obj managedObjectContext];

            NSLog(@"-----------before save-----------:%@",obj);
            NSError *saveErr = nil;
            if ( ![objContext save:&saveErr] ) {
                RZVLogError(@"Error saving managed object context context %@: %@", self, saveErr);
                rzv_performSaveCompletionAsync(completion, saveErr);

            }
            else if ( objContext.parentContext != nil ) {
                [objContext.parentContext rzv_saveToStoreWithCompletion:completion];
            }
            else if ( completion ) {
                rzv_performSaveCompletionAsync(completion, nil);
            }
        }

        /*
        NSLog(@"-----------before save-----------:%@",myObject);
        NSLog(@"-----------before save end-----------");
        NSError *saveErr = nil;
        if ( ![self save:&saveErr] ) {
            RZVLogError(@"Error saving managed object context context %@: %@", self, saveErr);
            rzv_performSaveCompletionAsync(completion, saveErr);
        }
        else if ( self.parentContext != nil ) {
            [self.parentContext rzv_saveToStoreWithCompletion:completion];
        }
        else if ( completion ) {
            rzv_performSaveCompletionAsync(completion, nil);
        }
        */

    }];
}

I have many objects in the context. Looped through all the objects and logged them. I found few nil values in the context. Below is one of the context object which has nil value for settings. Attached a screen shot of the entity of ContentLanguage.

<ContentLanguage: 0x60000009f8b0> (entity: ContentLanguage; id: 0xd0000000000c0006 <x-coredata://B53C7782-1231-4DB9-8579-77BFC31ADDA9/ContentLanguage/p3> ; data: { displayName = "T\U00fcrk\U00e7e"; langId = tr; relationship = "<relationship fault: 0x60400023c9e0 'relationship'>"; settings = nil; user = "0xd000000000040002 <x-coredata://B53C7782-1231-4DB9-8579-77BFC31ADDA9/User/p1>"; })

screen shot 2017-10-09 at 7 03 07 pm

I would like to know if the app is crashing because of the nil value for settings key.
Can we have a Skype call or any other means so that I can share my screen to show you the crash.

ZevEisenberg commented 6 years ago

Core Data can save nil values as long as the relationship is set to "Optional" in the Attributes Inspector. If it's not "Optional," you may have a state management or timing bug. If you have nil values in non-optional properties when you try to save, you'll definitely run into problems.

Sorry, but I don't have time to do a screen share right now, and I'm not an RZVinyl expert.