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.
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 .
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:
The following functions print messages in both debug and release builds:
// 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." );
若 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:
// 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." );
The following macros can be used to check critical conditions. If the condition is not fulfilled the program is stopped.
另请参阅 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);