Add material to layer can successful in v6.0 sr15 but not successful in v6.0 sr18 (c++)

HI,
I want to add material to the layer, it can successful in v6.0 sr15 but no new material create in v6.0 sr18 by my core , is it bug?

void SetLayerMaterial(const CRhinoLayer& layer, ON_wString filename)
{
	CRhinoDoc* pDoc = RhinoApp().ActiveDoc();
	if (CRhinoFileUtilities::FileExists(filename))
	{
		CRhinoDib dib;
		if (dib.ReadFromFile(pDoc->RuntimeSerialNumber(), filename))
		{
			ON_Material mat;
			mat.m_diffuse.SetRGB(255,191,0);
			mat.SetTransparency(0.0);
            mat.AddTexture(filename, ON_Texture::TYPE::bitmap_texture);

			auto* pMaterial = ::RhRdkNewBasicMaterial(mat, pDoc);
			ON_wString sName;
			ON_FileSystemPath::SplitPath(filename, nullptr, nullptr, &sName, nullptr);
			pMaterial->SetInstanceName(sName);
			auto& contents = pDoc->Contents().BeginChange(RhRdkChangeContext::Program);
			contents.Attach(*pMaterial);
			contents.EndChange();
			CRhRdkObjectDataAccess da(&layer);
			da.SetMaterialInstanceId(pMaterial);
		}
	}
}

@johnc - can you look at this?

Hi suc_kiet,

I pasted your code into a test command in Version 6 SR18. I called it with the default layer and the filename of a JPG file – and it worked. I could see the material and texture in the Layer Material window. I also tested in Rhino 7 (WIP) and it works there too. I’m afraid I don’t know what to suggest at this stage.

Regards,

John

HI johnc,
Thanks a lot.
May be I need to create a template file to solve it.