Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: Window refuses to draw if I don't include iostream + other issues (solved)  (Read 4490 times)

0 Members and 1 Guest are viewing this topic.

two-tone-

  • Newbie
  • *
  • Posts: 23
    • View Profile
OS: Win 7
IDE: CodeBlocks 12.11
Compiler: Defualt GCC (MinGW) for code blocks
SFML: 2.1

Well, I have two main issues.  I have a function where I set up the window and everything else called Start().  But for some reason if I don't include iostream that function is either skipped or the window is not drawn. Not sure which but I'm thinking it's the former.  Compiles just fine without iostream though

My other issue is that in Start() I have a while loop with another function in it.  Everything SFML related in that function seems to be ignored.

Compiles just fine, only run time errors are the two that I listed.


« Last Edit: September 20, 2013, 01:08:07 am by two-tone- »

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #1 on: September 17, 2013, 07:49:54 am »
For me it skips most of your code whether iostream is included or not, and the reason is fairly obvious as soon as I step through it with the debugger: gameState is never initialized, so the statement "if(gameState != Uninitialized) return;" always causes it to "return;", which makes the program exit before doing anything else.

Why not just define a constructor for the Game class instead of this weird Start() function that has to check if it's called twice?
« Last Edit: September 17, 2013, 07:51:33 am by Ixrec »

two-tone-

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #2 on: September 17, 2013, 08:11:32 am »
Actually, oops.  That was a bit of left over code that I had not realized that I did not yet remove.  However, if I keep that but still include iostream it does not return.  This is rather odd. 

I did not run a debugger on it because I have yet to learn how to debug.  I'm still learning, if it was not yet obvious ^^;.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #3 on: September 17, 2013, 08:48:25 am »
The values of uninitialized variables are essentially random, so while "odd," it's not impossible.  It's just a reminder of why not to rely on undefined behavior.

If you're new to this you should consider getting an IDE of some kind like Visual Studio or Code::Blocks, since that way you get a built-in debugger and other stuff for free.
Edit: Turns out I can't read!
« Last Edit: September 17, 2013, 09:32:42 am by Ixrec »

two-tone-

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #4 on: September 17, 2013, 08:59:36 am »
I'm already using CodeBlocks :P  My first post that started this thread states that :P

My issue is that I have no clue on how to use a debugger.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email

two-tone-

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #6 on: September 17, 2013, 09:14:23 pm »
That's a good way to start debugging in Code Blocks if you already know how. It doesn't tell you how to understand the output.

But enough of that.  My second problem still exists and I still have no idea as to why.  I know that the function is called as i can put a cout statement in it and it will print, but nothing SFML related works in there.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #7 on: September 17, 2013, 09:29:48 pm »
When I get rid of that line in start() the rest of the program does run and a window appears and everything.  It doesn't act like a normal window because there's no game loop and event loop, but the code that's actually there is doing what I would expect it to do.

I see that you've tried to simulate the game loop and event loop with these functions inside your class, but I don't think that's going to work.  I would ditch that design entirely and put those loops in main() where they belong.

two-tone-

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #8 on: September 17, 2013, 09:50:44 pm »
There is an event loop in GameLoop().  Which is the function I have been talking about.  Why would  having a nested function like that keep all the SFML things in it from working?  If I can't have nested functions while using SFML then that seems like a serious flaw in SFML.

Ixrec

  • Hero Member
  • *****
  • Posts: 1241
    • View Profile
    • Email
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #9 on: September 17, 2013, 09:55:04 pm »
Of course you can have nested functions.  I'm only referring to the game loop and event loop (which aren't even supposed to be functions, by the way).  Everything else you can have inside classes.

And requiring those two loops to be out in main isn't much of a flaw or limitation because there's almost nothing else that main() should ever be doing in a windowed program.

Kojay

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #10 on: September 17, 2013, 10:28:28 pm »
Line 9 in Game.cpp you 're creating a local mainwindow. Change it to

mainWindow.create(sf::VideoMode(800, 800), "Heros of Late - Extreme Pre Alpha");

There's nothing wrong with having the loops in class functions rather than main().


two-tone-

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #11 on: September 17, 2013, 10:46:11 pm »
Thanks for the suggestion, but still nothing happens in the window.  It SHOULD be set to red and allow me to hit Escape to close the window when in the while loop that calls GameLoop() but it just sort of hangs.

Kojay

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #12 on: September 17, 2013, 10:55:00 pm »
It is not a suggestion. Exactly what you describe happens when that line is changed - and the if statement above it commented out.
« Last Edit: September 17, 2013, 10:56:58 pm by Kojay »

two-tone-

  • Newbie
  • *
  • Posts: 23
    • View Profile
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #13 on: September 17, 2013, 11:05:25 pm »
And I'm saying that I tried that and it still does not change anything.

I can't even move the window until Windows shows that it is being unresponsive.

Kojay

  • Full Member
  • ***
  • Posts: 104
    • View Profile
Re: Window refuses to draw if I don't include iostream + other issues
« Reply #14 on: September 17, 2013, 11:07:20 pm »
Are you using the exact sources that you posted here?
Did you clean and rebuild the project?

 

anything