Hello!
I'm starting to get into the feel of using pointers and attempted making a RectangleShape using them.
It worked, I was able to make it be displayed, but when I tried deleting it with a Keyboard event the Window proceeded to crash with "has stopped working"
Any reason this is happening and how to fix it?
int main() {
RenderWindow window(VideoMode(800,600), "Game");
window.setFramerateLimit(60);
RectangleShape * Obj1 = new RectangleShape(Vector2f(40, 40));
while (window.isOpen()) {
Event event;
while (window.pollEvent(event)) {
switch (event.type) {
case Event::Closed:
window.close();
case Event::KeyPressed:
if (Keyboard::isKeyPressed(Keyboard::Escape))
window.close();
else if (Keyboard::isKeyPressed(Keyboard::W))
delete Obj1;
}
}
window.clear(Color::Red);
window.draw(*Obj1);
window.display();
}
return 0;
}