godot-cpp
godot-cpp copied to clipboard
No assert ?
Hi, I'm sending this message because as far as I can see I find no way to actually do an assert using godot-cpp which is a problem as the standard c++ assert function only prints to stdout and godot (god knows why) doesn't use the standard stdout making assert useless is there anything like Godot::assert or something that serves the same purpose ? I expected to find a Godot::assert the same way as the Godot class has the printing methods but no...
godot (god knows why) doesn't use the standard stdout making assert useless
Godot prints error and warning messages (printed using ERR_PRINT()
) to the standard error stream, so that they can be filtered independently of lines printed by the project using print()
(print_line()
in C++).
Also, I don't see the relationship between an assert function and stdout/stderr. Are you referring to the Godot process' exit codes instead? Godot tries to be as well-behaved as possible in this regard, but it's not perfect. Feel free to open pull requests on the main Godot repository to improve this :slightly_smiling_face:
I ended up finding the macro CRASH_COND that seems to have a similar behaviour to assert (except that it takes the crash condition rather than the assertion condition) this one outputs to the godot log properly rather than stdout
godot (god knows why) doesn't use the standard stdout making assert useless
Godot prints error and warning messages (printed using
ERR_PRINT()
) to the standard error stream, so that they can be filtered independently of lines printed by the project usingprint()
(print_line()
in C++).Also, I don't see the relationship between an assert function and stdout/stderr. Are you referring to the Godot process' exit codes instead? Godot tries to be as well-behaved as possible in this regard, but it's not perfect. Feel free to open pull requests on the main Godot repository to improve this slightly_smiling_face
what i meant was that the problem caused by asset is that as it outputs to stdout, when it does crash because of an assert it won't output the assert output to the godot log, now that i found CRASH_COND Now though it's fine
in fact seems like CRASH_COND only stops the current function though it doesn't stop the execution of the rest of the program
I was able to make an ASSERT macro that works the same as CRASH_COND but reverses the condition and calls abort rather than return
#ifndef ASSERT
#include <Defs.hpp>
#define ASSERT(cond) \
do \
{ \
bool condition = !(cond); \
if (unlikely(condition)) \
{ \
FATAL_PRINT(ERR_MSG_COND(condition)); \
abort(); \
} \
} while (0)
#endif
it might be a good addition to godot-cpp
cc @Zylann @vnen
This is supposed to be covered by CRASH_COND
. I opened an issue a while ago because it does not behave correctly at the moment. It barely does the same as ERR_FAIL_COND
... https://github.com/godotengine/godot-cpp/issues/521 instead it should basically do the same as assert()
with reverse condition: causing an actual crash with the error printed to stderr, which in debug mode makes the debugger stop on it as well.