From 76de05af611580c66be1f7e02fd933f0f3b641b8 Mon Sep 17 00:00:00 2001 From: LaurentGom Date: Mon, 22 Feb 2010 11:30:43 +0000 Subject: [PATCH] FS#150 - SFML should use its own stream instead of std::cerr, for reporting errors git-svn-id: https://sfml.svn.sourceforge.net/svnroot/sfml/branches/sfml2@1417 4e206d99-4929-0410-ac5d-dfc041789085 --- build/vc2008/sfml-system.vcproj | 8 ++ include/SFML/System.hpp | 1 + include/SFML/System/Err.hpp | 77 +++++++++++++ src/SFML/Audio/ALCheck.cpp | 9 +- src/SFML/Audio/AudioDevice.cpp | 6 +- src/SFML/Audio/Music.cpp | 6 +- src/SFML/Audio/SoundBuffer.cpp | 16 +-- src/SFML/Audio/SoundFile.cpp | 10 +- src/SFML/Audio/SoundRecorder.cpp | 8 +- src/SFML/Audio/SoundStream.cpp | 5 +- src/SFML/Graphics/Font.cpp | 16 +-- src/SFML/Graphics/GLCheck.cpp | 10 +- src/SFML/Graphics/Image.cpp | 22 ++-- src/SFML/Graphics/ImageLoader.cpp | 20 ++-- .../Graphics/Linux/RenderImageImplPBuffer.cpp | 16 +-- src/SFML/Graphics/RenderImage.cpp | 6 +- src/SFML/Graphics/RenderImageImplFBO.cpp | 8 +- src/SFML/Graphics/Shader.cpp | 32 ++--- .../Graphics/Win32/RenderImageImplPBuffer.cpp | 14 +-- src/SFML/Network/SocketTCP.cpp | 20 ++-- src/SFML/Network/SocketUDP.cpp | 18 +-- src/SFML/System/Err.cpp | 109 ++++++++++++++++++ src/SFML/System/Win32/ThreadImpl.cpp | 4 +- src/SFML/Window/Linux/ContextGLX.cpp | 10 +- src/SFML/Window/Linux/VideoModeSupport.cpp | 14 +-- src/SFML/Window/Linux/WindowImplX11.cpp | 14 +-- src/SFML/Window/Win32/ContextWGL.cpp | 12 +- src/SFML/Window/Win32/WindowImplWin32.cpp | 6 +- src/SFML/Window/Window.cpp | 8 +- 29 files changed, 351 insertions(+), 154 deletions(-) create mode 100644 include/SFML/System/Err.hpp create mode 100644 src/SFML/System/Err.cpp diff --git a/build/vc2008/sfml-system.vcproj b/build/vc2008/sfml-system.vcproj index cb0d42ec..6f500871 100644 --- a/build/vc2008/sfml-system.vcproj +++ b/build/vc2008/sfml-system.vcproj @@ -379,6 +379,14 @@ RelativePath="..\..\include\SFML\System\Clock.hpp" > + + + + diff --git a/include/SFML/System.hpp b/include/SFML/System.hpp index 59837354..02e3b69f 100644 --- a/include/SFML/System.hpp +++ b/include/SFML/System.hpp @@ -31,6 +31,7 @@ #include #include +#include #include #include #include diff --git a/include/SFML/System/Err.hpp b/include/SFML/System/Err.hpp new file mode 100644 index 00000000..d294dcd9 --- /dev/null +++ b/include/SFML/System/Err.hpp @@ -0,0 +1,77 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +#ifndef SFML_ERR_HPP +#define SFML_ERR_HPP + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +namespace sf +{ +//////////////////////////////////////////////////////////// +/// \brief Standard stream used by SFML to output warnings and errors +/// +//////////////////////////////////////////////////////////// +SFML_API std::ostream& Err(); + +} // namespace sf + + +#endif // SFML_ERR_HPP + + +//////////////////////////////////////////////////////////// +/// \fn sf::Err +/// +/// By default, sf::Err() outputs to the same location as std::cerr, +/// (-> the stderr descriptor) which is the console if there's +/// one available. +/// +/// It is a standard std::ostream instance, so it supports all the +/// insertion operations defined by the STL +/// (operator <<, manipulators, etc.). +/// +/// sf::Err() can be redirected to write to another output, independantly +/// of std::cerr, by using the rdbuf() function provided by the +/// std::ostream class. +/// +/// Example: +/// \code +/// // Redirect to a file +/// std::ofstream file("sfml-log.txt"); +/// std::streambuf* previous = sf::Err().rdbuf(file.rdbuf()); +/// +/// // Redirect to nothing +/// sf::Err().rdbuf(NULL); +/// +/// // Restore the original output +/// sf::Err().rdbuf(previous); +/// \endcode +/// +//////////////////////////////////////////////////////////// diff --git a/src/SFML/Audio/ALCheck.cpp b/src/SFML/Audio/ALCheck.cpp index 0572abf5..ef764eff 100644 --- a/src/SFML/Audio/ALCheck.cpp +++ b/src/SFML/Audio/ALCheck.cpp @@ -27,6 +27,7 @@ //////////////////////////////////////////////////////////// #include #include +#include namespace sf @@ -83,10 +84,10 @@ void ALCheckError(const std::string& file, unsigned int line) } // Log the error - std::cerr << "An internal OpenAL call failed in " - << file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : " - << error << ", " << description - << std::endl; + Err() << "An internal OpenAL call failed in " + << file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : " + << error << ", " << description + << std::endl; } } diff --git a/src/SFML/Audio/AudioDevice.cpp b/src/SFML/Audio/AudioDevice.cpp index f29d1410..2e7bccf2 100644 --- a/src/SFML/Audio/AudioDevice.cpp +++ b/src/SFML/Audio/AudioDevice.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include //////////////////////////////////////////////////////////// @@ -62,12 +62,12 @@ AudioDevice::AudioDevice() } else { - std::cerr << "Failed to create the audio context" << std::endl; + Err() << "Failed to create the audio context" << std::endl; } } else { - std::cerr << "Failed to open the audio device" << std::endl; + Err() << "Failed to open the audio device" << std::endl; } } diff --git a/src/SFML/Audio/Music.cpp b/src/SFML/Audio/Music.cpp index 9b71a8af..8ec0deb4 100644 --- a/src/SFML/Audio/Music.cpp +++ b/src/SFML/Audio/Music.cpp @@ -29,8 +29,8 @@ #include #include #include +#include #include -#include namespace sf @@ -63,7 +63,7 @@ bool Music::OpenFromFile(const std::string& filename) // Create the sound file implementation, and open it in read mode if (!myFile->OpenRead(filename)) { - std::cerr << "Failed to open \"" << filename << "\" for reading" << std::endl; + Err() << "Failed to open \"" << filename << "\" for reading" << std::endl; return false; } @@ -89,7 +89,7 @@ bool Music::OpenFromMemory(const void* data, std::size_t sizeInBytes) // Create the sound file implementation, and open it in read mode if (!myFile->OpenRead(data, sizeInBytes)) { - std::cerr << "Failed to open music from memory for reading" << std::endl; + Err() << "Failed to open music from memory for reading" << std::endl; return false; } diff --git a/src/SFML/Audio/SoundBuffer.cpp b/src/SFML/Audio/SoundBuffer.cpp index d2415dcd..2b3a0f2b 100644 --- a/src/SFML/Audio/SoundBuffer.cpp +++ b/src/SFML/Audio/SoundBuffer.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include #include @@ -152,12 +152,12 @@ bool SoundBuffer::LoadFromSamples(const Int16* samples, std::size_t samplesCount else { // Error... - std::cerr << "Failed to load sound buffer from memory (" - << "Samples : " << samples << ", " - << "Samples count : " << samplesCount << ", " - << "Channels count : " << channelsCount << ", " - << "Sample rate : " << sampleRate << ")" - << std::endl; + Err() << "Failed to load sound buffer from memory (" + << "Samples : " << samples << ", " + << "Samples count : " << samplesCount << ", " + << "Channels count : " << channelsCount << ", " + << "Sample rate : " << sampleRate << ")" + << std::endl; return false; } @@ -251,7 +251,7 @@ bool SoundBuffer::Update(unsigned int channelsCount, unsigned int sampleRate) // Check if the format is valid if (format == 0) { - std::cerr << "Unsupported number of channels (" << channelsCount << ")" << std::endl; + Err() << "Unsupported number of channels (" << channelsCount << ")" << std::endl; return false; } diff --git a/src/SFML/Audio/SoundFile.cpp b/src/SFML/Audio/SoundFile.cpp index 5b1b462a..9a91c08e 100644 --- a/src/SFML/Audio/SoundFile.cpp +++ b/src/SFML/Audio/SoundFile.cpp @@ -26,7 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include #include @@ -86,7 +86,7 @@ bool SoundFile::OpenRead(const std::string& filename) myFile = sf_open(filename.c_str(), SFM_READ, &fileInfos); if (!myFile) { - std::cerr << "Failed to read sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl; + Err() << "Failed to read sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl; return false; } @@ -114,7 +114,7 @@ bool SoundFile::OpenRead(const void* data, std::size_t sizeInBytes) myFile = sf_open_virtual(&io, SFM_READ, &fileInfos, &myMemoryIO); if (!myFile) { - std::cerr << "Failed to read sound file from memory (" << sf_strerror(myFile) << ")" << std::endl; + Err() << "Failed to read sound file from memory (" << sf_strerror(myFile) << ")" << std::endl; return false; } @@ -139,7 +139,7 @@ bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelsCoun if (format == -1) { // Error : unrecognized extension - std::cerr << "Failed to create sound file \"" << filename << "\" (unknown format)" << std::endl; + Err() << "Failed to create sound file \"" << filename << "\" (unknown format)" << std::endl; return false; } @@ -153,7 +153,7 @@ bool SoundFile::OpenWrite(const std::string& filename, unsigned int channelsCoun myFile = sf_open(filename.c_str(), SFM_WRITE, &fileInfos); if (!myFile) { - std::cerr << "Failed to create sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl; + Err() << "Failed to create sound file \"" << filename << "\" (" << sf_strerror(myFile) << ")" << std::endl; return false; } diff --git a/src/SFML/Audio/SoundRecorder.cpp b/src/SFML/Audio/SoundRecorder.cpp index 670abfe3..295c2f49 100644 --- a/src/SFML/Audio/SoundRecorder.cpp +++ b/src/SFML/Audio/SoundRecorder.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include //////////////////////////////////////////////////////////// @@ -64,14 +64,14 @@ void SoundRecorder::Start(unsigned int sampleRate) // Check if the device can do audio capture if (!IsAvailable()) { - std::cerr << "Failed to start capture : your system cannot capture audio data (call SoundRecorder::CanCapture to check it)" << std::endl; + Err() << "Failed to start capture : your system cannot capture audio data (call SoundRecorder::CanCapture to check it)" << std::endl; return; } // Check that another capture is not already running if (captureDevice) { - std::cerr << "Trying to start audio capture, but another capture is already running" << std::endl; + Err() << "Trying to start audio capture, but another capture is already running" << std::endl; return; } @@ -79,7 +79,7 @@ void SoundRecorder::Start(unsigned int sampleRate) captureDevice = alcCaptureOpenDevice(NULL, sampleRate, AL_FORMAT_MONO16, sampleRate); if (!captureDevice) { - std::cerr << "Failed to open the audio capture device" << std::endl; + Err() << "Failed to open the audio capture device" << std::endl; return; } diff --git a/src/SFML/Audio/SoundStream.cpp b/src/SFML/Audio/SoundStream.cpp index 885148ce..abcc6917 100644 --- a/src/SFML/Audio/SoundStream.cpp +++ b/src/SFML/Audio/SoundStream.cpp @@ -29,6 +29,7 @@ #include #include #include +#include namespace sf @@ -68,7 +69,7 @@ void SoundStream::Initialize(unsigned int channelsCount, unsigned int sampleRate { myChannelsCount = 0; mySampleRate = 0; - std::cerr << "Unsupported number of channels (" << myChannelsCount << ")" << std::endl; + Err() << "Unsupported number of channels (" << myChannelsCount << ")" << std::endl; } } @@ -79,7 +80,7 @@ void SoundStream::Play() // Check if the sound parameters have been set if (myFormat == 0) { - std::cerr << "Failed to play audio stream: sound parameters have not been initialized (call Initialize first)" << std::endl; + Err() << "Failed to play audio stream: sound parameters have not been initialized (call Initialize first)" << std::endl; return; } diff --git a/src/SFML/Graphics/Font.cpp b/src/SFML/Graphics/Font.cpp index 5d7c2477..dc465277 100644 --- a/src/SFML/Graphics/Font.cpp +++ b/src/SFML/Graphics/Font.cpp @@ -26,12 +26,12 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include FT_FREETYPE_H #include FT_GLYPH_H #include FT_OUTLINE_H #include FT_BITMAP_H -#include namespace sf @@ -84,7 +84,7 @@ bool Font::LoadFromFile(const std::string& filename) FT_Library library; if (FT_Init_FreeType(&library) != 0) { - std::cerr << "Failed to load font \"" << filename << "\" (failed to initialize FreeType)" << std::endl; + Err() << "Failed to load font \"" << filename << "\" (failed to initialize FreeType)" << std::endl; return false; } myLibrary = library; @@ -93,14 +93,14 @@ bool Font::LoadFromFile(const std::string& filename) FT_Face face; if (FT_New_Face(static_cast(myLibrary), filename.c_str(), 0, &face) != 0) { - std::cerr << "Failed to load font \"" << filename << "\" (failed to create the font face)" << std::endl; + Err() << "Failed to load font \"" << filename << "\" (failed to create the font face)" << std::endl; return false; } // Select the unicode character map if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0) { - std::cerr << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl; + Err() << "Failed to load font \"" << filename << "\" (failed to set the Unicode character set)" << std::endl; return false; } @@ -124,7 +124,7 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes) FT_Library library; if (FT_Init_FreeType(&library) != 0) { - std::cerr << "Failed to load font from memory (failed to initialize FreeType)" << std::endl; + Err() << "Failed to load font from memory (failed to initialize FreeType)" << std::endl; return false; } myLibrary = library; @@ -133,14 +133,14 @@ bool Font::LoadFromMemory(const void* data, std::size_t sizeInBytes) FT_Face face; if (FT_New_Memory_Face(static_cast(myLibrary), reinterpret_cast(data), static_cast(sizeInBytes), 0, &face) != 0) { - std::cerr << "Failed to load font from memory (failed to create the font face)" << std::endl; + Err() << "Failed to load font from memory (failed to create the font face)" << std::endl; return false; } // Select the unicode character map if (FT_Select_Charmap(face, FT_ENCODING_UNICODE) != 0) { - std::cerr << "Failed to load font from memory (failed to set the Unicode character set)" << std::endl; + Err() << "Failed to load font from memory (failed to set the Unicode character set)" << std::endl; return false; } @@ -460,7 +460,7 @@ IntRect Font::FindGlyphRect(Page& page, unsigned int width, unsigned int height) else { // Oops, we've reached the maximum texture size... - std::cerr << "Failed to add a new character to the font: the maximum image size has been reached" << std::endl; + Err() << "Failed to add a new character to the font: the maximum image size has been reached" << std::endl; return IntRect(0, 0, 2, 2); } } diff --git a/src/SFML/Graphics/GLCheck.cpp b/src/SFML/Graphics/GLCheck.cpp index db3fa328..6016d234 100644 --- a/src/SFML/Graphics/GLCheck.cpp +++ b/src/SFML/Graphics/GLCheck.cpp @@ -26,7 +26,7 @@ // Headers //////////////////////////////////////////////////////////// #include -#include +#include namespace sf @@ -100,10 +100,10 @@ void GLCheckError(const std::string& file, unsigned int line) } // Log the error - std::cerr << "An internal OpenGL call failed in " - << file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : " - << error << ", " << description - << std::endl; + Err() << "An internal OpenGL call failed in " + << file.substr(file.find_last_of("\\/") + 1) << " (" << line << ") : " + << error << ", " << description + << std::endl; } } diff --git a/src/SFML/Graphics/Image.cpp b/src/SFML/Graphics/Image.cpp index 81983420..9a42017b 100644 --- a/src/SFML/Graphics/Image.cpp +++ b/src/SFML/Graphics/Image.cpp @@ -30,8 +30,8 @@ #include #include #include +#include #include -#include #include #include @@ -121,7 +121,7 @@ bool Image::LoadFromMemory(const void* data, std::size_t sizeInBytes) // Check parameters if (!data || (sizeInBytes == 0)) { - std::cerr << "Failed to image font from memory, no data provided" << std::endl; + Err() << "Failed to image font from memory, no data provided" << std::endl; return false; } @@ -389,8 +389,8 @@ void Image::SetPixel(unsigned int x, unsigned int y, const Color& color) // Check if pixel is whithin the image bounds if ((x >= myWidth) || (y >= myHeight)) { - std::cerr << "Cannot set pixel (" << x << "," << y << ") for image " - << "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl; + Err() << "Cannot set pixel (" << x << "," << y << ") for image " + << "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl; return; } @@ -412,8 +412,8 @@ const Color& Image::GetPixel(unsigned int x, unsigned int y) const // Check if pixel is whithin the image bounds if ((x >= myWidth) || (y >= myHeight)) { - std::cerr << "Cannot get pixel (" << x << "," << y << ") for image " - << "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl; + Err() << "Cannot get pixel (" << x << "," << y << ") for image " + << "(width = " << myWidth << ", height = " << myHeight << ")" << std::endl; return Color::Black; } @@ -437,7 +437,7 @@ const Uint8* Image::GetPixelsPtr() const } else { - std::cerr << "Trying to access the pixels of an empty image" << std::endl; + Err() << "Trying to access the pixels of an empty image" << std::endl; return NULL; } } @@ -661,10 +661,10 @@ bool Image::CreateTexture() unsigned int maxSize = GetMaximumSize(); if ((myTextureWidth > maxSize) || (myTextureHeight > maxSize)) { - std::cerr << "Failed to create image, its internal size is too high " - << "(" << myTextureWidth << "x" << myTextureHeight << ", " - << "maximum is " << maxSize << "x" << maxSize << ")" - << std::endl; + Err() << "Failed to create image, its internal size is too high " + << "(" << myTextureWidth << "x" << myTextureHeight << ", " + << "maximum is " << maxSize << "x" << maxSize << ")" + << std::endl; return false; } diff --git a/src/SFML/Graphics/ImageLoader.cpp b/src/SFML/Graphics/ImageLoader.cpp index d0d49c7e..508f9970 100644 --- a/src/SFML/Graphics/ImageLoader.cpp +++ b/src/SFML/Graphics/ImageLoader.cpp @@ -33,7 +33,7 @@ extern "C" } #include #include -#include +#include namespace @@ -43,7 +43,7 @@ namespace //////////////////////////////////////////////////////////// void PngErrorHandler(png_structp png, png_const_charp message) { - std::cerr << "Failed to write PNG image. Reason : " << message << std::endl; + sf::Err() << "Failed to write PNG image. Reason : " << message << std::endl; longjmp(png->jmpbuf, 1); } } @@ -112,7 +112,7 @@ bool ImageLoader::LoadImageFromFile(const std::string& filename, std::vector(width), static_cast(height), 4, ptr)) { // Error, failed to save the image - std::cerr << "Failed to save image \"" << filename << "\". Reason: " << SOIL_last_result() << std::endl; + Err() << "Failed to save image \"" << filename << "\". Reason: " << SOIL_last_result() << std::endl; return false; } @@ -206,7 +206,7 @@ bool ImageLoader::WriteJpg(const std::string& filename, const std::vector FILE* file = fopen(filename.c_str(), "wb"); if (!file) { - std::cerr << "Failed to save image file \"" << filename << "\". Reason : cannot open file" << std::endl; + Err() << "Failed to save image file \"" << filename << "\". Reason : cannot open file" << std::endl; return false; } @@ -265,7 +265,7 @@ bool ImageLoader::WritePng(const std::string& filename, const std::vector FILE* file = fopen(filename.c_str(), "wb"); if (!file) { - std::cerr << "Failed to save image file \"" << filename << "\". Reason : cannot open file" << std::endl; + Err() << "Failed to save image file \"" << filename << "\". Reason : cannot open file" << std::endl; return false; } @@ -274,7 +274,7 @@ bool ImageLoader::WritePng(const std::string& filename, const std::vector if (!png) { fclose(file); - std::cerr << "Failed to save image file \"" << filename << "\". Reason : cannot allocate PNG write structure" << std::endl; + Err() << "Failed to save image file \"" << filename << "\". Reason : cannot allocate PNG write structure" << std::endl; return false; } @@ -284,7 +284,7 @@ bool ImageLoader::WritePng(const std::string& filename, const std::vector { fclose(file); png_destroy_write_struct(&png, NULL); - std::cerr << "Failed to save image file \"" << filename << "\". Reason : cannot allocate PNG info structure" << std::endl; + Err() << "Failed to save image file \"" << filename << "\". Reason : cannot allocate PNG info structure" << std::endl; return false; } diff --git a/src/SFML/Graphics/Linux/RenderImageImplPBuffer.cpp b/src/SFML/Graphics/Linux/RenderImageImplPBuffer.cpp index 8d255bd6..652d61b1 100644 --- a/src/SFML/Graphics/Linux/RenderImageImplPBuffer.cpp +++ b/src/SFML/Graphics/Linux/RenderImageImplPBuffer.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace sf @@ -112,7 +112,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns GLXFBConfig* configs = glXChooseFBConfigSGIX(myDisplay, DefaultScreen(myDisplay), visualAttributes, &nbConfigs); if (!configs || !nbConfigs) { - std::cerr << "Impossible to create render image (failed to find a suitable pixel format for PBuffer)" << std::endl; + Err() << "Impossible to create render image (failed to find a suitable pixel format for PBuffer)" << std::endl; return false; } @@ -120,7 +120,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns myPBuffer = glXCreateGLXPbufferSGIX(myDisplay, configs[0], width, height, PBufferAttributes); if (!myPBuffer) { - std::cerr << "Impossible to create render image (failed to create the OpenGL PBuffer)" << std::endl; + Err() << "Impossible to create render image (failed to create the OpenGL PBuffer)" << std::endl; XFree(configs); return false; } @@ -131,10 +131,10 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns glXQueryGLXPbufferSGIX(myDisplay, myPBuffer, GLX_HEIGHT_SGIX, &actualHeight); if ((actualWidth != width) || (actualHeight != height)) { - std::cerr << "Impossible to create render image (failed to match the requested size). " - << "Size: " << actualWidth << "x" << actualHeight << " - " - << "Requested: " << width << "x" << height - << std::endl; + Err() << "Impossible to create render image (failed to match the requested size). " + << "Size: " << actualWidth << "x" << actualHeight << " - " + << "Requested: " << width << "x" << height + << std::endl; XFree(configs); return false; } @@ -150,7 +150,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns myContext = glXCreateContext(myDisplay, visual, currentContext, true); if (!myContext) { - std::cerr << "Impossible to create render image (failed to create the OpenGL context)" << std::endl; + Err() << "Impossible to create render image (failed to create the OpenGL context)" << std::endl; XFree(configs); XFree(visual); return false; diff --git a/src/SFML/Graphics/RenderImage.cpp b/src/SFML/Graphics/RenderImage.cpp index 997c83bf..b2a5ed64 100644 --- a/src/SFML/Graphics/RenderImage.cpp +++ b/src/SFML/Graphics/RenderImage.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace sf @@ -54,14 +54,14 @@ bool RenderImage::Create(unsigned int width, unsigned int height, bool depthBuff // Make sure that render-images are supported if (!IsAvailable()) { - std::cerr << "Impossible to create render image (your system doesn't support this feature)" << std::endl; + Err() << "Impossible to create render image (your system doesn't support this feature)" << std::endl; return false; } // Create the image if (!myImage.Create(width, height)) { - std::cerr << "Impossible to create render image (failed to create the target image)" << std::endl; + Err() << "Impossible to create render image (failed to create the target image)" << std::endl; return false; } diff --git a/src/SFML/Graphics/RenderImageImplFBO.cpp b/src/SFML/Graphics/RenderImageImplFBO.cpp index d38bc072..12d7ca21 100644 --- a/src/SFML/Graphics/RenderImageImplFBO.cpp +++ b/src/SFML/Graphics/RenderImageImplFBO.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace sf @@ -90,7 +90,7 @@ bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigne myFrameBuffer = static_cast(frameBuffer); if (!myFrameBuffer) { - std::cerr << "Impossible to create render image (failed to create the frame buffer object)" << std::endl; + Err() << "Impossible to create render image (failed to create the frame buffer object)" << std::endl; return false; } GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, myFrameBuffer)); @@ -103,7 +103,7 @@ bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigne myDepthBuffer = static_cast(depth); if (!myDepthBuffer) { - std::cerr << "Impossible to create render image (failed to create the attached depth buffer)" << std::endl; + Err() << "Impossible to create render image (failed to create the attached depth buffer)" << std::endl; return false; } GLCheck(glBindRenderbufferEXT(GL_RENDERBUFFER_EXT, myDepthBuffer)); @@ -118,7 +118,7 @@ bool RenderImageImplFBO::Create(unsigned int width, unsigned int height, unsigne if (glCheckFramebufferStatusEXT(GL_FRAMEBUFFER_EXT) != GL_FRAMEBUFFER_COMPLETE_EXT) { GLCheck(glBindFramebufferEXT(GL_FRAMEBUFFER_EXT, 0)); - std::cerr << "Impossible to create render image (failed to link the target image to the frame buffer)" << std::endl; + Err() << "Impossible to create render image (failed to link the target image to the frame buffer)" << std::endl; return false; } diff --git a/src/SFML/Graphics/Shader.cpp b/src/SFML/Graphics/Shader.cpp index 6a791a4f..d2dd6c16 100644 --- a/src/SFML/Graphics/Shader.cpp +++ b/src/SFML/Graphics/Shader.cpp @@ -28,8 +28,8 @@ //////////////////////////////////////////////////////////// #include #include +#include #include -#include #include @@ -79,7 +79,7 @@ bool Shader::LoadFromFile(const std::string& filename) std::ifstream file(filename.c_str()); if (!file) { - std::cerr << "Failed to open shader file \"" << filename << "\"" << std::endl; + Err() << "Failed to open shader file \"" << filename << "\"" << std::endl; return false; } @@ -118,7 +118,7 @@ void Shader::SetParameter(const std::string& name, float x) if (location != -1) GLCheck(glUniform1fARB(location, x)); else - std::cerr << "Parameter \"" << name << "\" not found in shader" << std::endl; + Err() << "Parameter \"" << name << "\" not found in shader" << std::endl; // Disable program GLCheck(glUseProgramObjectARB(program)); @@ -140,7 +140,7 @@ void Shader::SetParameter(const std::string& name, float x, float y) if (location != -1) GLCheck(glUniform2fARB(location, x, y)); else - std::cerr << "Parameter \"" << name << "\" not found in shader" << std::endl; + Err() << "Parameter \"" << name << "\" not found in shader" << std::endl; // Disable program GLCheck(glUseProgramObjectARB(program)); @@ -162,7 +162,7 @@ void Shader::SetParameter(const std::string& name, float x, float y, float z) if (location != -1) GLCheck(glUniform3fARB(location, x, y, z)); else - std::cerr << "Parameter \"" << name << "\" not found in shader" << std::endl; + Err() << "Parameter \"" << name << "\" not found in shader" << std::endl; // Disable program GLCheck(glUseProgramObjectARB(program)); @@ -184,7 +184,7 @@ void Shader::SetParameter(const std::string& name, float x, float y, float z, fl if (location != -1) GLCheck(glUniform4fARB(location, x, y, z, w)); else - std::cerr << "Parameter \"" << name << "\" not found in shader" << std::endl; + Err() << "Parameter \"" << name << "\" not found in shader" << std::endl; // Disable program GLCheck(glUseProgramObjectARB(program)); @@ -214,7 +214,7 @@ void Shader::SetTexture(const std::string& name, const Image& texture) GLCheck(glGetIntegerv(GL_MAX_TEXTURE_COORDS_ARB, &maxUnits)); if (myTextures.size() + 1 >= static_cast(maxUnits)) { - std::cerr << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl; + Err() << "Impossible to use texture \"" << name << "\" for shader: all available texture units are used" << std::endl; return; } @@ -222,7 +222,7 @@ void Shader::SetTexture(const std::string& name, const Image& texture) int location = glGetUniformLocationARB(myShaderProgram, name.c_str()); if (location == -1) { - std::cerr << "Texture \"" << name << "\" not found in shader" << std::endl; + Err() << "Texture \"" << name << "\" not found in shader" << std::endl; return; } @@ -321,8 +321,8 @@ bool Shader::CompileProgram() // First make sure that we can use shaders if (!IsAvailable()) { - std::cerr << "Failed to create a shader: your system doesn't support shaders " - << "(you should test Shader::IsAvailable() before trying to use the Shader class)" << std::endl; + Err() << "Failed to create a shader: your system doesn't support shaders " + << "(you should test Shader::IsAvailable() before trying to use the Shader class)" << std::endl; return false; } @@ -360,8 +360,8 @@ bool Shader::CompileProgram() { char log[1024]; GLCheck(glGetInfoLogARB(vertexShader, sizeof(log), 0, log)); - std::cerr << "Failed to compile shader:" << std::endl - << log << std::endl; + Err() << "Failed to compile shader:" << std::endl + << log << std::endl; GLCheck(glDeleteObjectARB(vertexShader)); GLCheck(glDeleteObjectARB(fragmentShader)); GLCheck(glDeleteObjectARB(myShaderProgram)); @@ -373,8 +373,8 @@ bool Shader::CompileProgram() { char log[1024]; GLCheck(glGetInfoLogARB(fragmentShader, sizeof(log), 0, log)); - std::cerr << "Failed to compile shader:" << std::endl - << log << std::endl; + Err() << "Failed to compile shader:" << std::endl + << log << std::endl; GLCheck(glDeleteObjectARB(vertexShader)); GLCheck(glDeleteObjectARB(fragmentShader)); GLCheck(glDeleteObjectARB(myShaderProgram)); @@ -400,8 +400,8 @@ bool Shader::CompileProgram() // Oops... link errors char log[1024]; GLCheck(glGetInfoLogARB(myShaderProgram, sizeof(log), 0, log)); - std::cerr << "Failed to link shader:" << std::endl - << log << std::endl; + Err() << "Failed to link shader:" << std::endl + << log << std::endl; GLCheck(glDeleteObjectARB(myShaderProgram)); myShaderProgram = 0; return false; diff --git a/src/SFML/Graphics/Win32/RenderImageImplPBuffer.cpp b/src/SFML/Graphics/Win32/RenderImageImplPBuffer.cpp index 5ef3ffc9..62981856 100644 --- a/src/SFML/Graphics/Win32/RenderImageImplPBuffer.cpp +++ b/src/SFML/Graphics/Win32/RenderImageImplPBuffer.cpp @@ -28,7 +28,7 @@ #include #include #include -#include +#include namespace sf @@ -117,7 +117,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns // Make sure that one pixel format has been found if (nbFormats == 0) { - std::cerr << "Impossible to create render image (failed to find a suitable pixel format for PBuffer)" << std::endl; + Err() << "Impossible to create render image (failed to find a suitable pixel format for PBuffer)" << std::endl; return false; } @@ -129,7 +129,7 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns // Check errors if (!myPBuffer || !myDeviceContext || !myContext) { - std::cerr << "Impossible to create render image (failed to create PBuffer)" << std::endl; + Err() << "Impossible to create render image (failed to create PBuffer)" << std::endl; return false; } @@ -139,10 +139,10 @@ bool RenderImageImplPBuffer::Create(unsigned int width, unsigned int height, uns wglQueryPbufferARB(myPBuffer, WGL_PBUFFER_HEIGHT_ARB, &actualHeight); if ((actualWidth != static_cast(width)) || (actualHeight != static_cast(height))) { - std::cerr << "Impossible to create render image (failed to match the requested size). " - << "Size: " << actualWidth << "x" << actualHeight << " - " - << "Requested: " << width << "x" << height - << std::endl; + Err() << "Impossible to create render image (failed to match the requested size). " + << "Size: " << actualWidth << "x" << actualHeight << " - " + << "Requested: " << width << "x" << height + << std::endl; return false; } diff --git a/src/SFML/Network/SocketTCP.cpp b/src/SFML/Network/SocketTCP.cpp index e40c9244..cc50d751 100644 --- a/src/SFML/Network/SocketTCP.cpp +++ b/src/SFML/Network/SocketTCP.cpp @@ -29,8 +29,8 @@ #include #include #include +#include #include -#include #include @@ -183,7 +183,7 @@ bool SocketTCP::Listen(unsigned short port) if (bind(mySocket, reinterpret_cast(&sockAddr), sizeof(sockAddr)) == -1) { // Not likely to happen, but... - std::cerr << "Failed to bind socket to port " << port << std::endl; + Err() << "Failed to bind socket to port " << port << std::endl; return false; } @@ -191,7 +191,7 @@ bool SocketTCP::Listen(unsigned short port) if (listen(mySocket, 0) == -1) { // Oops, socket is deaf - std::cerr << "Failed to listen to port " << port << std::endl; + Err() << "Failed to listen to port " << port << std::endl; return false; } @@ -259,7 +259,7 @@ Socket::Status SocketTCP::Send(const char* data, std::size_t sizeInBytes) else { // Error... - std::cerr << "Cannot send data over the network (invalid parameters)" << std::endl; + Err() << "Cannot send data over the network (invalid parameters)" << std::endl; return Socket::Error; } } @@ -302,7 +302,7 @@ Socket::Status SocketTCP::Receive(char* data, std::size_t maxSize, std::size_t& else { // Error... - std::cerr << "Cannot receive data from the network (invalid parameters)" << std::endl; + Err() << "Cannot receive data from the network (invalid parameters)" << std::endl; return Socket::Error; } } @@ -400,7 +400,7 @@ bool SocketTCP::Close() { if (!SocketHelper::Close(mySocket)) { - std::cerr << "Failed to close socket" << std::endl; + Err() << "Failed to close socket" << std::endl; return false; } @@ -482,15 +482,15 @@ void SocketTCP::Create(SocketHelper::SocketType descriptor) int yes = 1; if (setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&yes), sizeof(yes)) == -1) { - std::cerr << "Failed to set socket option \"SO_REUSEADDR\" ; " - << "binding to a same port may fail if too fast" << std::endl; + Err() << "Failed to set socket option \"SO_REUSEADDR\" ; " + << "binding to a same port may fail if too fast" << std::endl; } // Disable the Nagle algorithm (ie. removes buffering of TCP packets) if (setsockopt(mySocket, IPPROTO_TCP, TCP_NODELAY, reinterpret_cast(&yes), sizeof(yes)) == -1) { - std::cerr << "Failed to set socket option \"TCP_NODELAY\" ; " - << "all your TCP packets will be buffered" << std::endl; + Err() << "Failed to set socket option \"TCP_NODELAY\" ; " + << "all your TCP packets will be buffered" << std::endl; } // Set blocking by default (should always be the case anyway) diff --git a/src/SFML/Network/SocketUDP.cpp b/src/SFML/Network/SocketUDP.cpp index 51f7b682..05e96839 100644 --- a/src/SFML/Network/SocketUDP.cpp +++ b/src/SFML/Network/SocketUDP.cpp @@ -28,8 +28,8 @@ #include #include #include +#include #include -#include #include @@ -81,7 +81,7 @@ bool SocketUDP::Bind(unsigned short port) // Bind the socket to the port if (bind(mySocket, reinterpret_cast(&sockAddr), sizeof(sockAddr)) == -1) { - std::cerr << "Failed to bind the socket to port " << port << std::endl; + Err() << "Failed to bind the socket to port " << port << std::endl; myPort = 0; return false; } @@ -149,7 +149,7 @@ Socket::Status SocketUDP::Send(const char* data, std::size_t sizeInBytes, const else { // Error... - std::cerr << "Cannot send data over the network (invalid parameters)" << std::endl; + Err() << "Cannot send data over the network (invalid parameters)" << std::endl; return Socket::Error; } } @@ -167,7 +167,7 @@ Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t& // Make sure the socket is bound to a port if (myPort == 0) { - std::cerr << "Failed to receive data ; the UDP socket first needs to be bound to a port" << std::endl; + Err() << "Failed to receive data ; the UDP socket first needs to be bound to a port" << std::endl; return Socket::Error; } @@ -207,7 +207,7 @@ Socket::Status SocketUDP::Receive(char* data, std::size_t maxSize, std::size_t& else { // Error... - std::cerr << "Cannot receive data from the network (invalid parameters)" << std::endl; + Err() << "Cannot receive data from the network (invalid parameters)" << std::endl; return Socket::Error; } } @@ -313,7 +313,7 @@ bool SocketUDP::Close() { if (!SocketHelper::Close(mySocket)) { - std::cerr << "Failed to close socket" << std::endl; + Err() << "Failed to close socket" << std::endl; return false; } @@ -408,14 +408,14 @@ void SocketUDP::Create(SocketHelper::SocketType descriptor) int yes = 1; if (setsockopt(mySocket, SOL_SOCKET, SO_REUSEADDR, reinterpret_cast(&yes), sizeof(yes)) == -1) { - std::cerr << "Failed to set socket option \"reuse address\" ; " - << "binding to a same port may fail if too fast" << std::endl; + Err() << "Failed to set socket option \"reuse address\" ; " + << "binding to a same port may fail if too fast" << std::endl; } // Enable broadcast by default if (setsockopt(mySocket, SOL_SOCKET, SO_BROADCAST, reinterpret_cast(&yes), sizeof(yes)) == -1) { - std::cerr << "Failed to enable broadcast on UDP socket" << std::endl; + Err() << "Failed to enable broadcast on UDP socket" << std::endl; } // Set blocking by default (should always be the case anyway) diff --git a/src/SFML/System/Err.cpp b/src/SFML/System/Err.cpp new file mode 100644 index 00000000..26c43013 --- /dev/null +++ b/src/SFML/System/Err.cpp @@ -0,0 +1,109 @@ +//////////////////////////////////////////////////////////// +// +// SFML - Simple and Fast Multimedia Library +// Copyright (C) 2007-2009 Laurent Gomila (laurent.gom@gmail.com) +// +// This software is provided 'as-is', without any express or implied warranty. +// In no event will the authors be held liable for any damages arising from the use of this software. +// +// Permission is granted to anyone to use this software for any purpose, +// including commercial applications, and to alter it and redistribute it freely, +// subject to the following restrictions: +// +// 1. The origin of this software must not be misrepresented; +// you must not claim that you wrote the original software. +// If you use this software in a product, an acknowledgment +// in the product documentation would be appreciated but is not required. +// +// 2. Altered source versions must be plainly marked as such, +// and must not be misrepresented as being the original software. +// +// 3. This notice may not be removed or altered from any source distribution. +// +//////////////////////////////////////////////////////////// + +//////////////////////////////////////////////////////////// +// Headers +//////////////////////////////////////////////////////////// +#include +#include + + +//////////////////////////////////////////////////////////// +// Private data +//////////////////////////////////////////////////////////// +namespace +{ +// This class will be used as the default streambuf of sf::Err, +// it outputs to stderr by default (to keep the default beaviour) +class DefaultErrStreamBuf : public std::streambuf +{ +public : + + DefaultErrStreamBuf() + { + // Allocate the write buffer + static const int size = 64; + char* buffer = new char[size]; + setp(buffer, buffer + size); + } + + ~DefaultErrStreamBuf() + { + // Synchronize + sync(); + + // Delete the write buffer + delete[] pbase(); + } + +private : + + virtual int overflow(int character) + { + if (character != EOF) + { + // Valid character: add it to the write buffer (sync() will be called if the buffer is full) + return sputc(static_cast(character)); + } + else + { + // Invalid character: just synchronize output + return sync(); + } + } + + virtual int sync() + { + // Check if there is something into the write buffer + if (pbase() != pptr()) + { + // Retrieve the contents of the write buffer + int size = static_cast(pptr() - pbase()); + std::string buffer(pbase(), size); + + // Write it into the standard error output + fprintf(stderr, "%s", buffer.c_str()); + + // Reset the pointer position to the beginning of the write buffer + setp(pbase(), epptr()); + } + + return 0; + } +}; +} + +namespace sf +{ +//////////////////////////////////////////////////////////// +std::ostream& Err() +{ + static DefaultErrStreamBuf buffer; + static std::ostream stream(&buffer); + + return stream; +} + + +} // namespace sf diff --git a/src/SFML/System/Win32/ThreadImpl.cpp b/src/SFML/System/Win32/ThreadImpl.cpp index 2f707a29..cc1ff653 100644 --- a/src/SFML/System/Win32/ThreadImpl.cpp +++ b/src/SFML/System/Win32/ThreadImpl.cpp @@ -27,8 +27,8 @@ //////////////////////////////////////////////////////////// #include #include +#include #include -#include namespace sf @@ -41,7 +41,7 @@ ThreadImpl::ThreadImpl(Thread* owner) myThread = reinterpret_cast(_beginthreadex(NULL, 0, &ThreadImpl::EntryPoint, owner, 0, NULL)); if (!myThread) - std::cerr << "Failed to create thread" << std::endl; + Err() << "Failed to create thread" << std::endl; } diff --git a/src/SFML/Window/Linux/ContextGLX.cpp b/src/SFML/Window/Linux/ContextGLX.cpp index 474580a3..6fce2575 100644 --- a/src/SFML/Window/Linux/ContextGLX.cpp +++ b/src/SFML/Window/Linux/ContextGLX.cpp @@ -30,7 +30,7 @@ #include #include #include -#include +#include namespace sf @@ -158,7 +158,7 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co XWindowAttributes windowAttributes; if (XGetWindowAttributes(myDisplay, myWindow, &windowAttributes) == 0) { - std::cerr << "Failed to get the window attributes" << std::endl; + Err() << "Failed to get the window attributes" << std::endl; return; } @@ -175,7 +175,7 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co { if (visuals) XFree(visuals); - std::cerr << "There is no valid visual for the selected screen" << std::endl; + Err() << "There is no valid visual for the selected screen" << std::endl; return; } @@ -216,7 +216,7 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co // Make sure that we have found a visual if (!bestVisual) { - std::cerr << "Failed to find a suitable pixel format for the window -- cannot create OpenGL context" << std::endl; + Err() << "Failed to find a suitable pixel format for the window -- cannot create OpenGL context" << std::endl; return; } @@ -267,7 +267,7 @@ void ContextGLX::CreateContext(ContextGLX* shared, unsigned int bitsPerPixel, co myContext = glXCreateContext(myDisplay, bestVisual, toShare, true); if (!myContext) { - std::cerr << "Failed to create an OpenGL context for this window" << std::endl; + Err() << "Failed to create an OpenGL context for this window" << std::endl; return; } } diff --git a/src/SFML/Window/Linux/VideoModeSupport.cpp b/src/SFML/Window/Linux/VideoModeSupport.cpp index de824601..bb91c907 100644 --- a/src/SFML/Window/Linux/VideoModeSupport.cpp +++ b/src/SFML/Window/Linux/VideoModeSupport.cpp @@ -26,10 +26,10 @@ // Headers //////////////////////////////////////////////////////////// #include +#include #include #include #include -#include namespace sf @@ -89,13 +89,13 @@ void VideoModeSupport::GetSupportedVideoModes(std::vector& modes) else { // Failed to get the screen configuration - std::cerr << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl; + Err() << "Failed to retrieve the screen configuration while trying to get the supported video modes" << std::endl; } } else { // XRandr extension is not supported : we cannot get the video modes - std::cerr << "Failed to use the XRandR extension while trying to get the supported video modes" << std::endl; + Err() << "Failed to use the XRandR extension while trying to get the supported video modes" << std::endl; } // Close the connection with the X server @@ -104,7 +104,7 @@ void VideoModeSupport::GetSupportedVideoModes(std::vector& modes) else { // We couldn't connect to the X server - std::cerr << "Failed to connect to the X server while trying to get the supported video modes" << std::endl; + Err() << "Failed to connect to the X server while trying to get the supported video modes" << std::endl; } } @@ -145,13 +145,13 @@ VideoMode VideoModeSupport::GetDesktopVideoMode() else { // Failed to get the screen configuration - std::cerr << "Failed to retrieve the screen configuration while trying to get the desktop video modes" << std::endl; + Err() << "Failed to retrieve the screen configuration while trying to get the desktop video modes" << std::endl; } } else { // XRandr extension is not supported : we cannot get the video modes - std::cerr << "Failed to use the XRandR extension while trying to get the desktop video modes" << std::endl; + Err() << "Failed to use the XRandR extension while trying to get the desktop video modes" << std::endl; } // Close the connection with the X server @@ -160,7 +160,7 @@ VideoMode VideoModeSupport::GetDesktopVideoMode() else { // We couldn't connect to the X server - std::cerr << "Failed to connect to the X server while trying to get the desktop video modes" << std::endl; + Err() << "Failed to connect to the X server while trying to get the desktop video modes" << std::endl; } return desktopMode; diff --git a/src/SFML/Window/Linux/WindowImplX11.cpp b/src/SFML/Window/Linux/WindowImplX11.cpp index b50f73cf..fc47ef6f 100644 --- a/src/SFML/Window/Linux/WindowImplX11.cpp +++ b/src/SFML/Window/Linux/WindowImplX11.cpp @@ -28,10 +28,10 @@ #include // important to be included first (conflict with None) #include #include +#include #include #include #include -#include #include #include @@ -84,7 +84,7 @@ myKeyRepeat (true) XWindowAttributes windowAttributes; if (XGetWindowAttributes(myDisplay, myWindow, &windowAttributes) == 0) { - std::cerr << "Failed to get the window attributes" << std::endl; + Err() << "Failed to get the window attributes" << std::endl; return; } myWidth = windowAttributes.width; @@ -151,7 +151,7 @@ myKeyRepeat (true) CWEventMask | CWOverrideRedirect, &attributes); if (!myWindow) { - std::cerr << "Failed to create window" << std::endl; + Err() << "Failed to create window" << std::endl; return; } @@ -379,7 +379,7 @@ void WindowImplX11::SetIcon(unsigned int width, unsigned int height, const Uint8 XImage* iconImage = XCreateImage(myDisplay, defVisual, defDepth, ZPixmap, 0, (char*)iconPixels, width, height, 32, 0); if (!iconImage) { - std::cerr << "Failed to set the window's icon" << std::endl; + Err() << "Failed to set the window's icon" << std::endl; return; } Pixmap iconPixmap = XCreatePixmap(myDisplay, RootWindow(myDisplay, myScreen), width, height, defDepth); @@ -461,13 +461,13 @@ void WindowImplX11::SwitchToFullscreen(const VideoMode& mode) else { // Failed to get the screen configuration - std::cerr << "Failed to get the current screen configuration for fullscreen mode, switching to window mode" << std::endl; + Err() << "Failed to get the current screen configuration for fullscreen mode, switching to window mode" << std::endl; } } else { // XRandr extension is not supported : we cannot use fullscreen mode - std::cerr << "Fullscreen is not supported, switching to window mode" << std::endl; + Err() << "Fullscreen is not supported, switching to window mode" << std::endl; } } @@ -497,7 +497,7 @@ void WindowImplX11::Initialize() myInputContext = NULL; } if (!myInputContext) - std::cerr << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl; + Err() << "Failed to create input context for window -- TextEntered event won't be able to return unicode" << std::endl; // Show the window XMapWindow(myDisplay, myWindow); diff --git a/src/SFML/Window/Win32/ContextWGL.cpp b/src/SFML/Window/Win32/ContextWGL.cpp index 0de0e4df..d7e9e7b0 100644 --- a/src/SFML/Window/Win32/ContextWGL.cpp +++ b/src/SFML/Window/Win32/ContextWGL.cpp @@ -31,7 +31,7 @@ #include #include #include -#include +#include namespace sf @@ -205,7 +205,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co else { // wglChoosePixelFormatARB not supported ; disabling antialiasing - std::cerr << "Antialiasing is not supported ; it will be disabled" << std::endl; + Err() << "Antialiasing is not supported ; it will be disabled" << std::endl; mySettings.AntialiasingLevel = 0; } } @@ -229,7 +229,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co bestFormat = ChoosePixelFormat(myDeviceContext, &descriptor); if (bestFormat == 0) { - std::cerr << "Failed to find a suitable pixel format for device context -- cannot create OpenGL context" << std::endl; + Err() << "Failed to find a suitable pixel format for device context -- cannot create OpenGL context" << std::endl; return; } } @@ -245,7 +245,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co // Set the chosen pixel format if (!SetPixelFormat(myDeviceContext, bestFormat, &actualFormat)) { - std::cerr << "Failed to set pixel format for device context -- cannot create OpenGL context" << std::endl; + Err() << "Failed to set pixel format for device context -- cannot create OpenGL context" << std::endl; return; } @@ -289,7 +289,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co myContext = wglCreateContext(myDeviceContext); if (!myContext) { - std::cerr << "Failed to create an OpenGL context for this window" << std::endl; + Err() << "Failed to create an OpenGL context for this window" << std::endl; return; } @@ -301,7 +301,7 @@ void ContextWGL::CreateContext(ContextWGL* shared, unsigned int bitsPerPixel, co Lock lock(mutex); if (!wglShareLists(sharedContext, myContext)) - std::cerr << "Failed to share the OpenGL context" << std::endl; + Err() << "Failed to share the OpenGL context" << std::endl; } } } diff --git a/src/SFML/Window/Win32/WindowImplWin32.cpp b/src/SFML/Window/Win32/WindowImplWin32.cpp index 6581d912..d651b624 100644 --- a/src/SFML/Window/Win32/WindowImplWin32.cpp +++ b/src/SFML/Window/Win32/WindowImplWin32.cpp @@ -32,7 +32,7 @@ #include #include #include -#include +#include #include // MinGW lacks the definition of some Win32 constants @@ -309,7 +309,7 @@ void WindowImplWin32::SetIcon(unsigned int width, unsigned int height, const Uin } else { - std::cerr << "Failed to set the window's icon" << std::endl; + Err() << "Failed to set the window's icon" << std::endl; } } @@ -363,7 +363,7 @@ void WindowImplWin32::SwitchToFullscreen(const VideoMode& mode) // Apply fullscreen mode if (ChangeDisplaySettings(&devMode, CDS_FULLSCREEN) != DISP_CHANGE_SUCCESSFUL) { - std::cerr << "Failed to change display mode for fullscreen" << std::endl; + Err() << "Failed to change display mode for fullscreen" << std::endl; return; } diff --git a/src/SFML/Window/Window.cpp b/src/SFML/Window/Window.cpp index 6b5207c6..81ca327f 100644 --- a/src/SFML/Window/Window.cpp +++ b/src/SFML/Window/Window.cpp @@ -29,7 +29,7 @@ #include #include #include -#include +#include //////////////////////////////////////////////////////////// @@ -104,7 +104,7 @@ void Window::Create(VideoMode mode, const std::string& title, unsigned long styl // Make sure there's not already a fullscreen window (only one is allowed) if (fullscreenWindow) { - std::cerr << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; + Err() << "Creating two fullscreen windows is not allowed, switching to windowed mode" << std::endl; style &= ~Style::Fullscreen; } else @@ -112,7 +112,7 @@ void Window::Create(VideoMode mode, const std::string& title, unsigned long styl // Make sure the chosen video mode is compatible if (!mode.IsValid()) { - std::cerr << "The requested video mode is not available, switching to a valid mode" << std::endl; + Err() << "The requested video mode is not available, switching to a valid mode" << std::endl; mode = VideoMode::GetMode(0); } @@ -315,7 +315,7 @@ bool Window::SetActive(bool active) const } else { - std::cerr << "Failed to activate the window's context" << std::endl; + Err() << "Failed to activate the window's context" << std::endl; return false; } }