C++ Visual Studio中未处理的异常访问冲突写入位置

C++ Visual Studio中未处理的异常访问冲突写入位置,c++,visual-studio-2005,access-violation,unhandled-exception,C++,Visual Studio 2005,Access Violation,Unhandled Exception,在VisualStudio2005中有没有办法找出导致这种访问冲突的指针或变量?我试图在调试模式下运行,并在发生时中断。通过查看调用堆栈,它发生在函数的末尾(见下文)。使用try/catch可以找出它是哪个指针吗 编辑: 发布我的代码: 在我的应用程序中有一个Qt行编辑和一个复选框。切换复选框将切换行编辑中的数据格式。像3'b111 3'h7。下面是连接到复选框stateChanged信号的回调函数。当销毁局部变量时,异常发生在函数末尾 // switch hex/binary format.

在VisualStudio2005中有没有办法找出导致这种访问冲突的指针或变量?我试图在调试模式下运行,并在发生时中断。通过查看调用堆栈,它发生在函数的末尾(见下文)。使用try/catch可以找出它是哪个指针吗


编辑: 发布我的代码:

在我的应用程序中有一个Qt行编辑和一个复选框。切换复选框将切换行编辑中的数据格式。像3'b111 3'h7。下面是连接到复选框stateChanged信号的回调函数。当销毁局部变量时,异常发生在函数末尾

// switch hex/binary format. 15'h0000 <==> 15'b000000000000000
void switchDataFormat(int checkState) {
    QLineEdit* writeRegLE = this->getWriteRegLineEdit();
    string oldText = writeRegLE->text().toStdString();
    string newText = "";
    int maxLength;
    string regLengthText = oldText.substr(0, oldText.find('\''));
    string regValueText = oldText.substr(oldText.find('\'')+2);
    int regLength = this->getRegLength();

    if (checkState == Qt::Unchecked) {
        // switch to binary format
        maxLength = regLengthText.size() + 2 + regLength;
        string binaryText;
        for (int i = 0; i < regValueText.size(); ++i) {
            binaryText += hexToBinary(regValueText[i]);
        }
        newText = regLengthText + "'b" + binaryText.substr(binaryText.size()-regLength);  // trimming leading zeros to fit regLength
    }
    else {
        // switch to hex format
        maxLength = regLengthText.size() + 2 + regLength/4 + 1;
        newText = regLengthText + "'h";
        // zero filling to 4*n bits
        if (regLength%4 != 0) regValueText = string(regLength%4,'0') + regValueText;
        for (int i = 0; i < regValueText.size(); i+=4) {
            newText += binaryToHex(regValueText.substr(i,4));
        }
    }

    writeRegLE->setMaxLength(maxLength);
    writeRegLE->setText(QString::fromUtf8(newText.c_str()));
}
//切换十六进制/二进制格式。15'h0000 15'b000000000000000
void switchDataFormat(int checkState){
QLineEdit*writeRegLE=this->getwriteregileneedit();
字符串oldText=writeRegLE->text().toStdString();
字符串newText=“”;
int最大长度;
字符串regLengthText=oldText.substr(0,oldText.find('\'');
字符串regValueText=oldText.substr(oldText.find('\'')+2);
int regLength=this->getRegLength();
if(checkState==Qt::Unchecked){
//切换到二进制格式
maxLength=regLengthText.size()+2+regLength;
字符串二进制文本;
对于(int i=0;isetMaxLength(maxLength);
writeRange->setText(QString::fromUtf8(newText.c_str());
}

发布有问题的代码。另外,在调试模式下,在您知道问题发生之前设置一个断点,然后一步一步地检查代码,这可能会暴露您的问题。@user1264727:代码太复杂了,我将尝试使用更简单的版本发布它。我“进入”void操作符delete(void*p),现在可以看到导致冲突的指针。我怎么知道指针指向什么呢?如果你把鼠标移到
p
上,VS会显示出来,但听起来好像你在删除一个不应该删除的指针。找出原因。也许你有双重删除-删除一个已经被删除的指针,这是一个坏主意。如果可以,请发布一个再现问题的最小示例。或者至少是发生崩溃的函数的代码。您具体在哪里分解局部变量?使用VS debugger逐步遍历代码,异常会在函数的最后一行“}”的步骤之后发生,并在“delete(void*p)”中发生。