3

我目前正在做一个人工智能项目。这是关于你需要将编号从 1 到 8 的棋子(空白区域标记为 0)移动到最后排序的谜题。但是,当我尝试调试它时遇到了一个奇怪的问题。

int CreateNewState(State *parent, Action action) {
State *newState;

    if (!(newState = (State*)malloc(sizeof(State)))) // <<<< Error
       return 0;
...

   // Populate my newState
   newState->parent = parent;
   newState->matrix = CreateMatrix();
...
   // Insert my newState in the Queue
   Insert(newState, myMode);
}


void Insert(State *state, Mode mode) {
   State *aux;

    if (IsEmpty()) {
        myQueue->firstState = state;
        myQueue->numberOfElements++;
    }
    else {
        aux = myQueue->firstState;

        switch (mode)
        {
            // Breadth First Search
            case BFS:
                while (aux->next != NULL) {
                   aux = aux->next;
                }
                aux->next = state;
                myQueue->numberOfElements++;
                break;
           ...

        }
    }
}

在指定的错误注释中,当我第二次调用 CreateNewState() 函数时,调试器停止并弹出:

AIProject_Puzzle.exe 已触发断点。

发生此错误时,我试图在调用堆栈中为你们带来一些额外的信息:

ntdll.dll!RtlReportCriticalFailure()
ntdll.dll!RtlpHeapHandleError()
ntdll.dll!RtlpLogHeapFailure()
ntdll.dll!RtlpAllocateHeap()
ntdll.dll!RtlAllocateHeap()
ucrtbased.dll!00007ff9b582c4da()
ucrtbased.dll!
00007ffrt9b582c2c .dll!00007ff9b582f34f()
ucrtbased.dll!00007ff9b582fdde()
AIProject_Puzzle.exe!CreateNewState(state * parent=0x000000c05c273520, action action=DOWN)

我知道这可能是堆损坏,所以我真正需要的是一个线索来解决这个问题。我正在使用 Visual Studio Community 2015,VisualC++。这个错误让我恶心。请问有人知道如何解决这个问题吗?

4

0 回答 0