6

私が取り組んでいるC++プロジェクトは、ファーストチャンス例外をスローすると終了します。map<pair<int,int>, int>これは、Visual Studio 2008のデバッグモードで、単一のキーと値のペアを含むに最初にアクセスしようとしたときに発生します。コードに論理的な問題はありません。

私は最初のチャンスの例外を読み、それらが常に問題になるとは限らないことを理解しています。それにもかかわらず、私はそのようなすべての例外を壊そうとしました、そして予想通り、問題を引き起こさないいくつかが生成されることがわかりました。

私が取り組んでいるクラスは非常に大きく、多くのカスタムメモリ割り当てが含まれています。どういうわけか、これらの1つが問題を引き起こしていると思います。しかし、私は何が問題になっているのかを特定する方法を見つけるために数時間を費やしましたが、それを行うことができませんでした。

ファーストチャンス例外の出力を以下に示します。あまり役に立ちません!

First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x762cd09c in theapp.exe: 0xC0000005: Access violation reading location 0x6c696d00.
First-chance exception at 0x0050ae33 in theapp.exe: 0xC0000005: Access violation reading location 0x00000010.
Unhandled exception at 0x0050ae33 in theapp.exe: 0xC0000005: Access violation reading location 0x00000010.

私はこの時点で本当に苦労していて、どのように進めるかがわかりません。

誰かが私がこの問題に取り組む方法を提案し、何が悪いのかを正確に特定できますか?アドバイスをいただければ幸いです。

アップデート

関連するコードは次のとおりです。デバッガーは、ネストされたFORにリストされている最初のcoutステートメントで中断します。

        // Inside operator() :

        map<pair<int,int>,int> resultIdByStructIds;
        pair<int,int> spair (-1,-1); // Structure pair ids reusable reference.

        int nextMapEntryId = 0;
        int nextNumCandidates = 0;
        // For each remaining candidate.
        for (int ci = 0; ci < numCandidates; ) {
            // If candidate has been mapped or found not viable this mapping round,
            // move past it.
            if (candidatesDoneThisRound[ci] == currentMappingRoundId) {
                ++ci;
                continue;
            }

            Candidate candidate = candidates[ci];
            const int tId = candidate.tVertexId;
            const int pId = candidate.pVertexId;

            // Grab the result for this structure pair.
            // Create it if it doesn't exist.
            // Avoid copying as slight optimisation; simply
            // store pointer to true result instead.
            spair.first = tInfos[tId].structure->id;
            spair.second = pInfos[pId].structure->id;

            // DEBUG
            cout << "resultIdByStructIds size: " << resultIdByStructIds.size() << endl;
            for (map<pair<int,int>,int>::const_iterator ids_id = resultIdByStructIds.begin(); ids_id != resultIdByStructIds.end(); ++ids_id) {
                cout << ids_id->first.first << endl; // * Debugger breaks here.
                cout << ids_id->first.second << endl;
                cout << ids_id->second << endl;
                printf("Structures(%i,%i) => %i\n",ids_id->first.first,ids_id->first.second,ids_id->second);
            }
            //

            // code continues...

更新2

これは、問題のマップのマウスオーバーの説明の画像です。Michael Burrが示唆したように、破損しているように見えます。

ここに画像の説明を入力してください

4

1 に答える 1

9

一般に、アプリがクラッシュするコードの場所を特定するには、[デバッグ]/[例外]で例外処理をオンにします。この場合、最後のブランチを展開して、アクセス違反をチェックします。もちろん、それは悪いもの(0x10にアクセスする)だけでなく、すべてのアクセス違反で停止します。最後の既知の瞬間にトラップをオンにすることで、これを最小限に抑えることができます。

通常、メモリ使用量エラーが発生します。このタイプのエラーの原因を特定する最も簡単な方法は、BoundCheckerのようなサードパーティのツールで、メモリが破損するとすぐに怒鳴ります。それが欠けていると、レイモンド・チェンのアドバイスは的を射ている。どのオブジェクトが間違っているかを把握し、ウォッチウィンドウを使用していつ変更されたかを確認します。または、より効率的には、データブレークポイント機能を使用して、特定のアドレスのデータが変更されたときにプログラムを停止させます。

于 2012-02-16T14:33:32.227 に答える