How to totally deallocate a game object (Solved)

I encounter a small problem, I created a factory linked to my player object to generate bullets and when they encounter an obstacle they are supposed to be destroyed, here is roughly the script of my bullets:

function init(self)
	self.pos = go.get_position()
end

function update(self, dt)
	self.pos.y = self.pos.y + 400 * dt
	go.set_position(self.pos)
end

function on_message(self, message_id, message, sender)
	if message_id == hash("contact_point_response") then
		go.delete()
	end
end

My problem is that very quickly I come across this error:

ERROR:GAMESYS: Sprite could not be created since the sprite buffer is full (128). See 'sprite.max_count' in game.project
ERROR:GAMEOBJECT: Could not spawn an instance of prototype /main/game/gObjects/bullet.goc.

Doesn’t the go.delete() function completely deallocate a created object? By that I mean sprites or other assets related to it?

I also find it a bit strange that the same image is reallocated every time for the same objects, maybe I’m doing something wrong?

Yes it does. But are your sure that you are calling the function? Add a breakpoint and check with the debugger, or add a print to verify.

I have already inserted a print() in the condition and the program did go through that.

I also assumed that some instances might still be active when I left the collection and then returned to it, so I added this in doubt, as a simple test:

function final(self)
	go.delete()
end

The function was indeed executed but still the same problem.

Ok. But could it be that you actually have more than 128 sprites (and game objects) active?

You can check this with the profiler.

And you can of course increase this value in game. project.

Oh sorry, it’s totally my fault, I had forgotten a mask in the collisions and therefore some balls were not destroyed… Excuse me, I’m not used to graphical interfaces, I have to I get used to it…

Other question

Otherwise, so as not to have wasted this time for nothing, is it normal or is there a workaround on the fact that the images are duplicated in memory when objects are created by a factory? Where is there a subtlety that I do not understand, if you have the answer?

Edit: Finally even putting all the masks there the problem perciste and no I don’t have more than 128 sprites displayed, so I’m looking for where I could have made a mistake, I find it weird

I tried to take a capture at the right time but I can’t see the line of sprites go over 128 when I get this error, or it’s so fast that it doesn’t show (???) I don’t quite understand. Or do the other numbers below count as well?

After checking that everything was getting destroyed, I finally doubled the size of the buffer and everything was fine, I deduce that the line to read was SpriteVertexCount and everything becomes coherent.

Thanks a lot for the help! ^^

How do you mean?

Can you share the project please so that we can take a look?

The sprite count is shown next to the “Sprite” counter.

So why am I getting this error when the number of sprites does not exceed 29? I figured it was the bottom one because it was hitting 116 before getting the error.

What I don’t understand is why the number of sprites allocated in the buffer increases for the same object using the same sprite, is there a reason? Or rather how the engine uses this buffer? (sorry if this is a little “off topic” but I always like to understand what I’m doing)

I don’t think it’s necessary for you to waste your time on it, the problem would indeed come from the sprite limit allocated by default (128), all the instances created are indeed destroyed at some point.

However what I find strange (and this is the question I asked @Mathias_Westerdahl) is that the number of sprites displayed by the profiler never exceeded 29, the only value consistent with this error is the SpriteVertexCount which was limited to 116 before showing the error.

SpriteVertexCount, I would assume, is the number of mesh vertices used by sprites. Since sprites are rectangles, you would need at least 4 vertices per sprite. 29 * 4 = 116, so that makes sense.

It doesn’t explain why you are hitting the limit of 128 while only seeing 29 on the profiler though.
There is the caveat to go.delete (mentioned in the docs) that the objects aren’t actually removed until the end of the frame, but you would still need to be creating and deleting quite a few more for that to matter.

1 Like

The counter shows how many items are rendered.

1 Like

Hmm, taking into account that ppl use this counter to compare it with max counter, I think it’s a bug. We should have total sprites here, and show count of rendered sprites separately

2 Likes