Creating and destroying materials

// First, get our resource manager and access its interface.
RED::Object* resmgr = RED::Factory::CreateInstance( CID_REDResourceManager );
RED::IResourceManager* iresmgr = resmgr->As< RED::IResourceManager >();

// Then, create a material from it:
RED::Object* material;
RC_TEST( iresmgr->CreateMaterial( material, iresmgr->GetState() ) );

// Release the material after use:
RC_TEST( iresmgr->DeleteMaterial( material, iresmgr->GetState() ) );

As you can see, material creation and destruction is simple using the RED::IResourceManager interface. However, attention must be paid to the fact that a material must not be used by any shape at the time it's destroyed. REDsdk does not invalidate possible references to the destroyed material that may exist in the calling application. This is the responsibility of the application to ensure that a material that is destroyed is no longer used by any shape being rendered. REDsdk will detect invalid materials used during a draw and will return a RED_SCG_DEAD_MATERIAL_ADDRESS error code if this happens.