F
Furtano
Gast
Hi
Visual Studio 2012 gibt mir folgende Fehlermeldung wenn ich das Programm ausführe.
Unhandled exception at 0x56B080AE (sfml-graphics-2.dll) in SDL1.exe: 0xC0000005: Access violation reading location 0x05009F0C.
Das sagt der Debugger:
Lanton.h
Langton.cpp
Ameise.cpp
Danke und LG,
Furtano
Visual Studio 2012 gibt mir folgende Fehlermeldung wenn ich das Programm ausführe.
Unhandled exception at 0x56B080AE (sfml-graphics-2.dll) in SDL1.exe: 0xC0000005: Access violation reading location 0x05009F0C.
Das sagt der Debugger:
Lanton.h
PHP:
#include "Globals.h"
#include <SFML/Graphics.hpp>
class Langton {
private:
int richtung;
int x;
int y;
int seedx;
int seedy;
int rectangleSize;
public:
bool matrix[SIZE][SIZE];
bool newMatrix[SIZE][SIZE];
Langton ();
void getNextRound();
};
Langton.cpp
PHP:
#include "Langton.h"
#include <SFML/Graphics.hpp>
#include <iostream>
Langton::Langton (){
richtung = 0;
seedx = 25;
seedy = 25;
x = 25;
y = 25;
rectangleSize = SIZE*SIZE;
for (int y = 0; y < SIZE; y++){
for (int x = 0; x < SIZE; x++){
matrix[y][x] = false;
newMatrix[y][x] = false;
}
}
matrix[seedy][seedx] = true;
newMatrix[seedy][seedx] = true;
}
void Langton::getNextRound(){
std::vector <sf::RectangleShape> grid;
// Weiß ->nach rechts 90°
do {
if (matrix[y][x] == true){
std::cout << "MEH";
richtung = ((richtung - 1) % 4);
newMatrix[y][x] = false;
}
// Schwarz -> nach links 90°
else {
richtung = ((richtung + 1) % 4);
newMatrix[y][x] = true;
}
if (richtung == 0) {
richtung=4;
y--;
}
else if (richtung == 1) {
x++;
}
else if (richtung == 2) {
y++;
}
else if (richtung == 3) {
x--;
}
memcpy(matrix, newMatrix, sizeof(matrix));
}
while ((x>=0) && (x<=SIZE) && (y>=0) && (y<=SIZE));
}
Ameise.cpp
PHP:
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <cstdlib>
#include <iostream>
#include <Windows.h>
#include "Globals.h"
#include "Langton.h"
using namespace std;
int main (){
sf::RenderWindow window(sf::VideoMode(600, 600), "My window");
float i = 0;
bool timeOver = false;
bool langtonField[SIZE][SIZE];
std::vector <sf::RectangleShape> gridhey;
int spaceCounter = 0;
sf::Clock clock;
// 1000 Quadrate anlegen
int rectangleSize = 600/SIZE;
for (int y = 0; y < 600; y = y+= rectangleSize){
for (int x = 0; x < 600; x += rectangleSize){
sf::RectangleShape shape(sf::Vector2f(rectangleSize ,rectangleSize));
shape.setFillColor(sf::Color(255,255,255));
shape.setPosition((float)x, (float)y);
shape.setOutlineThickness(1);
shape.setOutlineColor(sf::Color(0,0,0));
gridhey.push_back(shape);
}
}
cout << "SIZE : " << gridhey.size();
while (window.isOpen())
{
// clear the window with black color
window.clear(sf::Color::Black);
Langton langton;
// check all the window's events that were triggered since the last iteration of the loop
sf::Event event;
while (window.pollEvent(event))
{
// "close requested" event: we close the window
if (event.type == sf::Event::Closed)
window.close();
}
if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
sf::Time time = clock.getElapsedTime();
if (time.asSeconds() > 1) {
cout << "HEY";
langton.getNextRound();
sf::RectangleShape shape2(sf::Vector2f(50 ,50));
sf::Vector2i localPosition = sf::Mouse::getPosition(window); // window is a sf::Window
shape2.setPosition((float)localPosition.x, (float)localPosition.y);
shape2.setOutlineThickness(1);
shape2.setOutlineColor(sf::Color(0,0,0));
for (int y = 0; y < SIZE; y++){
for (int x = 0; x < SIZE; x++){
cout << langton.newMatrix[y][x];
sf::RectangleShape bla = gridhey[(((y+1)*rectangleSize)-(x+1))-1];
if (langton.newMatrix[y][x] == true){
bla.setFillColor(sf::Color(255,255,255));
}
else {
bla.setFillColor(sf::Color(0,0,0));
}
gridhey[(((y+1)*rectangleSize)-(x+1))-1] = bla;
}
}
clock.restart();
}
// left mouse button is pressed: shoot
}
// draw everything here...
for (sf::RectangleShape drawShape : gridhey){
window.draw(drawShape);
}
window.display();
// end the current frame
}
return 0;
}
Furtano
Zuletzt bearbeitet von einem Moderator: