Jump to content

  • Log In with Google      Sign In   
  • Create Account


Basic Game Loop Crash


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 DeliciousThaiCosine   Members   -  Reputation: 134

Like
0Likes
Like

Posted 24 September 2013 - 02:08 AM

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;
}


Sponsor:

#2 rip-off   Moderators   -  Reputation: 8049

Like
0Likes
Like

Posted 24 September 2013 - 03:27 AM

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?



#3 DeliciousThaiCosine   Members   -  Reputation: 134

Like
0Likes
Like

Posted 24 September 2013 - 03:39 AM

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.



#4 Haytil   Members   -  Reputation: 372

Like
0Likes
Like

Posted 24 September 2013 - 09:21 AM

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.



#5 DeliciousThaiCosine   Members   -  Reputation: 134

Like
0Likes
Like

Posted 24 September 2013 - 11:41 AM

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.






Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS