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

Author Topic: SFML debugging xcode?  (Read 2521 times)

0 Members and 1 Guest are viewing this topic.

nikniknaks

  • Newbie
  • *
  • Posts: 8
    • View Profile
SFML debugging xcode?
« 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

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11030
    • View Profile
    • development blog
    • Email
Re: SFML debugging xcode?
« Reply #1 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.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

nikniknaks

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SFML debugging xcode?
« Reply #2 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?

select_this

  • Full Member
  • ***
  • Posts: 130
  • Current mood: just ate a pinecone
    • View Profile
    • darrenferrie.com
Re: SFML debugging xcode?
« Reply #3 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
Follow me on Twitter, why don'tcha? @select_this

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: SFML debugging xcode?
« Reply #4 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.
Laurent Gomila - SFML developer

Hiura

  • SFML Team
  • Hero Member
  • *****
  • Posts: 4321
    • View Profile
    • Email
Re: SFML debugging xcode?
« Reply #5 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):
  • stop your app in the if statement
  • print something (like x) in the if statement
  • print something (like x) in the if statement without breaking (here = stopping) your app
  • list variables' value
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.  ;)
SFML / OS X developer

nikniknaks

  • Newbie
  • *
  • Posts: 8
    • View Profile
Re: SFML debugging xcode?
« Reply #6 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.
« Last Edit: June 26, 2014, 01:00:02 pm by nikniknaks »

 

anything