Material to CME

Material to CME

Siger_
Enthusiast Enthusiast
583 Views
1 Reply
Message 1 of 2

Material to CME

Siger_
Enthusiast
Enthusiast

What is wrong?

I'm trying to put material from a loaded library into the Material Editor's Active slot (Basic mode). In Max 2017/2018  - ok. But Max 2013 crash!

C#

 

                    IMtlBaseLib tempLib = MaxCore.Core.MaterialLibrary;
                    MaxCore.Core.LoadMaterialLib(materialLibPath, tempLib);
                    if (tempLib != null)
                    {
                        string matId = item.Id;
                        int matIdx = tempLib.FindMtlByName(ref matId);
                        if (matIdx != -1)
                        {
#if REL13
                            IMtlBase mat = tempLib[(IntPtr)matIdx];
#else
                            IMtlBase mat = tempLib[matIdx];
#endif
                            int actMtlSlot = MaxCore.Core.ActiveMtlSlot;
                            mat.Name = item.DisplayName;
                            MaxCore.Core.PutMtlToMtlEditor(mat, actMtlSlot);

                           // Some commented methods, currently inactive

                            MaxCore.Core.UpdateMtlEditorBrackets();
                        }
                        tempLib.DeleteAll();
                        tempLib.Dispose();
                    }
0 Likes
584 Views
1 Reply
Reply (1)
Message 2 of 2

Siger_
Enthusiast
Enthusiast

Strange, but... I add this to the end of method, and now Ok.

#if REL13
                                Marshal.FreeHGlobal(matIdx);
#endif

 

0 Likes