Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

No assert ? #555

Open
SeleDreams opened this issue May 8, 2021 · 7 comments
Open

No assert ? #555

SeleDreams opened this issue May 8, 2021 · 7 comments
Labels
discussion enhancement This is an enhancement on the current functionality

Comments

@SeleDreams
Copy link
Contributor

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...

@Calinou
Copy link
Member

Calinou commented May 8, 2021

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 🙂

@Calinou Calinou added discussion enhancement This is an enhancement on the current functionality labels May 8, 2021
@SeleDreams
Copy link
Contributor Author

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

@SeleDreams
Copy link
Contributor Author

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

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

@SeleDreams
Copy link
Contributor Author

in fact seems like CRASH_COND only stops the current function though it doesn't stop the execution of the rest of the program

@SeleDreams
Copy link
Contributor Author

SeleDreams commented May 9, 2021

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

@Calinou
Copy link
Member

Calinou commented May 9, 2021

cc @Zylann @vnen

@Zylann
Copy link
Collaborator

Zylann commented May 9, 2021

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... #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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
discussion enhancement This is an enhancement on the current functionality
Projects
None yet
Development

No branches or pull requests

3 participants