Domanda

Recentemente, sono stato ricevendo segnalazioni di errori intermittenti dal mio app affermando "selettore non riconosciuto" in aree che non potevano eventualmente causare loro, eppure fare.

Ad esempio, questa:

Error: NSInvalidArgumentException: *** -[NSCFString didReceiveMemoryWarning]: unrecognized selector sent to instance 0x541fe0
0  CoreFoundation                      0x32de1e23 __handleUncaughtException + 230
1  libobjc.A.dylib                    0x3266d894 _objc_terminate + 156
2  libstdc++.6.dylib                  0x338c3a8c _ZN10__cxxabiv111__terminateEPFvvE + 84
3  libstdc++.6.dylib                  0x338c3b04 _ZSt9terminatev + 24
4  libstdc++.6.dylib                  0x338c3c2c __cxa_throw + 108
5  libobjc.A.dylib                    0x3266be5c objc_exception_throw + 112
6  CoreFoundation                      0x32de2bfd -[NSObject doesNotRecognizeSelector:] + 112
7  CoreFoundation                      0x32d67b19 ___forwarding___ + 480
8  CoreFoundation                      0x32d5e840 _CF_forwarding_prep_0 + 48
9  Foundation                          0x33f765d9 _nsnote_callback + 184
10  CoreFoundation                      0x32d9e511 _CFXNotificationPostNotification + 304
11  Foundation                          0x33f741b3 -[NSNotificationCenter postNotificationName:object:userInfo:] + 70
12  Foundation                          0x33f76519 -[NSNotificationCenter postNotificationName:object:] + 20
13  UIKit                              0x30d18db8 -[UIApplication _performMemoryWarning] + 68
14  UIKit                              0x30d18d50 -[UIApplication _receivedMemoryNotification] + 136
15  UIKit                              0x30d18c80 _memoryStatusChanged + 64
16  CoreFoundation                      0x32d66eb7 __CFNotificationCenterDarwinCallBack + 26
17  CoreFoundation                      0x32d5cb51 __CFMachPortPerform + 78
18  CoreFoundation                      0x32da452b CFRunLoopRunSpecific + 2302
19  CoreFoundation                      0x32da3c1f CFRunLoopRunInMode + 50
20  GraphicsServices                    0x31bb9374 GSEventRunModal + 196
21  UIKit                              0x30bf3c30 -[UIApplication _run] + 560
22  UIKit                              0x30bf2230 UIApplicationMain + 968
23  Mind                                0x00002c68 main + 72
24  Mind                                0x00002be4 start + 52

Questo è il sistema operativo l'invio di un avviso di memoria per la mia app, e in qualche modo la classe di applicazione è cambiato in una stringa.

Sembra accadere molto di più quando il codice viene richiamato tramite un NSOperation:

Error: NSInvalidArgumentException: -[NSCFString setObject:forKey:]: unrecognized selector sent to instance 0x3e793088
9  Mind                                0x0015de70 -[CCTextureCache textureFromFile:] + 528
10  Mind                                0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11  Mind                                0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12  Mind                                0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13  Mind                                0x000854c4 -[ImageLoadOperation performLoad] + 68
14  Mind                                0x00085800 -[ResourceLoadOperation main] + 112
15  Foundation                          0x30c4c8b5 -[__NSOperationInternal start] + 664
16  Foundation                          0x30c4c613 -[NSOperation start] + 22
17  Foundation                          0x30cbdb63 ____startOperations_block_invoke_2 + 46
18  libSystem.B.dylib                  0x31227858 _dispatch_call_block_and_release + 20
19  libSystem.B.dylib                  0x3122863c _dispatch_worker_thread2 + 128
20  libSystem.B.dylib                  0x311b1544 _pthread_wqthread + 400
21  libSystem.B.dylib                  0x311a8b74 __stack_chk_fail + 4294967295

Il codice in questione è:

[texture setObject: Struttura Forkey: filename];

texture è di tipo NSMutableDictionary * e non viene mai riassegnato o deallocata (naturalmente, dal momento che questo è un oggetto di cache). Questo è l'unico posto in cui setObject viene richiamato in questo metodo, ma secondo l'analisi dello stack, texture era una stringa.

Ho anche ottenere questo stranezza:

