我有一个VC++的问题,只是,我讨厌它哈哈。我的代码似乎在我的Mac上运行良好,但是当我尝试在VC++中运行它时,出现调试中的错误:访问冲突阅读地点
Windows在Assignment1-FINAL.exe中触发了一个断点。
这可能是由于堆损坏引起的,这表示 Assignment1-FINAL.exe或其中已加载的任何DLL的错误。
这可能也是由于用户按下了F12而 Assignment1-FINAL.exe有焦点。
我知道,所以我不知道为什么我收到了...那么我还没有按下F12一个事实,当我尝试在Release模式下运行它,我得到这个:
Assignment1-FINAL.exe中的0x00401473未处理的异常: 0xC0000005:访问冲突读取位置0x00347015。
这是我使用的代码:
int countPointsAboveThreshold(point * points, double threshold_distance) {
int i = 1;
int count = 0;
while (points[i - 1].end != true) {
point pointOne = points[i -1];
point pointTwo = points[i];
double distance = distanceBetweenTwoPoints(pointOne, pointTwo);
if (pointTwo.end == true) {
if (distance > threshold_distance) {
count++;
return count;
} else {
return count;
}
} else if (distance > threshold_distance) {
count++;
}
i++;
}
return count;
}
int totalPoints(point * points) {
int i = 0;
while (points[i].end != true) {
i++;
}
return i + 1;
}
point * findLongPaths(point * points, double threshold_distance) {
int i = 1;
int locationToStore = 0;
int pointsAboveThreshold = countPointsAboveThreshold(points, threshold_distance);
point * pointsByThreshold = new point[pointsAboveThreshold];
pointValues * pointsToCalculate = new pointValues[pointsAboveThreshold];
while (points[i - 1].end != true && i < pointsAboveThreshold) {
point pointOne = points[i - 1];
point pointTwo = points[i];
//Check to see if the distance is greater than the threshold, if it is store in an array of pointValues
double distance = distanceBetweenTwoPoints(pointOne, pointTwo);
if (distance > threshold_distance) {
pointsToCalculate[i - 1].originalLocation = i - 1;
pointsToCalculate[i - 1].distance = distance;
pointsToCalculate[i - 1].final = pointTwo;
pointsToCalculate[i - 1].stored = false;
//If the final point has been calculated, break the loop
if (pointTwo.end == true) {
pointsToCalculate[i].end = true;
break;
} else {
pointsToCalculate[i - 1].end = false;
i++;
continue;
}
}
}
if (points[0].end == true && pointsAboveThreshold == 0) {
point emptyPoint;
emptyPoint.x = 0.0;
emptyPoint.y = 0.0;
emptyPoint.end = true;
pointsByThreshold[0] = emptyPoint;
return pointsByThreshold;
}
//Find the point with the lowest distance
int j = 2;
//EDITED
pointValues pointWithLowest;
pointWithLowest = pointsToCalculate[0];
while (pointsToCalculate[j - 1].end != true) {
for (int k = 1; pointsToCalculate[k - 1].end != true; k++) {
if (pointsToCalculate[k - 1].stored == true) {
k++;
continue;
} else {
if (pointsToCalculate[k - 1].distance > pointWithLowest.distance) {
pointWithLowest = pointsToCalculate[k - 1];
k++;
continue;
} else if (pointsToCalculate[k - 1].distance == pointWithLowest.distance) {
if (pointWithLowest.originalLocation < pointsToCalculate[k - 1].originalLocation) {
pointWithLowest = pointsToCalculate[k - 1];
k++;
continue;
} else {
k++;
continue;
}
} else {
pointWithLowest.stored = true;
pointsByThreshold[locationToStore] = pointWithLowest.final;
locationToStore++;
break;
}
}
}
//DEBUGGER STOPS HERE
j++;
}
delete[] pointsToCalculate;
return pointsByThreshold;
}
这是主要的功能:
point *longest_calculated = findLongPaths(p, 1.1);
std::cout << "Should equal " << longest[1].y << ": " << longest_calculated[1].y;
delete longest_calculated;
cin.get();
return 0;
那么在代码中调试器停止了吗? – user885074
我添加了一条评论,它接近它的末尾,它是'j ++;' – Brandon
这里有很多事情要做 - 你可以发布'point'的定义吗? – Chad