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

Author Topic: [Solved] Disable SFML error messages  (Read 3335 times)

0 Members and 1 Guest are viewing this topic.

Raincode

  • Full Member
  • ***
  • Posts: 118
    • View Profile
[Solved] Disable SFML error messages
« on: January 02, 2017, 12:56:58 am »
Hi,

how can I stop SFML from writing to my console?  In my case, I would like to handle sf::UdpSocket::bind() failing in my own way by using another Port.  However, SFML always prints an error message to my console, which I do not want in this case.
« Last Edit: January 02, 2017, 05:58:26 pm by Raincode »

Laurent

  • Administrator
  • Hero Member
  • *****
  • Posts: 32498
    • View Profile
    • SFML's website
    • Email
Re: Disable SFML error messages
« Reply #1 on: January 02, 2017, 08:39:52 am »
SFML prints to sf::err(), which you can redirect to something else than the console or even nothing. It's a standard std::ostream, so I let you Google (or search this forum) to find how to do it ;)
Laurent Gomila - SFML developer

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: Disable SFML error messages
« Reply #2 on: January 02, 2017, 02:01:16 pm »
My Plinth class that does this ;D
Simply create a temporary object of this class during the activity that insists on outputting to the error stream. It automatically resumes where it was when the object is destroyed ;)

#include <Plinth/Sfml/ErrBlocker.hpp>
int main()
{
    // stuff before (errors are output as normal)
    {
        pl::Sfml::ErrBlocker sfmlErrBlocker;
        // stuff while errors are blocked
    }
    // stuff after (errors are output as normal)
}
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Raincode

  • Full Member
  • ***
  • Posts: 118
    • View Profile
Re: Disable SFML error messages
« Reply #3 on: January 02, 2017, 05:58:17 pm »
Hello,

thank you for your replies, I have a much better grasp of the SFML error printing now and the tools necessary to change it for my needs.

The premade class also works nicely, thank you.

 

anything