謎のエラー | らいとういんぐ

らいとういんぐ

-Light Wings- Ж gameproject

横スクロールしゃぼん玉アクションゲーム 「しゃぼんふぁんたじあ」 制作中

今日、謎のエラーに悩まされていました。


↓やった事はこんな事

class object

{

  hoge* m_instance;

};




list<object> obj_list;


list<object>::Iterator it;

list<object>::Iterator end_it = obj_list.begin();


while(it!=end_it)

{

  delete (*it).m_instance;  // Run-Time Check Failure #0
  ++it;

}

上記のdeleteで

Run-Time Check Failure #0 - The value of ESP was not properly saved across a function call. This is usually a result of calling a function declared with one calling convention with a function pointer declared with a different calling convention.

が発生。


m_instanceはどこかで定義されたhogeクラスをオーバーライドしているクラスポインターでベースクラスポインターとして格納されとります。




色々考えられる事調べたのだけど、結局確証が無かったので省略。。

よく分かんないけど以下の様に変えたらいけました。


class object

{

  hoge* m_instance;

  ~object(){ delete m_instance; }

};




list<object*> obj_list;


list<object>::Iterator it;

list<object>::Iterator end_it = obj_list.begin();


while(it!=end_it)

{

  delete (*it);  // OK
  ++it;
}

何なんでしょうね。コンテナクラス謎です。

まぁ、ホントはカスタムされたツリーコンテナ使ってたんですがstdでも起こるのかも。


ぱっと書いたので構文が変なのはご容赦ください。