SFML community forums

Help => General => Topic started by: nikniknaks on June 23, 2014, 10:35:24 am

Title: SFML debugging xcode?
Post by: nikniknaks on June 23, 2014, 10:35:24 am
Hi. I just want to know how to have a debug console on xcode?

Say for example i have a code like this
void Game::handlePlayerInput(sf::Keyboard::Key key, bool isPressed){
   
    if(key == sf::Keyboard::W){
        mIsMovingUp = isPressed;

// i want to view this on a console if its working but i dont know hw
    }
}

Or like

sf::Log("Trial if it is working")

but i cant find anything
Title: Re: SFML debugging xcode?
Post by: eXpl0it3r on June 23, 2014, 11:14:11 am
You could just do:
std::cout << "This is working!" << std::endl;

Though I've no idea how xcode deals with std output.
Title: Re: SFML debugging xcode?
Post by: nikniknaks on June 23, 2014, 11:24:49 am
So basically sfml doesnt provide such a thing for debugging? I still have to use the std function?
Title: Re: SFML debugging xcode?
Post by: select_this on June 23, 2014, 11:33:40 am
Such a thing would be fairly trivial for you to implement yourself, but there's also sf:err:

http://www.sfml-dev.org/documentation/2.1/group__system.php#ga7fe7f475639e26334606b5142c29551f (http://www.sfml-dev.org/documentation/2.1/group__system.php#ga7fe7f475639e26334606b5142c29551f)
Title: Re: SFML debugging xcode?
Post by: Laurent on June 23, 2014, 12:20:43 pm
XCode shows the application output in a tab (at the bottom). So all you have to do is to output text from your app to the standard output(s), which you can access through std::cout/std::cerr/std::clog. You don't need anything at all from SFML.
Title: Re: SFML debugging xcode?
Post by: Hiura on June 23, 2014, 09:01:37 pm
I would go even further: DON'T USE LOG FOR DEBUGGING. (Yes, I really mean it.) More generally, don't EDIT code to figure out how it works.

Why?

Well, simply put: if you edit the code, you change it's behaviour and you'll end up debugging something else.

Just take this code example and add a print in the if.

int foo(bool bar)
{
    int x = 42;
    if (bar)
        x = 58;

    return 100 - x;
}
 

I hear you saying «I've only to add braces to the if and I'm good.» Yes, indeed, here it's just braces... But think of what you would end up doing in a really complex function.

Now, don't forget one more important factor: everytime you edit your code to display some log, you'll have to edit it back to remove the log in your final app. This represents a HUGE amount of work in the long term and will most probably introduce other bugs.

Insead, learn how to use your debugger. Start here (https://developer.apple.com/library/mac/documentation/IDEs/Conceptual/gdb_to_lldb_transition_guide/document/Introduction.html) or look for other tutorial.

Then you'll be able to (just to give you a few example):
all of this WITHOUT editing your code. And in a much faster way!

I have to admit that at first it's hard to use a debugger but I hope this preachy talk will convince you and hopefully motivates you to overcome the first difficulties.  ;)
Title: Re: SFML debugging xcode?
Post by: nikniknaks on June 26, 2014, 12:44:39 pm
Okay to clarify things up. the reason for this because i thought that std::cout or some function using std slows the fps down.

Like for example the LibGDX framework. I used that framework and they have their own logger. And out of curiousity i did some comparison about the system.out.print and their own logger and sysout really slows down the fps of the app if executed. It lags real bad.

Dont get me wrong here i am not comparing the two. Im just saying.

And i think since std::cout doesnt slow things down then i guest i could use that or the built in debugger of xcode.


UPDATE:
I was right using std::cout slows things down a little



But thanks guys.