ゲームが作れるようになるまでがんばる日記

ゲーム制作のことを中心にゲームに関することを書いています

typeidは使っちゃだめ?

DirectXのSample BrowserからSimpleSampleをインストール。そしてSimpleSample.cppのOnFrameMoveに次のようなコードを追加

class A
{
};

//--------------------------------------------------------------------------------------
// Handle updates to the scene.  This is called regardless of which D3D API is used
//--------------------------------------------------------------------------------------
void CALLBACK OnFrameMove( double fTime, float fElapsedTime, void* pUserContext )
{
    // Update the camera's position based on user input 
    g_Camera.FrameMove( fElapsedTime );

    static bool s_flag = false;
    if(!s_flag)
    {
        s_flag = true;

        A* p = new A;
        DXUTOutputDebugStringA( "(%s)\n", typeid(*p).name() );
        delete p;
    }
}

ビルドして実行して、ESCでアプリケーションを終了すると出力ウィンドウにメモリリーク検出のメッセージ。

Detected memory leaks!
Dumping objects ->
{683} normal block at 0x01866808, 8 bytes long.
 Data: <class A > 63 6C 61 73 73 20 41 00 
{682} normal block at 0x018667C0, 8 bytes long.
 Data: < h      > 08 68 86 01 00 00 00 00 
Object dump complete.

typeidを使っている行をコメントアウトするとメモリリークのメッセージは出てこない。


結局、今まで出ていたメモリリークは自分が確保したメモリの解放しわすれではなかった。
うーむ、DirectXではtypeidを使ってはいけないということなのか?