#include "SFML\Graphics.hpp"
#include <random>
#include <ctime>
int main() {
srand(time(NULL));
sf::RenderWindow TestingWindow(sf::VideoMode(100, 100), "Testing Window");
sf::Image img;
sf::Texture txt;
sf::Sprite spr;
int x = 1, y = 1, z;
while (y < 100){
while (x < 100) {
z = rand() % 2 + 1;
if (z == 1) {
img.setPixel(x, y, sf::Color::Black);
}
else {
img.setPixel(x, y, sf::Color::Black);
}
x++;
}
x = 1; y++;
}
txt.loadFromImage(img);
spr.setTexture(txt);
while (TestingWindow.isOpen())
{
sf::Event event;
while (TestingWindow.pollEvent(event))
{
if (event.type == sf::Event::Closed)
TestingWindow.close();
}
TestingWindow.clear();
TestingWindow.draw(spr);
TestingWindow.display();
}
}
So.... I'm trying to run this program, and it should be creating a sort of fuzz you see on a faulty television, but everytime I run the program, this exception is thrown.
Unhandled exception at 0x6B8C5C98 (sfml-graphics-2.dll) in SFML 2.0 APPLICATION.exe: 0xC0000005: Access violation writing location 0x00000004.
Is there something I can do to fix this?
(And yes, I know there is a lack of comments. I'm trying to put more in my code, but I keep forgetting because I'm the only one who reads it)