Canardia Posted December 20, 2009 Share Posted December 20, 2009 I'm trying to spawn a cube when I place a model in editor, but Editor crashes when it tries to free the cube when I delete the model from Editor: function class:CreateObject(model) local object=self.super:CreateObject(model) cube=CreateCube() function object:Free() cube:Free() end end Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
macklebee Posted December 20, 2009 Share Posted December 20, 2009 hmmm that code works fine for me... except if i drag and drop more two of the objects onto the screen, and then delete them it leaves the first cube, because the second cube create effectively is now 'cube' you should parent the cube to the model in creation... then it gets deleted no matter what... Quote Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590 LE / 3DWS / BMX / Hexagon macklebee's channel Link to comment Share on other sites More sharing options...
Canardia Posted December 20, 2009 Author Share Posted December 20, 2009 Ok, I can parent it to the lua object, but not to the entity, since then the animation would not work anymore. This seems to work fine, and it also deletes the cubes for each model you place in Editor: require "scripts/class" local class=CreateClass(...) function class:CreateObject(model) local object=self.super:CreateObject(model) object.cube=CreateCube() object.cube:SetPosition(object.model:GetPosition()) function object:Free() self.cube:Free() end end Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Rick Posted December 20, 2009 Share Posted December 20, 2009 The first way you were doing it was actually creating a global variable named cube. I'm guessing you don't want the cube to be global so making it apart of object would be what you want. Quote Link to comment Share on other sites More sharing options...
Josh Posted December 20, 2009 Share Posted December 20, 2009 I usually like to have a lot of extra checks: function class:CreateObject(model) local object=self.super:CreateObject(model) object.cube=CreateCube() function object:Free() if self.cube~=nil then self.cube:Free() self.cube=nil end self.super:Free() end end Don't forget self.super:Free()! Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted December 20, 2009 Author Share Posted December 20, 2009 Doesn't seem to be needed, as the model disappears when I press the delete key in Editor. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Josh Posted December 20, 2009 Share Posted December 20, 2009 It may be invisible, but it will still be stored in memory and in the lua object table. The class will never get freed either. Quote My job is to make tools you love, with the features you want, and performance you can't live without. Link to comment Share on other sites More sharing options...
Canardia Posted December 20, 2009 Author Share Posted December 20, 2009 Ok, then it's better to free it also. Quote ■ Ryzen 9 ■ RX 6800M ■ 16GB ■ XF8 ■ Windows 11 ■ ■ Ultra ■ LE 2.5 ■ 3DWS 5.6 ■ Reaper ■ C/C++ ■ C# ■ Fortran 2008 ■ Story ■ ■ Homepage: https://canardia.com ■ Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.