Basic Game Loop Crash

Started by
3 comments, last by DeliciousThaiCosine 10 years, 7 months ago

Basically, I crashed my computer when I ran my code.

My friend told me the reason was probably due to something about overheating my comp somehow.

Later on I ran this code on my laptop and when I opened my task manager my CPU Usage was at 100%.

So I know I'm doing something horrifically wrong, but I don't know what.

Originally the code was all in the main function and it worked fine, but only when

I rewrote the code in the game class did the program became problematic. Please help


#include <SFML/System.hpp>
#include <SFML/Window.hpp>
#include <SFML/Graphics.hpp>
#include <iostream>
#include <fstream>
#include <vector>
#include <cmath>
#include <cctype>

class Game
{
    private:
        sf::RenderWindow m_window;
        sf::Vector2u m_windowSize;
        sf::View m_mainView;
        sf::Event m_event;
        sf::Clock m_clock;

        sf::CircleShape m_Player;
    public:
        Game();
        void run();
    private:
        void getImput();
        void updateLogic();
        void renderGraphics();
};

Game::Game()
    :m_windowSize(1024, 640)
    ,m_window(sf::VideoMode(m_windowSize.x, m_windowSize.y), "Title")
    {
        m_window.setFramerateLimit(100);

        m_Player.setRadius(40.f);
        m_Player.setPosition(30.f, 30.f);
        m_Player.setFillColor(sf::Color::Cyan);
    }

void Game::run(){
    while(m_window.isOpen()){
        getImput();
        sf::sleep(sf::milliseconds(5));
        updateLogic();
        renderGraphics();
    }
}

void Game::getImput(){
    while(m_window.pollEvent(m_event)){
        switch (m_event.type){
            case sf::Event::Closed:
                m_window.close();
                break;
            case sf::Event::KeyPressed:
                if(m_event.key.code == sf::Keyboard::F4){
                    //Resize Window
                    m_windowSize.x = 800;
                    m_windowSize.y = 600;
                    // Apply possible size changes
                    m_window.setSize(sf::Vector2u(m_windowSize.x, m_windowSize.y));
                    m_mainView = sf::View(sf::FloatRect(0.f, 0.f, m_windowSize.x, m_windowSize.y));
                    m_window.setView(m_mainView);
                }
                break;
            default:
                //idk
                break;
        }
    }
}

void Game::updateLogic(){
    //Update the Logic here
}

void Game::renderGraphics(){
    m_window.clear();
    m_window.draw(m_Player);
    m_window.display();
}

int main()
{
    //Game
    Game game;
    game.run();

    return 0;
}
Advertisement

Your entire computer crashed? It should not be possible for user mode code to crash the entire machine. It is certainly either an operating system bug, or a hardware/driver issue.

Are all your drivers up to date? Are your computer's fan vents clear of dust?

Your entire computer crashed? It should not be possible for user mode code to crash the entire machine. It is certainly either an operating system bug, or a hardware/driver issue.

Are all your drivers up to date? Are your computer's fan vents clear of dust?

By crashed I meant my computer shut down. It still works perfectly fine.

Yeah all my drivers are up to date and everything.

I assume it was the program that did it because that's when it shut down.

Also my computer hasn't really had any problems before that I know of.

Sounds like your fans are clogged or you've got a lot of dust (or the temperature gauge is malfunctioning and reading as hot when it's not). Did your computer feel pretty hot to the touch when it shut down?

It probably would have happened no matter what program you were running - doing something CPU intensive like watching a movie will also accelerate the heatup/shutdown.

Sounds like your fans are clogged or you've got a lot of dust (or the temperature gauge is malfunctioning and reading as hot when it's not). Did your computer feel pretty hot to the touch when it shut down?

It probably would have happened no matter what program you were running - doing something CPU intensive like watching a movie will also accelerate the heatup/shutdown.

I didn't try touching it so I can't say.

My CPU was pretty high during the time though, so yeah.

I'll also try cleaning the inside later when I my family stops using it just to be extra safe.

I'm more interested in seeing what's wrong with my code though, assuming it doesn't work properly for anyone else.

This topic is closed to new replies.

Advertisement