我有一个无限循环,如果用户退出主窗口,该循环就会中断。我在循环中运行以下代码:
unsigned int* renderableShapeIndices = new unsigned int[aNumberCreatedAtRuntime];
// Do something
delete[] renderableShapeIndices;
Run Code Online (Sandbox Code Playgroud)
然后,以下情况会发生几次循环迭代,并在第一次迭代后停止发生:
1st breakpoint:
A breakpoint instruction (__debugbreak() statement or a similar call) was executed in Main.exe.
2nd breakpoint:
Unhandled exception at 0x00007FF8C3B8C729 (ntdll.dll) in InTimeEngine2D.exe: 0xC0000374: A heap has been corrupted (parameters: 0x00007FF8C3BF7780).
Run Code Online (Sandbox Code Playgroud)
还有其他人经历过类似的问题吗?我不知道发生了什么事。
另一个有趣的因素是它只发生在调试模式下。在发布模式下不会发生这种情况。
下面的代码使用文件的路径提取文件的文件名。
#include <iostream>
#include <vector>
using namespace std;
int main() {
cout << "Program operating..." << endl;
string s = "C:\\Users\\user\\Pictures\\Strategic_Offense_Logo_1";
string name;
for (unsigned int i = s.size() - 1; i > 0; i--) {
if (s[i] == '\\') {
for (unsigned int j = i + 1; j < s.size(); j++) {
if (s[j] == '.' || j == s.size() - 1) {
if (j == s.size() - 1)
j++;
vector<char> v(j - i - 1);
unsigned int …
Run Code Online (Sandbox Code Playgroud)