Alienhead Posted November 7 Share Posted November 7 How to completely remove an entity that uses the same variable in the same routine. I have two variables that hold references to two weapon entities the player uses. Scenario: Player changes weapons but nulling the variable holders for the previous weapons dont work because the new weapons fill in the varaible preventing it from being deleted. -- drop old weps self.weplefthand = nil self.weprighthand = nil collectgarbage() self.weplefthand = NewWepToHold1 self.weprighthand = NewWepToHold2 Quote I'm only happy when I'm coding, I'm only coding when I'm happy. Link to comment Share on other sites More sharing options...
Dreikblack Posted November 7 Share Posted November 7 1 hour ago, Alienhead said: Player changes weapons but nulling the variable holders for the previous weapons dont work because the new weapons fill in the varaible preventing it from being deleted. It should not prevent it at all. Are you sure there are no other pointers exist to those weapons? Example how same reusing of var deletes prev entity without other references to it: local displays = GetDisplays() local window = CreateWindow("Ultra Engine", 0, 0, 1280, 720, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR) local framebuffer = CreateFramebuffer(window) local world = CreateWorld() -- Create a camera local camera = CreateCamera(world) camera:SetClearColor(0.125) camera:SetFov(70) camera:Move(0, 2, -8) -- Create light local light = CreateBoxLight(world) light:SetRotation(45, 35, 0) light:SetRange(-10, 10) local box = CreateBox(world) box:SetPosition(1, 1, 1) -- Main loop while window:Closed() == false and window:KeyHit(KEY_ESCAPE) == false do collectgarbage() world:Update() world:Render(framebuffer) if (window:KeyHit(KEY_SPACE)) then box = CreateBox(world) end end Quote Link to comment Share on other sites More sharing options...
Josh Posted November 10 Share Posted November 10 On 11/7/2024 at 3:43 AM, Alienhead said: How to completely remove an entity that uses the same variable in the same routine. I have two variables that hold references to two weapon entities the player uses. Scenario: Player changes weapons but nulling the variable holders for the previous weapons dont work because the new weapons fill in the varaible preventing it from being deleted. -- drop old weps self.weplefthand = nil self.weprighthand = nil collectgarbage() self.weplefthand = NewWepToHold1 self.weprighthand = NewWepToHold2 There is no need to set those variables to nil at all. -- drop old weps self.weplefthand = NewWepToHold1 self.weprighthand = NewWepToHold2 collectgarbage() If the old objects are not being deleted, you must have the same objects referenced somewhere else. You can call SetHidden() to hide them, if nothing else works. In Leadwerks, stuff like this could cause invalid pointer errors, which are impossible to detect and cause random memory overwrite. This was the #1 issue I saw causing problems in games made by the community. 1 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...
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.