【问题标题】:Stack Overflow occuring when moving my window (C++, winapi)移动窗口时发生堆栈溢出(C++,winapi)
【发布时间】:2014-12-16 18:09:37
【问题描述】:

所以我有一个相当大的程序,并且开始出现一个我似乎无法追踪的新错误 - 并且撤消我记得最近所做的更改并没有证明是富有成效的。下面的所有代码实际上从程序开始就已经存在 - 仍然没有改变。我……至少可以这么说,我很困惑。 ;_;

如果它有助于诊断;我正在使用 Visual Studio 2012 Express 和 OpenCV api。

所以有两种方法可以让我始终得到错误:

  1. 尝试通过标题栏抓取窗口并移动它。
  2. 在与任何选项交互后尝试“隐藏”选项窗口(即使只是单击文本框 - 无需实际更改/键入任何内容)。

    case WM_COMMAND:
        switch(LOWORD(wParam))
        {
            case IDOK:
                SendMessage(g_hOptions, WM_COMMAND, IDAPPLY, NULL);
                ShowWindow(g_hOptions, SW_HIDE); //Causes the issue
            break;
            case IDAPPLY:
                //Never Crashes Program
            break;
            case IDCANCEL:
                SendMessage(cboDotColors, CB_SETCURSEL, currentDot, 0);
                SendMessage(cboBackgroundColors, CB_SETCURSEL, currentBG, 0);
                SendMessage(cboCentralColors, CB_SETCURSEL, currentCen, 0);
                SendMessage(cboCornerColor, CB_SETCURSEL, currentCC, 0);
                SendMessage(cboSaveShots, CB_SETCURSEL, currentSS, 0);
                SendMessage(cboDebugMode, CB_SETCURSEL, currentDM, 0);
                SendMessage(cboTextOutput, CB_SETCURSEL, currentTO, 0);
                SendMessage(cboLighting, CB_SETCURSEL, lightingCondition, 0);
                SetDlgItemText(g_hOptions, IDD_MINSIZE_ETB, const_cast<char *>(to_string(minPixelCount).c_str()));
                SetDlgItemText(g_hOptions, IDD_MAXSIZE_ETB, const_cast<char *>(to_string(maxPixelCount).c_str()));
                SetDlgItemText(g_hOptions, IDD_VISUALTHRESH_ETB, const_cast<char *>(to_string(visualThreshold).c_str()));
                SetDlgItemText(g_hOptions, IDD_ALIGNMENTTHRESH_ETB, const_cast<char *>(to_string(alignmentThreshold).c_str()));
                SetDlgItemText(g_hOptions, IDD_DELAY_MULTIPLIER_ETB, const_cast<char *>(to_string(endDelayMultiplier).c_str()));
                SetDlgItemText(g_hOptions, IDD_DELAY_DIVISOR_ETB, const_cast<char *>(to_string(endDelayDivisor).c_str()));
                SetDlgItemText(g_hOptions, IDD_PICTURE_DELAY_ETB, const_cast<char *>(to_string(pictureWait).c_str()));
                ShowWindow(g_hOptions, SW_HIDE);
        {
    

(以上内容有所删减,因为其他事情似乎没有与/导致问题交互。)

不会触发它的事情:显示选项窗口、移动选项窗口、更改选项窗口、应用这些更改、将焦点移离/移回程序,将程序用于其正常功能,然后让它无所事事。

所以这是从 Visual Studio 弹出的实际错误:

ProjectNameHere.exe 中 0x01447FB7 处未处理的异常:0xC00000FD:堆栈溢出(参数:0x00000000、0x03332000)。

第一个和最后一个数字可以不同。 如果我点击“继续”,则会出现另一个错误:

ProjectNameHere.exe 中 0x01447FB7 处的未处理异常:0xC0000005:访问冲突读取位置 0x03330000。

相同的数字在这里有所不同 - 它们在两个错误之间保持一致。 如果我继续尝试推动它,第二个错误不会进一步改变 - 只是重复自己。

崩溃时运行的线程总是:[10###] msvcr110d.dll!_threadstartex 当我查看 VS 中的“调用堆栈”时,我实际编写的最近执行的行是“return DefWindowProc(hwnd, msg, wParam, lParam);”

LRESULT CALLBACK WndProc(HWND hwnd, UINT msg, WPARAM wParam, LPARAM lParam)
{
    switch(msg)
    {
        case WM_CREATE:
            g_hOptions = CreateDialog(GetModuleHandle(NULL), MAKEINTRESOURCE(IDD_OPTIONS), hwnd, OptionsDlgProc);
            g_hbmBoard = ConvertIplImageToHBITMAP(targetBoardImg);
            g_hbmGreenLight = ConvertIplImageToHBITMAP(GreenLightOff);
            g_hbmWorkingLight = ConvertIplImageToHBITMAP(GreenLightOff);
            g_hbmWorkingIndicator = ConvertIplImageToHBITMAP(WorkingIndicatorNull);
            if(g_hbmBoard == NULL)
            {
                setExitError(1001);
                MessageBox(hwnd, "Could not load target board!", "Error", MB_OK | MB_ICONEXCLAMATION);
            }
            hDataBox = CreateWindowEx(WS_EX_STATICEDGE, TEXT("EDIT"), TEXT(""),
                WS_CHILD | WS_VISIBLE | ES_READONLY | WS_BORDER |
                ES_MULTILINE | ES_AUTOVSCROLL | WS_VSCROLL,
                screenResW - 349, 100, 315, 470,
                hwnd, (HMENU)NULL, NULL, NULL );
            CreateWindow(TEXT("Button"), TEXT("Load and Process"),
                WS_VISIBLE | WS_CHILD | BS_DEFPUSHBUTTON,
                screenResW - 349, 35, 315, 50,
                hwnd, (HMENU) ID_START_STOP, NULL, NULL );
            CreateWindow(TEXT("Button"), TEXT("Clear Processing"),
                WS_VISIBLE | WS_CHILD,
                screenResW - 349, 585, 155, 35,
                hwnd, (HMENU) ID_BUTTON_CLEARPROCESSING, NULL, NULL );
            CreateWindow(TEXT("Button"), TEXT("Save Data"),
                WS_VISIBLE | WS_CHILD,
                screenResW - 349, 630, 155, 35,
                hwnd, (HMENU) ID_FILE_SAVE, NULL, NULL );
            CreateWindow(TEXT("Button"), TEXT("Clear Data"),
                WS_VISIBLE | WS_CHILD,
                screenResW - 189, 585, 155, 35,
                hwnd, (HMENU) ID_FILE_CLEAR, NULL, NULL );
            CreateWindow(TEXT("Button"), TEXT("Quit"),
                WS_VISIBLE | WS_CHILD,
                screenResW - 189, 630, 155, 35,
                hwnd, (HMENU) ID_FILE_EXIT, NULL, NULL );
        break;
        case WM_PAINT:
            g_hbmBoard = ConvertIplImageToHBITMAP(targetBoardImg);
            BITMAP bm;
            PAINTSTRUCT ps;
            HDC hdc = BeginPaint(hwnd, &ps);
            HDC hdcMem = CreateCompatibleDC(hdc);

            HBITMAP hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmBoard);
            GetObject(g_hbmBoard, sizeof(bm), &bm);
            BitBlt(hdc, 0, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

            hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmGreenLight);
            GetObject(g_hbmGreenLight, sizeof(bm), &bm);
            BitBlt(hdc, screenResW - 59, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

            hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmWorkingLight);
            GetObject(g_hbmWorkingLight, sizeof(bm), &bm);
            BitBlt(hdc, screenResW - 94, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

            hbmOld = (HBITMAP)SelectObject(hdcMem, g_hbmWorkingIndicator);
            GetObject(g_hbmWorkingIndicator, sizeof(bm), &bm);
            BitBlt(hdc, screenResW - 129, 0, bm.bmWidth, bm.bmHeight, hdcMem, 0, 0, SRCCOPY);

            SelectObject(hdcMem, hbmOld);
            DeleteDC(hdcMem);

            EndPaint(hwnd, &ps);
        break;
        case WM_COMMAND:
            if(HIWORD(wParam) == BN_CLICKED)
            {
                switch(LOWORD(wParam))
                {
                    //case ID_BUTTON_CAMVIEW:
                        //{
                            //if(!camviewOn)
                            //{thread (displayCameraView).detach();}
                        //}
                    break; // Whoops! Not that this should affect anything...
                    case ID_FILE_SAVE:
                    {
                        if(textBoxCoords != "")
                        {
                            OPENFILENAME ofn;
                            WCHAR savefile[MAX_PATH+1] = L"";
                            ZeroMemory(&ofn, sizeof(ofn));
                            ofn.lStructSize = sizeof(ofn); 
                            ofn.hwndOwner = hwnd;
                            ofn.lpstrFilter = (LPCSTR)"Text(*.txt)\0*.txt\0All Files(*.*)\0*.*\0";
                            ofn.lpstrFile = (LPSTR)savefile;
                            ofn.nMaxFile = MAX_PATH;
                            ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST | OFN_HIDEREADONLY;
                            ofn.lpstrDefExt = (LPCSTR)"txt";
                            if(textOutput){cout << "Choosing save file...\n";}
                            if(GetSaveFileName(&ofn))
                            {
                                ifstream checkFile;
                                checkFile.open(ofn.lpstrFile);
                                if(checkFile.good())
                                {
                                    checkFile.close();
                                    if(textOutput){cout << "File exists.\n";}
                                    if(MessageBox(hwnd, "File exists. Overwrite?", "Overwrite?", MB_ICONEXCLAMATION | MB_YESNO) == IDYES)
                                    {
                                        ofstream outputFile;
                                        outputFile.open ((ofn.lpstrFile), fstream::in | fstream::out | fstream::trunc);
                                        if(outputFile.is_open())
                                        {
                                            outputFile << textBoxCoords;
                                            outputFile.close();
                                            if(textOutput){cout << "File overwritten.\n";}
                                        }
                                        else
                                        {
                                            if(textOutput){cout << "File failed to open.\n";}
                                            MessageBox(hwnd, "File could not be saved.", "Error!",
                                                MB_ICONEXCLAMATION | MB_OK);
                                            outputFile.close(); // Just in case.
                                        }
                                    }
                                    else
                                    {
                                        if(textOutput){cout << "File not overwritten.\n";}
                                    }
                                }
                                else
                                {
                                    checkFile.close();
                                    ofstream outputFile;
                                    outputFile.open ((ofn.lpstrFile), fstream::in | fstream::out | fstream::trunc);
                                    if(outputFile.is_open())
                                    {
                                        outputFile << textBoxCoords;
                                        outputFile.close();
                                        if(textOutput){cout << "File Saved.\n";}
                                    }
                                    else
                                    {
                                        if(textOutput){cout << "File failed to open.\n";}
                                        MessageBox(hwnd, "File could not be saved.", "Error!",
                                            MB_ICONEXCLAMATION | MB_OK);
                                        outputFile.close(); // Just in case.
                                    }
                                }
                            }
                            else
                            {if(textOutput){cout << "File save canceled.\n";}}
                        }
                        else
                        {MessageBox(hwnd, "Nothing to save.", "Error!", MB_ICONEXCLAMATION | MB_OK);}
                    }
                    break;
                    case ID_FILE_LOAD:
                    {
                        OPENFILENAME ofn;
                        WCHAR loadfile[MAX_PATH+1] = L"";
                        ZeroMemory(&ofn, sizeof(ofn));
                        ofn.lStructSize = sizeof(ofn); 
                        ofn.hwndOwner = hwnd;
                        ofn.lpstrFilter = (LPCSTR)"Text(*.txt)\0*.txt\0All Files(*.*)\0*.*\0";
                        ofn.lpstrFile = (LPSTR)loadfile;
                        ofn.nMaxFile = MAX_PATH;
                        ofn.Flags = OFN_EXPLORER | OFN_FILEMUSTEXIST;
                        ofn.lpstrDefExt = (LPCSTR)"txt";
                        if(textOutput){cout << "Choosing load file...\n";}
                        if(GetOpenFileName(&ofn))
                        {
                            ifstream inputFile;
                            inputFile.open(ofn.lpstrFile);
                            if (inputFile.is_open())
                            {
                                if(textBoxCoords == "" || MessageBox(hwnd, "Loading a file will clear all current datapoints. Unsaved data will be lost. Are you sure you want to proceed?",
                                    "Barrel full of monkeys?", MB_ICONEXCLAMATION | MB_YESNO) == IDYES)
                                {
                                    textBoxCoords = "";
                                    inputFile.seekg(0, std::ios::end);
                                    textBoxCoords.reserve(inputFile.tellg());
                                    inputFile.seekg(0, std::ios::beg);
                                    textBoxCoords.assign((std::istreambuf_iterator<char>(inputFile)), std::istreambuf_iterator<char>());
                                    refreshTargetBoard();
                                    if(textOutput){cout << "Data loaded.\n";}
                                    inputFile.close();
                                }
                            }
                            else
                            {
                                if(textOutput){cout << "File does not exist or cannot  be read.\n";}
                                    MessageBox(hwnd, "File could not be opened.", "Error!",
                                        MB_ICONEXCLAMATION | MB_OK);
                            }
                        }
                        else
                        {if(textOutput){cout << "File load canceled.\n";}}
                    }
                    break;
                    case ID_BUTTON_RESETERRORS:
                    {
                        exitCode = 0;
                        g_hbmGreenLight = ConvertIplImageToHBITMAP(GreenLightOff);
                        program_ON = false;
                        char Starp[6];
                        sprintf(Starp, "Start");
                        SetDlgItemTextA(hwnd, ID_START_STOP, (LPCSTR)Starp);
                        updateMainWindow();
                        clickPoint[0].X = -1; clickPoint[0].Y = -1;
                        clickPoint[1].X = -1; clickPoint[1].Y = -1;
                        clickPoint[2].X = -1; clickPoint[2].Y = -1;
                        clickPoint[3].X = -1; clickPoint[3].Y = -1;
                        done = true;
                    }
                    break;
                    case ID_BUTTON_CLEARPROCESSING:
                    {
                        //Not written yet.
                    }
                    break;
                    case ID_FILE_CLEAR:
                    {
                        if(textBoxCoords == "" || MessageBox(hwnd, "All unsaved data will be lost.\r\nAre you sure you wish to proceed?", "Make data go \"Bye-Bye\"?", MB_ICONEXCLAMATION | MB_YESNO) == IDYES)
                        {
                            textBoxCoords = "";
                            refreshTargetBoard();
                            if(textOutput){cout << "Data cleared.\n";}
                        }
                    }
                    break;
                    case ID_FILE_OPTIONS:
                    {
                        if(g_hOptions != NULL)
                        {ShowWindow(g_hOptions, SW_SHOW);}//AnimateWindow(g_hOptions, 200, AW_ACTIVATE);}
                        else
                        {MessageBox(hwnd, "Options window failed to be created", "Warning!", MB_OK | MB_ICONINFORMATION);}
                    }
                    break;
                    case ID_FILE_CALIBRATE:
                    {if(textOutput){cout << "Calibration window not yet available.\n";}}
                    break;
                    case ID_FILE_EXIT:
                    {exitProg = true; done = true; Sleep(30); PostMessage(hwnd, WM_CLOSE, 0, 0);}
                    break;
                    case ID_HELP_INST:
                    {if(textOutput){cout << "Instructions window not yet available.\n";}} // TODO
                    break;
                    case ID_HELP_ABOUT:
                    {if(textOutput){cout << "About window not yet available.\n";}} // TODO
                    break;
                    case ID_LOAD_PROCESS:
                    {
                        if(exitCode == 0)
                        {
                            done = false;
                            if(!program_ON)
                            {
                                program_ON = true;
                                thread (pointProc).detach();
                                thread (workingIndicatorFunction).detach();
                            }
                        }
                    }
                    break;
                    case ID_START_STOP:
                    {
                        if(exitCode == 0)
                        {
                            if(!program_ON)
                            {
                                g_hbmGreenLight = ConvertIplImageToHBITMAP(GreenLightOn);
                                program_ON = true;
                                char Starp[5];
                                sprintf(Starp, "Stop");
                                SetDlgItemTextA(hwnd, ID_START_STOP, (LPCSTR)Starp);
                                updateMainWindow();
                                done = false;
                                thread (pointProc).detach();
                                thread (workingIndicatorFunction).detach();
                                if(true) // Part of functionality that was changed earlier.
                                {
                                    const int MAX_SHOTFILE_LINES = 512;
                                    IplImage* imgB4;
                                    IplImage* imgAR;
                                    Mat TempB4;
                                    Mat TempAR;
                                    ifstream shotFile;
                                    shotFile.open("Input Pictures/ShotFile.txt");
                                    if(shotFile.good())
                                    {
                                        char shotFileLine[MAX_SHOTFILE_LINES][512] = {};
                                        int countUp = 0;
                                        string lineGot = "";
                                        while(!shotFile.eof() && countUp < MAX_SHOTFILE_LINES)
                                        {
                                            std::getline(shotFile, lineGot);
                                            int lineGotSize = lineGot.size();
                                            for(int i = 0; i < lineGotSize; i++)
                                            {shotFileLine[countUp][i] = lineGot.at(i);}
                                            countUp++;
                                        }
                                        for(int i = 0; i < countUp; i++)
                                        {
                                            if(isalnum(shotFileLine[i][0]))
                                            {
                                                string filenames[2];
                                                int fileCoords[8];

                                                int numSearch = 0;
                                                int numCheck = 0;
                                                int totalShotFileWords = 0;

                                                string shotFileLineStr(shotFileLine[i]);

                                                for(;numSearch < 512;numSearch++)
                                                {
                                                    if(shotFileLine[i][numSearch] == ' ' || shotFileLine[i][numSearch] == NULL)
                                                    {
                                                        if(totalShotFileWords < 2)
                                                        {
                                                            filenames[totalShotFileWords] = "Input Pictures/" + shotFileLineStr.substr(numCheck, (1+numSearch-numCheck));
                                                        }
                                                        else if(totalShotFileWords < 10)
                                                        {
                                                            for(int count = numCheck; count < numSearch; count++)
                                                            {if(!isdigit(shotFileLine[i][count])){goto malformed_coords;}}
                                                            istringstream(shotFileLineStr.substr(numCheck, (1+numSearch-numCheck))) >> fileCoords[totalShotFileWords-2];
                                                        }
                                                        numCheck = numSearch+1;
                                                        totalShotFileWords++;
                                                    }
                                                    if(shotFileLine[i][numSearch] == NULL){break;}
                                                }
                                                malformed_coords:
                                                if(totalShotFileWords < 2) // Not enough filenames
                                                {/*\Nothing Happens\*/}
                                                else if(totalShotFileWords < 10) // Not enough coords
                                                {
                                                    imgB4 = cvLoadImage( filenames[0].c_str(), 1);
                                                    if(imgB4 != NULL)
                                                    {
                                                        TempB4 = imgB4;
                                                        imgAR = cvLoadImage( filenames[1].c_str(), 1);
                                                        if (imgAR != NULL)
                                                        {
                                                            TempAR = imgAR;
                                                            Mat TestshotB4 = TempB4*1;
                                                            Mat TestshotAR = TempAR*1;
                                                            falsePics(TestshotB4, TestshotAR, ++audioCount);
                                                            cvReleaseImage(&imgB4);
                                                            cvReleaseImage(&imgAR);
                                                            delete imgB4;
                                                            delete imgAR;
                                                        }
                                                    }
                                                }
                                                else // Got everything
                                                {
                                                    imgB4 = cvLoadImage( filenames[0].c_str(), 1);
                                                    if(imgB4 != NULL)
                                                    {
                                                        TempB4 = imgB4;
                                                        imgAR = cvLoadImage( filenames[1].c_str(), 1);
                                                        if (imgAR != NULL)
                                                        {
                                                            TempAR = imgAR;
                                                            Mat TestshotB4 = TempB4*1;
                                                            Mat TestshotAR = TempAR*1;
                                                            coords testShotCyanCoordsA, testShotCyanCoordsB, testShotCyanCoordsC, testShotCyanCoordsD;
                                                            testShotCyanCoordsA.X = fileCoords[0]; testShotCyanCoordsA.Y = fileCoords[1];
                                                            testShotCyanCoordsB.X = fileCoords[2]; testShotCyanCoordsB.Y = fileCoords[3];
                                                            testShotCyanCoordsC.X = fileCoords[4]; testShotCyanCoordsC.Y = fileCoords[5];
                                                            testShotCyanCoordsD.X = fileCoords[6]; testShotCyanCoordsD.Y = fileCoords[7];
                                                            falsePics(TestshotB4, TestshotAR, ++audioCount, testShotCyanCoordsA, testShotCyanCoordsB, testShotCyanCoordsC, testShotCyanCoordsD);
                                                            cvReleaseImage(&imgB4);
                                                            cvReleaseImage(&imgAR);
                                                            delete imgB4;
                                                            delete imgAR;
                                                        }
                                                    }
                                                }
                                            }
                                        }
                                    }
                                    shotFile.close();
                                }
                            }
                            else
                            {
                                g_hbmGreenLight = ConvertIplImageToHBITMAP(GreenLightOff);
                                program_ON = false;
                                char Starp[20];
                                sprintf(Starp, "Load and Process");
                                SetDlgItemTextA(hwnd, ID_START_STOP, (LPCSTR)Starp);
                                updateMainWindow();
                                done = true;
                            }
                        }
                    }
                    break;
                }
            }
                    break;
        case WM_CLOSE:
        {
            if(textBoxCoords == "" || MessageBox(hwnd, "Are you certain you wish to exit?\r\nAll unsaved data will be lost.", "Leaving so soon?", MB_ICONEXCLAMATION | MB_YESNO) == IDYES)
            {
                DestroyWindow(hwnd);
            }
        }
        break;
        case WM_DESTROY:
        {
            if(textOutput){cout << "\nExiting.\n\n";}
            else{if(IsWindow(consoleWindow)){ShowWindow(consoleWindow, SW_SHOW);} cout << "\nExiting.\n\n";}
            PostQuitMessage(0);
        }
        break;
        default:
            cout << setw(10) << hwnd << setw(10) << msg << setw(15) << wParam << setw(15) << lParam << endl;
            //Recent addition when this started. If you think the info I get from this would help, please ask!
            return DefWindowProc(hwnd, msg, wParam, lParam); // <===This thing!
    }
    return 0;
}

它崩溃的实际代码在“chkstk.asm”中:“test dword ptr [eax],eax”

; Find next lower page and probe
cs20:
        sub     eax, _PAGESIZE_         ; decrease by PAGESIZE
        test    dword ptr [eax],eax     ; probe page. <====
        jmp     short cs10

这是来自 Visual Studio 的完整堆栈跟踪/调用堆栈:

Project1.exe!_chkstk() Line 99  Unknown
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_SendMessageWorker@20()  Unknown
user32.dll!_SendMessageW@16()   Unknown
msctf.dll!UIComposition::UpdateCompositionRect(class IMCLock &) Unknown
msctf.dll!CIMEUIWindowHandler::ImeUINotifyHandler(struct HWND__ *,unsigned int,unsigned int,long)   Unknown
msctf.dll!CIMEUIWindowHandler::ImeUIWndProcWorker(struct HWND__ *,unsigned int,unsigned int,long)   Unknown
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_SendMessageWorker@20()  Unknown
user32.dll!_SendMessageToUI@20()    Unknown
user32.dll!_ImeNotifyHandler@16()   Unknown
user32.dll!_ImeWndProcWorker@20()   Unknown
user32.dll!_ImeWndProcW@16()    Unknown
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_SendMessageWorker@20()  Unknown
user32.dll!_RealDefWindowProcWorker@20()    Unknown
user32.dll!_RealDefWindowProcA@16() Unknown
user32.dll!_DefWindowProcA@16() Unknown
Project1.exe!WndProc(HWND__ * hwnd=0x000f04be, unsigned int msg=642, unsigned int wParam=11, long lParam=0) Line 1842   C++
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_SendMessageWorker@20()  Unknown
user32.dll!_SendMessageW@16()   Unknown
imm32.dll!_MakeIMENotify@28()   Unknown
imm32.dll!_ImmSetCompositionWindow@8()  Unknown
user32.dll!_ImeSetContextHandler@16()   Unknown
user32.dll!_ImeWndProcWorker@20()   Unknown
user32.dll!_ImeWndProcW@16()    Unknown
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_SendMessageWorker@20()  Unknown
user32.dll!_RealDefWindowProcWorker@20()    Unknown
user32.dll!_RealDefWindowProcA@16() Unknown
user32.dll!_DefWindowProcA@16() Unknown
Project1.exe!WndProc(HWND__ * hwnd=0x000f04be, unsigned int msg=641, unsigned int wParam=1, long lParam=-1073741809) Line 1842  C++
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_SendMessageWorker@20()  Unknown
user32.dll!_SendMessageW@16()   Unknown
imm32.dll!_ImmSetActiveContext@12() Unknown
user32.dll!_FocusSetIMCContext@8()  Unknown
user32.dll!_ImeSystemHandler@16()   Unknown
user32.dll!_ImeWndProcWorker@20()   Unknown
user32.dll!_ImeWndProcW@16()    Unknown
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_DispatchClientMessage@20()  Unknown
user32.dll!___fnDWORD@4()   Unknown
ntdll.dll!_KiUserCallbackDispatcher@12()    Unknown
user32.dll!_GetWindowInfo@8()   Unknown
user32.dll!_RealDefWindowProcA@16() Unknown
user32.dll!_DefWindowProcA@16() Unknown
Project1.exe!WndProc(HWND__ * hwnd=0x000f04be, unsigned int msg=6, unsigned int wParam=1, long lParam=1640404) Line 1842    C++
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_DispatchClientMessage@20()  Unknown
user32.dll!___fnDWORD@4()   Unknown
ntdll.dll!_KiUserCallbackDispatcher@12()    Unknown
user32.dll!_GetWindowInfo@8()   Unknown
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallDlgProcCheckWow@32()    Unknown
user32.dll!_DefDlgProcWorker@20()   Unknown
user32.dll!_DefDlgProcA@16()    Unknown
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_SendMessageWorker@20()  Unknown
user32.dll!_SendMessageW@16()   Unknown
user32.dll!_xxxButtonNotifyParent@8()   Unknown
user32.dll!_xxxBNReleaseCapture@8() Unknown
user32.dll!_ButtonWndProcWorker@20()    Unknown
user32.dll!_ButtonWndProcA@16() Unknown
user32.dll!_InternalCallWinProc@20()    Unknown
user32.dll!_UserCallWinProcCheckWow@32()    Unknown
user32.dll!_DispatchMessageWorker@8()   Unknown
user32.dll!_DispatchMessageA@4()    Unknown
Project1.exe!WinMain(HINSTANCE__ * hInstance=0x00000000, HINSTANCE__ * hPrevInstance=0x00000000, char * lpCmdLine=0x00000000, int nCmdShow=1) Line 1914 C++
Project1.exe!std::_Bind<0,void,int (__stdcall*)(HINSTANCE__ *,HINSTANCE__ *,char *,int),HINSTANCE__ *,HINSTANCE__ *,char *,int,std::_Nil,std::_Nil,std::_Nil>::operator()() Line 1152   C++
Project1.exe!std::_LaunchPad<std::_Bind<0,void,int (__stdcall*)(HINSTANCE__ *,HINSTANCE__ *,char *,int),HINSTANCE__ *,HINSTANCE__ *,char *,int,std::_Nil,std::_Nil,std::_Nil> >::_Run(std::_LaunchPad<std::_Bind<0,void,int(__stdcall*)(HINSTANCE__ *,HINSTANCE__ *,char *,int),HINSTANCE__ *,HINSTANCE__ *,char *,int,std::_Nil,std::_Nil,std::_Nil> > * _Ln=0x0012fafc) Line 196  C++
Project1.exe!std::_LaunchPad<std::_Bind<0,void,int (__stdcall*)(HINSTANCE__ *,HINSTANCE__ *,char *,int),HINSTANCE__ *,HINSTANCE__ *,char *,int,std::_Nil,std::_Nil,std::_Nil> >::_Go() Line 187 C++
msvcp110d.dll!_Call_func(void * _Data=0x0012fafc) Line 52   C++
msvcr110d.dll!_callthreadstartex() Line 354 C
msvcr110d.dll!_threadstartex(void * ptd=0x00bcaba8) Line 337    C
kernel32.dll!@BaseThreadInitThunk@12()  Unknown
ntdll.dll!___RtlUserThreadStart@8() Unknown
ntdll.dll!__RtlUserThreadStart@8()  Unknown

我实际上不确定从这里去哪里。帮忙?

(如果您需要有关它的更多信息,请询问 - 我不完全确定这里有什么相关的,并且有很多代码和大量数据......编辑:这现在应该对所有人都很明显...... .)

【问题讨论】:

  • @HansPassant 我看到了那个——它对我的问题没有帮助。不知何故,断点被跳过,我最终直接进入错误。
  • 堆栈跟踪在哪里?
  • 那个栈不是很深。在你的 wndproc 中有一个 chkstk 调用的事实告诉我,你有非常大的局部变量正在吃掉你的堆栈。你的窗口过程中不应该有 chkstk。
  • @Alexander 看一眼你的代码,你已经在堆栈上分配了很多东西,但是 'char shotFileLine[MAX_SHOTFILE_LINES][512] = {}' 很大,然后会加剧WindProc 在堆栈上三次。要么动态分配它(std:vector?),减小它的大小,要么将 ID_START_STOP 案例重构到它自己的函数中,它可能会解决这个问题。

标签: c++ winapi visual-studio-2012


【解决方案1】:

深入了解调用堆栈。堆栈溢出的一个常见原因是无限递归。 DefWindowProc 是否以某种方式做某事最终调用WndProc,然后调用DefWindowProc,然后调用WndProc?中间可能有好几层函数调用。

也可能只是过度使用堆栈。增加堆栈大小的几种方法之一是:http://msdn.microsoft.com/en-us/library/tdkhxaks.aspx

其他可能的原因是堆栈上的大量分配(通常涉及alloca)或堆栈损坏。

【讨论】:

  • DefWindowProc 被多次调用;但几乎我所做的一切(成功或其他)都会导致它被多次调用。例如;通过关闭选项窗口崩溃时,它会被调用 19 次。当我成功关闭它时,它使用相同的 msg 参数调用相同的 19 次(其中一些参数略有不同的 wParams 和 lParams)再加上 3 次。崩溃的变体调用 DefWindowProc(00120888, 642, 11, 0) 而成功的等效调用 DefWindowProc(00120888, 642, 2, 0) - 我从未定义过 DefWindowProc,似乎找不到它。
  • 查看邮件编号。
  • 好消息是问题不在于无限递归(WndProc 的),否则你会在更大的堆栈中得到更多的调用(除非在计算调用次数时出错)。坏消息是你仍然有一些东西要么创建无限递归(WndProc 以外的函数),要么在堆栈上分配大量数据结构(>3mb),要么破坏堆栈:( 对不起,我不能更多比这更有帮助。
  • @RaymondChen - 假设有一个重复部分。堆栈没有在短时间内填满 - 程序在意识到使用了四分之一的堆栈空间之前就崩溃了。这意味着某些东西一次使用了> 75%的堆栈空间,或者我们正在查看其他东西并且错误被错误地报告为VS。或者完全是别的什么,我想。
  • Raymond 告诉你的那些,是你的 WndProc 和 DefWindowProc (which you should have had from the beginning by the way) 调用的第二个参数。在您之前与 Peter 交谈时列出的示例中,您说您一直收到 642,即 WM_IME_NOTIFY(如果您不知道那是什么,您可能没有使用它)。监视哪些消息进出您的窗口过程对于调试这些事情至关重要。
猜你喜欢
  • 1970-01-01
  • 2014-07-20
  • 2012-12-20
  • 2011-03-02
  • 2014-01-17
  • 1970-01-01
  • 1970-01-01
  • 2018-11-13
相关资源
最近更新 更多