Error: NSInvalidArgumentException: -[NSConcreteNotification getPixelFormatForIdentifier:]: unrecognized selector sent to instance 0x5c021b0
9  Mind                                0x0015dd0c -[CCTextureCache textureFromFile:] + 172
10  Mind                                0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11  Mind                                0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12  Mind                                0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13  Mind                                0x000854c4 -[ImageLoadOperation performLoad] + 68
14  Mind                                0x00085800 -[ResourceLoadOperation main] + 112
15  Foundation                          0x347b78b5 -[__NSOperationInternal start] + 664
16  Foundation                          0x347b7613 -[NSOperation start] + 22
17  Foundation                          0x34828b63 ____startOperations_block_invoke_2 + 46
18  libSystem.B.dylib                  0x32a2f858 _dispatch_call_block_and_release + 20
19  libSystem.B.dylib                  0x32a3063c _dispatch_worker_thread2 + 128
20  libSystem.B.dylib                  0x329b9544 _pthread_wqthread + 400
21  libSystem.B.dylib                  0x329b0b74 __stack_chk_fail + 4294967295

Questa traccia è dal seguente codice nel CCTextureCache:

CCTexture2DPixelFormat PixelFormat = [auto getPixelFormatForIdentifier: identificatore];

Come CCTextureCache cambiato in NSConcreteNotification dopo aver già chiamato un certo numero di metodi su se stessa è sconcertante per non dire altro.

Qualcun altro ha notato questo genere di cose? Sto diventando in qualche modo di corruzione della memoria?

È stato utile?

Soluzione

Hai controllato alcune condizioni di gara su multi-thread? Sembra che alcune delle risorse liberate da un altro thread, e thread corrente inviare un messaged a un oggetto deallocato.

Error: NSInvalidArgumentException: -[NSCFString setObject:forKey:]: unrecognized selector sent to instance 0x3e793088
9  Mind                                0x0015de70 -[CCTextureCache textureFromFile:] + 528
10  Mind                                0x0015d9f4 -[CCTextureCache loadImageUncached:pixelFormat:] + 116
11  Mind                                0x0015d058 -[CCTextureCache addImage:pixelFormat:] + 152
12  Mind                                0x00080524 -[ImageLoader imageWithFile:pixelFormat:] + 84
13  Mind                                0x000854c4 -[ImageLoadOperation performLoad] + 68
14  Mind                                0x00085800 -[ResourceLoadOperation main] + 112
15  Foundation                          0x30c4c8b5 -[__NSOperationInternal start] + 664
16  Foundation                          0x30c4c613 -[NSOperation start] + 22
17  Foundation                          0x30cbdb63 ____startOperations_block_invoke_2 + 46
18  libSystem.B.dylib                  0x31227858 _dispatch_call_block_and_release + 20
19  libSystem.B.dylib                  0x3122863c _dispatch_worker_thread2 + 128
20  libSystem.B.dylib                  0x311b1544 _pthread_wqthread + 400
21  libSystem.B.dylib                  0x311a8b74 __stack_chk_fail + 4294967295

Altri suggerimenti

Questo è spesso causato da errori di gestione della memoria. Hai provato zombie ?

  

... con zombie attivati, si comportano i messaggi agli oggetti deallocata non sarà più   stranamente o bloccarsi in difficili da comprendere modi, ma sarà invece registrare un messaggio   e morire in modo prevedibile e debugger-breakpointable. Questo è lo strumento da utilizzare   quando si cerca di rintracciare over-release e rilasci prematuri.

Ho appena incontrato lo stesso problema, ma si scopre che avevo fatto un errore stupido:

I aveva dichiarato un membro del genere nel file di intestazione:

NSMutableDictionary* myDict; 

Ma poi inizializzato in questo modo nel file .m:

myDict = [[NSDictionary alloc] init];

, che è valido e tutti, perché il NSMutableDictionary è derivata dalla classe NSDictionary. Pertanto tutte le chiamate che vengono ereditate da NSDictionary effettivamente lavorato, ma le chiamate specifiche per NSMutableDictionary [setObject: Forkey:]. Fallito perché ho cercato di richiamare loro sulla classe genitore

L'errore è stato veramente stupido, ma mi è stato anche gettato fuori dal fatto che il debugger ha segnalato il tipo di myDict come qualcosa di totalmente diverso (né NSDictionary, nè NSMutableDictionary). Spero che questo aiuta alcuni altri coder stanco: -)

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top