Warning: file_get_contents(/data/phpspider/zhask/data//catemap/6/cplusplus/141.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/0/azure/11.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
C++ 在发布模式下崩溃,而不是在调试模式下崩溃_C++_Windows - Fatal编程技术网

C++ 在发布模式下崩溃,而不是在调试模式下崩溃

C++ 在发布模式下崩溃,而不是在调试模式下崩溃,c++,windows,C++,Windows,我正在Visual Studio Express 2013中编写一个Windows控制台应用程序。它在调试模式下编译并运行良好,但发布版本崩溃(访问冲突读取位置0xFFFFFF)。 关于stackoverflow有几个类似的问题,但似乎没有一个能解决我的问题。它们通常与未初始化变量,访问数组边界以外的元素,指针算法,或动态分配内存有关。我认为这些都不适用于这里,但我希望被证明是错的 每次删除代码并检查代码是否仍然崩溃时,我都会大幅缩减代码(原始代码在1000到2000行之间)。我似乎无法使它再小

我正在Visual Studio Express 2013中编写一个Windows控制台应用程序。它在调试模式下编译并运行良好,但发布版本崩溃(访问冲突读取位置0xFFFFFF)。 关于stackoverflow有几个类似的问题,但似乎没有一个能解决我的问题。它们通常与未初始化变量访问数组边界以外的元素指针算法,或动态分配内存有关。我认为这些都不适用于这里,但我希望被证明是错的

每次删除代码并检查代码是否仍然崩溃时,我都会大幅缩减代码(原始代码在1000到2000行之间)。我似乎无法使它再小一些,但仍然有缺陷出现。现在代码这么简单,我不知道bug在哪里。这可能是标准的C++错误(我对语言很陌生)。我不想问这样一个普通的问题,但是:

下面代码中的bug在哪里

现在,我拿出的几乎任何东西都会让虫子消失。当我禁用优化时(甚至当我优化但禁用内联时),它也会消失。 我唯一的怀疑是它可能与向量的向量(左邻域)有关

点h

#pragma once
class Point {
public:
    double x, y;
    Point(double xcoord, double ycoord);
};
#pragma once
#include "Point.h"
#include <vector>

class Diagram
{
public:
    void check_for_crossing();
    std::vector<Point> vertices;
    std::vector<std::vector<size_t>> left_neighbors;
};
Point.cpp

#include "stdafx.h"
#include "Point.h"

Point::Point(double xcoord, double ycoord) {
    x = xcoord;
    y = ycoord;
}
#include "stdafx.h"
#include "Diagram.h"

double y_coordinate_of_segment_at(const Point start, const Point end, const double x) {
    return (start.y + (x - start.x) / (end.x - start.x) * (end.y - start.y));
}

void Diagram::check_for_crossing() {
    Point end1 = Point(1.5, 0.2);
    Point end2 = Point(2.8, 3.4);

    double y1_at_min = y_coordinate_of_segment_at(Point(0.5, 0.5), end1, 0.5);
    double y2_at_min = y_coordinate_of_segment_at(Point(1.5, 0.2), end2, 0.5);

    Point intersection(0.0, 0.0);
    intersection.x = (y2_at_min - y1_at_min) / (y2_at_min); // y2_at_min is not 0
    intersection.y = y_coordinate_of_segment_at(Point(0.5, 0.5), end1, intersection.x);
    vertices.push_back(intersection);

    left_neighbors.push_back({ 0, 1 });
}
图表h

#pragma once
class Point {
public:
    double x, y;
    Point(double xcoord, double ycoord);
};
#pragma once
#include "Point.h"
#include <vector>

class Diagram
{
public:
    void check_for_crossing();
    std::vector<Point> vertices;
    std::vector<std::vector<size_t>> left_neighbors;
};
Berlin.cpp(这是主要功能所在)

#包括“stdafx.h”
#包括
#包括“h点”
#包括“图表h”
图表创建_图表(){
图表;
图.顶点.向后推(点(2.8,3.4));
返回图;
}
int _tmain(int argc,_TCHAR*argv[]
{
diag diag=创建_图();
诊断检查交叉点的位置();
返回0;
}

项目中唯一的其他文件是stdafx.hstdafx.cpp,它们用于预编译头。stdafx.cpp的内容只有#include“stdafx.h”,并且stdafx.h是空的。

您仍然可以调试发布模式,只需确保它生成一个*.pdb文件。我找不到任何内容。尝试下载Visual Studio 2015社区,看看它是否仍然在那里崩溃。您对未签名的邻居使用大小\u t。可能是您在某处将-1指定为邻居计数,并隐式地假定它是一个int吗?这可能会产生有趣的错误。选择
RelWithDebInfo
,然后点击
F5
重新编程代码的正确操作。地址为0xfffffffff的AVE通常存在对齐问题。就在这里,VS2013并不是一尘不染,更新到VS2015是明智的。最简单的解决方法是项目>属性>C/C++>代码生成>启用增强指令集=/arch:SSE