MAXScript Debugger >

# CRT Debug Functions

A few diagnostic tools were added to MAXScript in 3ds Max 2012.

They are located in the SDK samples in the maxscript subdirectory <maxsdk>\samples\maxscript\Diagnostics\MxsDebugCRT.cpp

This file contains some powerful maxscript methods for diagnosing and testing using MAXScript.

    CRTCorruptHeap <int>offset

This method will corrupt the Heap! Dangerous! Used for testing only!

The offset parameter defines how far past the end of the pointer you want to do a wild write. Large numbers tend to not crash randomly later. This simply serves to corrupt memory in random places, that may or may not crash the application.

    CRTCheckMemory()

A MAXScript wrapper around the CRT (C Run-Time) Debug function _CrtCheckMemory

From MSDN:

Confirms the integrity of the memory blocks allocated in the debug heap (debug version only).

The _CrtCheckMemory function validates memory allocated by the debug heap manager by verifying

the underlying base heap and inspecting every memory block. If an error or memory inconsistency

is encountered in the underlying base heap, the debug header information, or the overwrite buffers,

_CrtCheckMemory generates a debug report with information describing the error condition.

When _DEBUG is not defined, calls to _CrtCheckMemory are removed during preprocessing.

This function is used to detect heap corruptions created by the previous MAXScript method. In practice this detects only small heap corruptions, of only a few bytes (i.e. 1-6).

This is because with every debug heap allocation is a small region of guard bytes (about 4 bytes) that wraps each heap allocation. Anything larger than a few bytes will corrupt some other pointers bytes, and thus this method doesn't work very well.

    CRTCheckAssert <int>choice

This simply fires one of two asserts.

Passing 1 as the argument fires an assert implemented in the max source code, Maxutil.dll. This corresponds to a DbgAsset macro found in the maxsdk: (assert1.h)

Passing 2 as the argument fires an assert implemented in the C runtime (i.e. Microsofts version).