Jump to content

FreeEntity() crashes editor?


Canardia
 Share

Recommended Posts

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

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

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...

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

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

Ryzen 9 RX 6800M ■ 16GB XF8 Windows 11 ■
Ultra ■ LE 2.53DWS 5.6  Reaper ■ C/C++ C# ■ Fortran 2008 ■ Story ■
■ Homepage: https://canardia.com ■

Link to comment
Share on other sites

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()!

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

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...