添加新行时工作代码引发异常.调试技巧?

Working code throwing exception when new lines added. Debugging tips?

本文关键字:调试 异常 新行时 工作 代码 添加      更新时间:2023-10-16

我正在研究一个专有的代码库,所以我必须抽象它。

我正在尝试在MyApplication中设置DataType_T*** myData的值。我正在使用共享的 c++ 库(我表示库 A(来设置值。共享 c++ 库只是围绕 C API 的简单包装类。C API 作为共享库包含在库 A 中(我表示库 B(。

因此,MyApplication 在 A 中调用 GetData(myData(,在 B 中调用 GetData(myData(。

我的应用程序具有以下代码:

void OnButtonPress(){
const DataType*** myData;
GetData(myData);
DataTypeVal1 val1 = (*myData)[0]->val1; // just grabbing some info.
}

GetData(myData(:工作并正确设置myData。

我:键入一些新代码

void OnButtonPress(){
const DataType*** myData;
GetData(myData);
const void* strData = (*myData)[0]->strData; // just grabbing some info now that we have the pointer.
//Add lots more new code that does this over and over for each member of myData
String^ str = gcnew String(static_cast<const char*>(strData));
}

GetData(myData(:引发写访问冲突。

我:"。 . . . . . "什么。">

  • 异常会因为某种 dll 卸载而被抛出吗?

  • 当我键入新代码时,链接过程是否有可能更改?

我以前没有遇到过这样的问题,所以我真的不知道如何调试它。

有建议吗?

谢谢。


解决。 我发现了我不确定的行为。

我想你想要这样的东西:

const DataType** myData;
GetData(&myData);
const void* strData = myData[0]->strData; 

因为在原始代码中,你只是按值传递一个指针;一个未初始化的指针,然后访问相同的未初始化值。

编辑:修复了第三行