Assertion failed: (cls), function getName でハマる

Xcodeデバッグモードで実行したら、見慣れないエラーが出てる。何でしょ?

Assertion failed: (cls), function getName, file /SourceCache/objc4_Sim/objc4-427.1.1/runtime/objc-runtime-new.m, line 3939.

ググってみると、あちこちでFAQが上がってるんだけど、根本的な解決方法が分からない。Xcode 3.2.3 あたりからこの現象が出てるっぽい。

Not too sure if it's because I did install the new Xcode 3.2.4 with the iOS SDK 4.1 but now, when I debug part of my code, at almost every single line stepping, I get this in the console:

I've been using the similar code in a different part of
the program and never had this message but that was with Xcode 3.2.3 and iOS SDK 4.

Subject: Strange Assertion Failed error while debugging

とりあえず、ヒントっぽいのはこれかな?でも、何が NULL で渡されてるんだろ? :-(

I have exactly the same issue. I know it's not the complete answer but here's what I could find.

The relevant function getName looks like this:

So gdb is complaining that the assertion assert(cls) is failing. Which means that getName somehow gets a NULL pointer as an argument.

Which is kinda funny, where could we be asking for the name of a NULL class?

Hope this helps...

XCODE - Getting strange debugger message: Assertion failed: (cls), function getName: what is this?


いろんな書き込み内容をみてると gdb のバグとか、シミュレータバグっていう意見が多い。どっちにしろ、自分じゃ手が出せないよ。困ったなぁ。 :-(

追記

プロパティ属性(retain, assign)の設定ミスが原因だったっぽい。(^^;)

プロパティとして保持してる値を使い回そうとして、この現象が発生してるんだろと思えたので NULL になるならメモリ解放が動いてるんだろと推測。おんじゃと思って、ソースを見直したら、やっぱり assign になってたよ :-)

[誤] @property (nonatomic, assign) Book *book;
[正] @property (nonatomic, retain) Book *book;


assign だと参照カウントがアップしないから、メモリ解放されちゃんたんだろね。プロパティ属性の使い方、ちゃんと意識してなかったのが敗因。ちゃんと勉強しなおそっと。:-)

retain や assign の説明は 毎日コミュニケーションズダイナミック Objective-C の説明が分かりやすそう。メモっとこ。

追記2

う〜ん、プロパティ属性が原因じゃなかったらしい。ブレークポイントを設定してデバッグ実行すると function getName と出てくるし。なんなんでしょ? やっぱり GDB バグなのかな?作業がすすまないよ〜 (T^T)

検証環境
  • Mac OSX 10.6.5
  • Xcode 3.2.4