Programming Advice

SDK Installation

The Cinema 4D C++ SDK can be installed in any location on the file system. It is not recommended to install it into any of the OS application-referred folders (e.g. "Program Files" or "Applications")

Handling API Functions And Classes

  • Include OS headers before Cinema 4D headers.
  • Keep code with shared OS and Cinema 4D calls as small as possible and gathered in one place (better portability and less data type conflicts).
  • When handling the classic API, only use the actual routines. Never use the C4DOS structure directly.
  • Do not use global static classes of complex types. Elementary data types (Int32, Float, Char etc.) are allowed, see Primitive Data Types Manual (Classic).

Using Native Cinema 4D Workflows

  • Make use of Cinema 4D's concepts of writing data to files. See HyperFile Manual and DescribeIO Manual.
  • Deliver a functionality-complete integration of the plugins to support all Cinema 4D features and grant a consistent user's experience across plugins' use (e.g. see Undo System Manual).

Defensive Programming

  • Always do "defensive programming". Check pointers and results everywhere.
  • Any API function may fail. Check for everything, even if it seems obvious e.g. NewMem().
  • Any division needs to be checked for 0.0.
  • Not every element of Cinema 4D is implemented as a plugin, so GeListNode::GetNodeData() might return nullptr.
  • The order of evaluation depends on the compiler and platform. Make sure that operations are always called in the desired order. For example the functions of a pseudorandom number generator must be called explicitly in the correct order.

Portability And Compatibility

  • Only use Cinema 4D data types to ensure easy porting to other platforms. See Data & Algorithms.
  • Make use of external resource files. Do not hardcode descriptions, dialogs and strings. See Resource Files Manual.
  • Always use constants to avoid compatibility problems.
  • Provide different binary versions of your plugins to support older versions of Cinema 4D.
  • Plugins compiled with a newer API will not load in an older version of Cinema 4D.
  • Information about previous Cinema 4D versions is only available for convenience. Only the latest API version can be supported. To maximize compatibility with a certain Cinema 4D version use the corresponding API.
  • Plugins compiled with older API will not automatically load in Cinema 4D R20 or newer versions. See Plugin Migration.

Memory

  • Only use the Cinema 4D memory model for maximum speed and stability. See Memory Allocation and Entity Creation. If a plugin uses its own memory handling it won't benefit from Cinema 4D's memory model.
  • Use reference counted elements whenever possible to avoid memory leaks. See References.
  • Double-check your cleanup code in PluginEnd() and C4DPL_ENDACTIVITY. See Plugin Functions Manual.

Critical Plugin Hooks

Further Reading