The SFML library that I'm trying to cythonize defines this function below that allows to change where errors are printed to (by default SFML writes error messages to the console when this function is not called):
namespace sf {
std::ostream& err() {
static DefaultErrStreamBuf buffer;
static std::ostream stream(&buffer);
return stream;
}
}
My simplified .pxd file for the above function:
cdef extern from 'SFML/System.hpp' namespace 'sf':
ostream& cerr 'sf::err' ()
And my .pyx module, which compiles and runs fine, but doesn't redirect the error messages (they are still printed to the console).
cdef void set_error_handler():
cerr().rdbuf(NULL) # This call should prevent errors appearing in the console but it silently fails
set_error_handler()
I'm using MSVC and linking statically with the C++ code.
Edit
Below is example how the SFML library logs errors in its own code (full source):
...
// Error, failed to load the image
err() << "Failed to load image \"" << filename << "\". Reason: " << stbi_failure_reason() << std::endl;
...
My goal is to suppress the error messages like the one above from appearing in the console and eventually later redirect them into own buffer.
sf:err()
, the SFML library does this and I want to suppress that or redirect. – Unbendingset_error_handler()
in c++ and call it from cython. Does it work then? Just trying to rule out, that this is a not a sfml-issue. – Invasive