2016-03-16 2 views
0

En essayant d'extraire des informations à partir d'une base de données SQLlite avec des données de base et juste après avoir quitté l'IBAction qui obtiennent le NSManageObject de DB, l'application se bloque avec une erreur EXEC_BAD_ACCESS.Obtention EXEC_BAD_ACCES après avoir quitté IBAction

Le code exécuté est:

- (IBAction)abrir:(id)sender{ 
[openBrowser setTag:[sender tag]]; 
[self showOpenPanel:mWindow]; 
if (acceptCancelButton) { 
    NSString *auxN; 
    NSPredicate *auxP; 
    NSFetchRequest *auxFR; 
    NSError *err; 
    NSArray *array; 
    switch ([sender tag]) { 
     case 1: 
      auxN = [[[openBrowser selectedCell] stringValue] copy]; 
      auxP =[NSPredicate predicateWithFormat:@"studyName == %@", auxN]; 
      auxFR = [[NSFetchRequest alloc] init]; 
      [auxFR setPredicate:auxP]; 
      [auxFR setEntity:[NSEntityDescription entityForName:@"Study" inManagedObjectContext:managedObjectContext]]; 
      [auxFR setIncludesSubentities:NO]; 
      [auxFR setFetchLimit:1]; 
      array = [managedObjectContext executeFetchRequest:auxFR error:&err]; 
      if(array){ 
       /* 
       Instanciamos un nuevo nsmanagedobject y lo cargamos con la información 
       leida de la BD 
       */ 
       actualStudy = [NSEntityDescription insertNewObjectForEntityForName:@"Study" inManagedObjectContext:managedObjectContext]; 
       [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"studyName"] forKey:@"studyName"]; 
       [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"studyPath"] forKey:@"studyPath"]; 
       [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"studyDescription"] forKey:@"studyDescription"]; 
       [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"compressRate"] forKey:@"compressRate"]; 
       [actualStudy setValue:[[array objectAtIndex:0] valueForKey:@"testDuration"] forKey:@"testDuration"]; 
       NSLog(@"%@ %@ %@ %d %d", 
         [actualStudy valueForKey:@"studyName"], 
         [actualStudy valueForKey:@"studyPath"], 
         [actualStudy valueForKey:@"studyDescription"], 
         [[actualStudy valueForKey:@"compressRate"] floatValue], 
         [[actualStudy valueForKey:@"testDuration"] intValue]); 
      }else{ 
       [Auxiliar showError:-15]; 
      } 
      break; 
     ... 
    } 
} 

}

  • actualStudy est une variable d'@interface Étude: NSManagedObject {

Le code execute normaly mais quand le retour de l'application de l'appel donne ce message:

The Debugger has exited with status 0. 
[Session started at 2016-03-16 15:23:07 +0000.] 
GNU gdb 6.3.50-20050815 (Apple version gdb-1515) (Sat Jan 15 08:33:48 UTC 2011) 
Copyright 2004 Free Software Foundation, Inc. 
GDB is free software, covered by the GNU General Public License, and you are 
welcome to change it and/or distribute copies of it under certain conditions. 
Type "show copying" to see the conditions. 
There is absolutely no warranty for GDB. Type "show warranty" for details. 
This GDB was configured as "x86_64-apple-darwin". 
tty /dev/ttys001 
Loading program into debugger… 
sharedlibrary apply-load-rules all 
warning: Unable to read symbols from "CoreData" (not yet mapped into memory). 
Program loaded. 
run 
[Switching to process 3574] 
Running… 
[Switching to process 3574] 
[Switching to process 3574] 
[Switching to process 3574] 
[Switching to process 3574] 
(gdb) continue 
Current language: auto; currently objective-c++ 
(gdb) continue 
2016-03-16 15:23:36.720 eTracker[3574:a0f] CoreData /Users/admin/usabilimac/build/Debug/CoreData/ Prueba core data 600 0 
Program received signal: “EXC_BAD_ACCESS”. 
(gdb) 

Que la pile exec:

#0 0x7fff88de6f10 in objc_msgSend 
#1 0x7fff836101d6 in _CFAutoreleasePoolPop 
#2 0x7fff86d3e110 in -[NSAutoreleasePool drain] 
#3 0x7fff81e27723 in -[NSApplication run] 
#4 0x7fff81e203b0 in NSApplicationMain 
#5 0x1000027f1 in main at main.mm:13 
+0

Je viens de trouver que le problème Son que managedobjectcontext appelle une version sur le tableau et quand quitter IBAction une autre version est envoyé à l'objet tableau. Comment puis-je éviter ça ? –

Répondre

0

Le problème était dans une autre partie du code, mais comme je l'ai dit était la multireleasing du même tableau. Après avoir éliminé tous les appels à libération explicite, EXEC_BAD_ACCESS a disparu.

Merci à tous ceux qui essaient de répondre à ma question.