Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help,
read this.
-
Gunroar:Cannon()
- Party member
- Posts: 141
- Joined: Thu Dec 10, 2020 1:57 am
Post
by Gunroar:Cannon() » Fri Jan 15, 2021 1:07 pm
I want to delete a map object that holds a bunch of entities and I have an idea but it still leaves the map object floating around with a few mb after I destroy it and the framerate goes down a little too.
1.Please just check it over if this is ok and notify if you see any possible problem( I use hump's gamestate (
https://github.com/vrld/hump/blob/master/gamestate.lua)so do I need to do anything specialwith that)
2.Is there anyway to check whether an object is still referenced and where?.
Here's the destroy function( I destroy objects so space will be freed in the object pool for that object):
Code: Select all
--GS = hump.gamestate btw
function Map:destroy(destroyPeer)
self.isOld = true
--destroying entities to free up space in
--object pools
local ents = lume.copy(self.entities)
for x, i in pairs(ents) do
if i ~= game.player then
i:destroy()
end
end
local bulls = lume.copy(self.bullets)
for x, i in pairs(bulls) do
i:destroy()
end
self.entites = {}
self.bullets = {}
--destroying tiles
self.allTiles = {}
self.tiles = {}
self.grid = {}
GS.stacks = {}--??
game.map = nil
game.currentMap = nil
self.active = false
self:unpause()
self.player.map = nil
game.player = nil
self.player = {}
lume.clear(self)
end
me: I don't always code but when I do it's done flawlessly.
also me:
Code: Select all
function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end
Code: Select all
Lua Error: [file Gunroar.lua]:18: C stack overflow
-
Gunroar:Cannon()
- Party member
- Posts: 141
- Joined: Thu Dec 10, 2020 1:57 am
Post
by Gunroar:Cannon() » Tue Jan 19, 2021 6:29 am
I also use bump.lua for entities and all tiles.
me: I don't always code but when I do it's done flawlessly.
also me:
Code: Select all
function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end
Code: Select all
Lua Error: [file Gunroar.lua]:18: C stack overflow
-
4vZEROv
- Party member
- Posts: 114
- Joined: Wed Jan 02, 2019 8:44 pm
Post
by 4vZEROv » Thu Jan 21, 2021 10:06 pm
A table will only be garbage collected if there is no reference of it anywhere is the program. (not counting weak tables)
So a reference to your map is still somewhere in your code and keep it alive.
It's probably inside your bump.lua code, I believe you initialize the bump tables with some references if I remember correctly.
-
dusoft
- Party member
- Posts: 125
- Joined: Fri Nov 08, 2013 12:07 am
Post
by dusoft » Sun Jan 24, 2021 11:21 pm
-
Gunroar:Cannon()
- Party member
- Posts: 141
- Joined: Thu Dec 10, 2020 1:57 am
Post
by Gunroar:Cannon() » Sat Jan 30, 2021 1:21 pm
Ah, I found it. Hump gamestate had a local called stacks so it couldn't be accessed and the class couldn't be deleted. I accessed it by making it part of the Gamestate class. thnx.
me: I don't always code but when I do it's done flawlessly.
also me:
Code: Select all
function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end
Code: Select all
Lua Error: [file Gunroar.lua]:18: C stack overflow
-
Gunroar:Cannon()
- Party member
- Posts: 141
- Joined: Thu Dec 10, 2020 1:57 am
Post
by Gunroar:Cannon() » Tue Feb 16, 2021 9:05 am
I made this function to find any references to an object (which I still had due to some accidentally global declared tables) so you can flush it out, and that really fixed it for me
https://love2d.org/forums/viewtopic.ph ... 3d7354eba0
me: I don't always code but when I do it's done flawlessly.
also me:
Code: Select all
function Gunroar:Cannon()
for x, enemy in ipairs(self.allEnemies) do
self:Cannon(enemy)
end
end
Code: Select all
Lua Error: [file Gunroar.lua]:18: C stack overflow
Users browsing this forum: No registered users and 59 guests