我无法打开test15.bmp。当我运行该程序时,它尝试打开一个窗口,但崩溃了。据我所知,问题线是image.loadFromFile(...);
Exception thrown at 0x50E82CC4 (vcruntime140.dll) in
MandelbrotProject.exe: 0xC0000005: Access violation reading location
0x00741000.
这是我使用image.loadFromFile("test15.bmp")
而不是绝对路径时遇到的异常。
我已经链接并包含了SFML教程中描述的所有内容。 https://www.sfml-dev.org/tutorials/2.5/start-vc.php
我正在使用Visual C ++(2017)-32位SFML和Microsoft Visual Studio 2017。
#include "pch.h"
#include<iostream>
#include "Fractal.h"
#include "RGB.h"
#include "Zoom.h"
#include <SFML/Graphics.hpp>
using namespace std;
using namespace sf::Glsl;
using namespace project;
int main() {
Fractal fractal(800, 600);
fractal.addRange(0.0, RGB(0, 0, 0));
fractal.addRange(0.3, RGB(255, 0, 0));
fractal.addRange(0.5, RGB(255, 255, 0));
fractal.addRange(1.0, RGB(255, 255, 255));
fractal.addZoom(Zoom(295, 202, 0.1));
fractal.addZoom(Zoom(312, 304, 0.1));//specified zooms
fractal.run("test15.bmp");
cout << "Zooming!" << endl;
double zoom = 0.1;
double offsetX = 400.0;
double offsetY = 300.0;
sf::RenderWindow window(sf::VideoMode(800, 600), "Mandelbrot");
window.setFramerateLimit(0);
sf::Image image;
image.loadFromFile("D:\Visual Studio
projects\MandelbrotProject\MandelbrotProject\test15.bmp");
if (!image.loadFromFile("test15.bmp")) { return -1; }
sf::Texture texture;
sf::Sprite sprite;
bool stateChanged = true;
while (window.isOpen()) {
sf::Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case sf::Event::Closed:
window.close();
break;
case sf::Event::KeyPressed:
stateChanged = true;
switch (event.key.code) {
case sf::Keyboard::Escape:
stateChanged = false;
window.close();
break;
case sf::Keyboard::Equal:
zoom *= 0.9;
break;
case sf::Keyboard::Dash:
zoom /= 0.9;
break;
case sf::Keyboard::W:
offsetY -= 40 * zoom;
break;
case sf::Keyboard::S:
offsetY += 40 * zoom;
break;
case sf::Keyboard::A:
offsetX -= 40 * zoom;
break;
case sf::Keyboard::D:
offsetX += 40 * zoom;
break;
default:stateChanged = false;
break;
}
default:
break;
}
}
if (stateChanged) {
fractal.addZoom(Zoom(offsetX, offsetY, zoom));
fractal.run("test15.bmp");
texture.loadFromFile("test15.bmp");
sprite.setTexture(texture);
}
window.clear();
window.draw(sprite);
window.display();
stateChanged = false;
}
cout << "Finished!" << endl;
cin.get();
return 0;
}
答案 0 :(得分:0)
默认情况下,Visual Studio将项目目录视为工作目录。
如果我没记错,请D:\Visual Studio projects\MandelbrotProject\MandelbrotProject\
。您应该确保test15.bmp
在该目录中。
以防万一,您可以通过打开项目属性->配置属性->输出目录(可以使用任何字段)来检查您的$(ProjectDir)
是哪一个。点击下拉箭头,然后点击编辑。打开宏并输入$(ProjectDir)