Add DEV_ASSERT and DEV_CHECK macros #53393
Merged
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Change the existing DEV_ASSERT macro to be switched on and off by the DEV_ENABLED define. DEV_ASSERT breaks into the debugger as soon as hit.
Add error macros DEV_CHECK and DEV_CHECK_ONCE to add an alternative check that ERR_PRINT when a condition fails, again only enabled in DEV_ENABLED builds.
c++ DEV only asserts
N.B. - These macros will now be compiled into
DEV_ENABLED
(debug
) builds only, they will be compiled out inrelease
andrelease_debug
builds. They therefore are particularly aimed at use particularly in bottleneck code (such as renderer, physics, or accessors), or if you are not sure whether a check warrants aCRASH_COND
or runtime check, but you want to document the assertion and check code flow in debug builds.Polarity / Naming
Happy to hear opinions regarding naming / polarity of these functions.
They are both positive logic functions, which in my experience is more common for asserts in programming than the negative logic of e.g.
ERR_FAIL
andCRASH_COND
which is often used in Godot. I personally find the positive logic more natural but maybe that is due to previous experience.Although Godot normally does everything possible to prevent crashing / halting, programmers will be expecting asserts to halt execution immediately in a debugger. This is why it is probably a good idea for us to have another method for recoverable errors - hence the
DEV_CHECK_ONCE
andDEV_CHECK
.Notes
DEV_ASSERT
in the portal renderer, these are now active in debug builds.Unify
tools
/target
build type configuration to disambiguate "debug" (used for both game debugging and engine dev tools) godot-proposals#3371