Debug and Output Functions

内容表

关于

The most simple way to debug and analyse code is to print data and events to a debug console. The MAXON API offers multiple functions that allow printing debug messages, checking for critical conditions and triggering debug stops.

注意
To print messages to Cinema 4D 's "Console" window use ApplicationOutput() 。见 LoggerInterface Manual .

Warning Levels

Output messages can be assigned to one of these levels: diagnostic , warning or critical . By default messages of all three levels are printed to the debug console.

The output to the console can be filtered by setting the configuration variables g_diagnostic , g_warning and g_critical to true or false 。见 Configuration Variables .

Console Output

C++ code can be compiled to either a release or debug build. DebugOutput() prints the given message only in such a debug build; it does not cost any time in a release build.

The following flags can be used to define the type of message:

The message can be formatted with:

// This example prints two debug messages using different flags.
maxon::OUTPUT flags = maxon::OUTPUT::DIAGNOSTIC | maxon::OUTPUT::HEADER ; DebugOutput (flags, "@" , "Debug test" _s);
flags = maxon::OUTPUT::CRITICAL | maxon::OUTPUT::HEADER ; DebugOutput (flags, "@" , "Critical Error" _s);

The following functions print messages in both debug and release builds:

// This example prints various debug messages.

// simple message const maxon::Int value = 1; DiagnosticOutput ( "The value is: @" , value);

// debug variable values const maxon::Int i = 123; const maxon::String msg { "This is a test" }; DiagnosticVarOutput (i, msg);

// This example checks if the sub-functions succeeded. // If not, debug messages are printed.

// perform task maxon::Result<void> res = PerformSimpleTask(); // check for success if (res == maxon::FAILED ) WarningOutput ( "Task could not be performed." );

// perform task res = PeformCriticalTask(); // check for success if (res == maxon::FAILED ) CriticalOutput ( "Critical Task could not be performed." );

Debug Stop

Cinema 4D is run with a debugger the program flow will stop if a breakpoint is hit. Such a breakpoint can be triggered dynamically with these functions:

// This example checks if the sub-functions succeeded. // If not, debug stops are triggered.

// perform task maxon::Result<void> res = PerformSimpleTask(); // check for success if (res == maxon::FAILED ) DebugStop ( "Task could not be performed." );

// perform task res = PeformCriticalTask(); // check for success if (res == maxon::FAILED ) CriticalStop ( "Critical Task could not be performed." );

Asserts

The following macros can be used to check critical conditions. If the condition is not fulfilled the program is stopped.

注意
Asserts will only be executed in debug builds. In release code, the check won't be executed.

另请参阅 Error Utility .

// This example checks the return values of the sub-functions. // Asserts are used to check these values. const Int32 elementCnt = GetElementCount(); DebugAssert (elementCnt > 0, "Invalid Element Count" _s); const Int32 error = GetErrorCode(); CriticalAssert (error == 0, "Error Code is not 0." _s);

延伸阅读

DebugStop
#define DebugStop(...)
定义: debugdiagnostics.h:228
DiagnosticVarOutput
#define DiagnosticVarOutput(...)
定义: debugdiagnostics.h:172
CriticalOutput
#define CriticalOutput(formatString,...)
定义: debugdiagnostics.h:200
DebugOutput
#define DebugOutput(flags, formatString,...)
定义: debugdiagnostics.h:158
maxon::String
定义: string.h:1197
maxon::OUTPUT
OUTPUT
output flags for console output
定义: debugdiagnostics.h:52
DiagnosticOutput
#define DiagnosticOutput(formatString,...)
定义: debugdiagnostics.h:166
WarningOutput
#define WarningOutput(formatString,...)
定义: debugdiagnostics.h:189
CriticalAssert
#define CriticalAssert(condition,...)
定义: debugdiagnostics.h:250
maxon::Result< void >
maxon::Int
Int64 Int
signed 32/64 bit int, size depends on the platform
定义: apibase.h:184
CriticalStop
#define CriticalStop(...)
定义: debugdiagnostics.h:234
maxon::FAILED
static const ERROR_FAILED FAILED
定义: resultbase.h:68
Int32
maxon::Int32 Int32
定义: ge_sys_math.h:58
maxon::OUTPUT::HEADER
@ HEADER
if set, header with line number and file name is added
maxon::OUTPUT::CRITICAL
@ CRITICAL
critical output, shows up if this group of output is activated
maxon::OUTPUT::DIAGNOSTIC
@ DIAGNOSTIC
diagnostic output, shows up if this group of output is activated. This is also the default
DebugAssert
#define DebugAssert(condition,...)
定义: debugdiagnostics.h:245

Copyright  © 2014-2025 乐数软件    

工业和信息化部: 粤ICP备14079481号-1