-3

So I woke up today, opened my project up and tried to run it - as luck would have it, it stops before even entering the main function.

However, it worked last night, but doesn't work now. I haven't done anything to change it.

This is source.cpp:

#include <SFML/Graphics.hpp>
#include "Game.h"
#include <iostream>

using namespace std;


int main()
{
    string name;
    cout << "alupigus";

    name = "Dino Attack";

    Game game(800, 800, name);

    game.loadAssets();

    game.Run();

    return 0;
}

When I compile and run it in the console, it doesn't show anything but the black screen. I can't enter anything, and the renderwindow from SFML doesn't show up.

I'm only using SFML as an external library, but I didn't modify any links, didn't move its files, etc.

no one
  • 1,332
  • 2
  • 8
  • 10
  • 1
    Try replacing `cout << "alupigus";` with `cout << "alupigus" << endl;` – Jonas Apr 18 '17 at 09:48
  • not sure how would that help, but i modified it and it doesn't start a new line or anything – no one Apr 18 '17 at 09:51
  • 1
    Have you tried putting a breakpoint in to see how far the code actually gets? – const_ref Apr 18 '17 at 09:53
  • yeah, it stops at the main's first brace – no one Apr 18 '17 at 09:55
  • @noone and when you step forward what happens? – const_ref Apr 18 '17 at 09:56
  • nothing http://imgur.com/a/ntL0V – no one Apr 18 '17 at 10:04
  • Looks like you have to take a look at `Game` carefully. – Dean Seo Apr 18 '17 at 10:07
  • that's the thing, last night it worked perfectly, and i didn't modify anything between last night when i ran it and closed it, and today when i opened it – no one Apr 18 '17 at 10:09
  • Have you done an system update since the last execution. Maybe a part of the underlying library is broken now. I once had a similar problem with an openGl app, that broke over night and it turned out to be a driver problem, that came with an update. – OutOfBound Apr 18 '17 at 11:08
  • Create a simple program using only iostream and let us know if you have the same results. – AresCaelum Apr 18 '17 at 13:13
  • i actually do not run into any problems with other programs. additionally, i found (after 2 hours...) the one header/source that cause the problem.however, i'm simply baffled - even without including it, unless i delete it from the program completely, the source simply doesn't enter main(). it works flawlessly otherwise. I could post the code in there here, but it's too much and i dont know if the code itself is a problem, given it worked and i haven't touched it since. – no one Apr 18 '17 at 15:44
  • So it was wrong to say "stop working before entering main()", right? Also, I see no try/catch or anything like that. Programmers often don't bother to check for problems and then encounter big problems that are difficult for others to help with. Also, do you know how to look at the debug output? Also you never answered the question from @const_ref of what happens when you continue from the breakpoint. – Sam Hobbs Apr 18 '17 at 16:27

2 Answers2

1

You didn't flush stream. Your code should look like this:

#include <SFML/Graphics.hpp>
#include "Game.h"
#include <iostream>

using namespace std;


int main()
{
    string name;
    cout << "alupigus" << endl;

    name = "Dino Attack";

    Game game(800, 800, name);

    game.loadAssets();

    game.Run();

    return 0;
}

Also, consider removing using namespace std;, because this is bad practice in bigger projects. Read this

Community
  • 1
  • 1
Kamila Szewczyk
  • 1,874
  • 1
  • 16
  • 33
1

Ok so basically I solved the problem.For some reason this prevented the program from running normally, despite me not touching this area of the code for a week

x = Board::dinozaurPoz;
        x.x = rand() % 400 + 200;
        while (Board::matrix[(int)x.y / 40][(int)x.x / 40] != 1) {
            x.x = rand() % 400 + 200;

the loop wouldn't run indefinitely, so I really don't know what was the problem here. Maybe someone more experienced can advise me on what I did wrong.

no one
  • 1,332
  • 2
  • 8
  • 10