When does CS2D free images?
18 replies



14.04.21 12:27:49 am
I know that images don't get freed on
endround and that they get freed on
startround.
Does that mean the images still technically "exist" on
startround_prespawn?
If so, is that consistent? Can I free the images on
startround_prespawn? Or is it better to let the game handle that and to just set the variable to
What is the order of execution?
When do images get automatically freed by CS2D?
Why is there no
post_endround (once the round completely ended)?


Does that mean the images still technically "exist" on

If so, is that consistent? Can I free the images on

nil
?What is the order of execution?
When do images get automatically freed by CS2D?
Why is there no

Look at me standing, here on my own again
It is better if you let CS2D free it whenever it can.
This way you are avoiding additional network traffic.
This way you are avoiding additional network traffic.
I mean, of course!
But I just noticed that one of my scripts frees images on
startround_prespawn, and I haven't noticed any issues.
I've changes it now to only free the image if the function wasn't called on a round start, I just wanted to know if I missed anything or if this really does work just fine either way.
But I just noticed that one of my scripts frees images on

I've changes it now to only free the image if the function wasn't called on a round start, I just wanted to know if I missed anything or if this really does work just fine either way.
Look at me standing, here on my own again
Yes, all dynamic objects, including NPCs, buildings and images, are removed when a new round starts.
No, images do NOT exist anymore in
startround_prespawn and therefore freeing does not make any sense. It doesn't do anything at all. It would not even cause extra taffic because CS2D would silently fail to find the images you want to remove. It's cleaner to simply not try to free images at that point but it doesn't cause any problem either. Only setting the variables to nil is better of course.
Execution order when a new round starts:
auto team balance
adjust scores (depending on end of previous round)
free all dynamic objects
reset the map (clear items, reset entities, clear particles, run trigger start, spawn items/npcs/buildings)
run
startround_prespawn
clear old hostages & spawn new hostages
spawn players (and run
spawn for each right after spawning)
run
startround
reset/start bot AI
optionally trigger an automatic map change if conditions are met
And no, that order isn't perfect. It just grew like that and it worked so that's why there is that order.
I guess there's no "post_endround" or something like that because there was no high demand for that yet. I would have no idea what you want to use that for. Everything what happens after
endround (gameplay wise) should be ignored because it's basically just an artificial delay so people can see how the round ended.
No, images do NOT exist anymore in

Execution order when a new round starts:













And no, that order isn't perfect. It just grew like that and it worked so that's why there is that order.
I guess there's no "post_endround" or something like that because there was no high demand for that yet. I would have no idea what you want to use that for. Everything what happens after

edited 1×, last 14.04.21 12:56:18 am
Thank you!
You should document that order somewhere on CS2D.com.
Perhaps on the cheat sheet!
I've also noticed bad usage of image IDs can lead to game breaking bugs, like being able to move a Turret's image but its physical body stays behind, similar stuff can happen to NPCs as well!
Of course all of that won't happen unless someone messed up the image handling...
You should document that order somewhere on CS2D.com.
Perhaps on the cheat sheet!
I've also noticed bad usage of image IDs can lead to game breaking bugs, like being able to move a Turret's image but its physical body stays behind, similar stuff can happen to NPCs as well!
Of course all of that won't happen unless someone messed up the image handling...
Look at me standing, here on my own again
Yes, I'm aware of this. Since all these objects share the same basic data type the image commands can be used to also modify npcs and buildings - leading to weird and possibly game breaking results. It would be quite easy to block that by checking the type but I simply never added such a check.
@
DC: Actually, I've had quite a few issues when trying to create images on the
startround_prespawn hook.
The images won't show up for some reason, perhaps the hook gets called before the images get freed? Do you mind verifying?
For now I'll stick to
startround.
EDIT:
I think that actually, players won't receive a packet about the image being set when using that hook, the image is there when I reconnect, this is really odd.


The images won't show up for some reason, perhaps the hook gets called before the images get freed? Do you mind verifying?
For now I'll stick to

EDIT:
I think that actually, players won't receive a packet about the image being set when using that hook, the image is there when I reconnect, this is really odd.
Look at me standing, here on my own again

Quote:
This hook can lead to problems with certain commands due to its early execution (especially when playing online). This is because many things will actually be initialized by the game AFTER calling this hook. Try to execute problematic commands later (in another hook or delayed with a timer) in case they do not work properly. Especially commands which change players/hostages/NPCs/items/entities might be affected.
So yes, please use




You are also totally right that this is related to networking and how stuff is synchronized and sent etc. I don't want to investigate this but I assume that clients receive and process your prespawn image spawn messages BEFORE they receive the message which starts the new round. Therefore the images are probably spawned but directly destroyed again due to the round restart on client side. So basically the order of execution is a bit different for clients. This is a special case because a new round / spawning triggers 3 different hooks but it's actually just one network message.
I never thought that much about this problem before but now it's very clear to me. I should probably update the documentation a bit

edited 4×, last 16.04.21 08:48:25 pm
@
DC: I decided to only use
startround_prespawn hook for things that relate to Lua only.
Anything that requires calling a CS2D function or sets anything in CS2D, will use the
startround hook.
That seems like a better approach.
I used to think that the
startround_prespawn hook was made for initialising everything, before the player spawn, but apparently it's even more strict than that and it should only be used for pure Lua execution that does not depend on CS2D (such as resetting variables, initialising tables, ETC.).
Thank you!


Anything that requires calling a CS2D function or sets anything in CS2D, will use the

That seems like a better approach.
I used to think that the

Thank you!
Look at me standing, here on my own again
This is probably the reason why network errors occur in my
Template Mod.


@
Pagyra: You better work with network packets instead of CS2D API.


Execution order when a new round starts:
auto team balance
adjust scores (depending on end of previous round)
free all dynamic objects
reset the map (clear items, reset entities, clear particles, run trigger start, spawn items/npcs/buildings)
run
startround_prespawn
clear old hostages & spawn new hostages
spawn players (and run
spawn for each right after spawning)
run
startround
reset/start bot AI
optionally trigger an automatic map change if conditions are met













I don't know where exactly to ask this, but is there a check to prevent the round from ending during that "initialising" phase?
Because just now, I think that I had a case where the round ended while it was initialising, and perhaps (probably) skipped the start round hooks.
Here's the video: Download
In that case, a player was auto team balanced, and a player died, the round ended twice in a row, before it fully started, under the same MVP and team winner.
That's really odd, I've never seen that happen, I don't even have simple

I suppose the player used

I really have no idea.
Look at me standing, here on my own again
I saw the problem there, easy to fix, its lua sided
CS2DBR @ Comunidade Brasileira de CS2D | https://cs2d.com.br
@
mrc: What do you mean?
I have three hooks:
endround - Ends all special events/rounds.
startround_prespawn - Resets all variables to default.
startround - Starts a new event/round.
Then how come were there two days on the same round?
I suspect some of the hooks may have been skipped.

I have three hooks:



Then how come were there two days on the same round?
I suspect some of the hooks may have been skipped.
Look at me standing, here on my own again
Really hard to tell what happened there. Do you have the server logs?
The full sequence I posted (which you just quoted) is basically atomic in the sense that it all happens in one frame/mainloop-iteration and can't be interrupted. At least it shouldn't be possible to interrupt it. Maybe if you do some really weird things in one of the hooks you might be able to break it somehow.
There is a delay of a few seconds between
endround and starting a new round though (where the outcome is displayed). Normally in that delay no new roundstart should be triggered but maybe it happened anyway for some reason. In that case it's possible that
endround was triggered multiple times but all the roundstart stuff (the quoted list) was just executed once.
The full sequence I posted (which you just quoted) is basically atomic in the sense that it all happens in one frame/mainloop-iteration and can't be interrupted. At least it shouldn't be possible to interrupt it. Maybe if you do some really weird things in one of the hooks you might be able to break it somehow.
There is a delay of a few seconds between


@
DC: I do have the server logs, but I don't recall them containing anything valuable.
Server logs doesn't countain rounds ending / starting messages and there weren't any errors.

Server logs doesn't countain rounds ending / starting messages and there weren't any errors.
Look at me standing, here on my own again
Oh okay. I guess I can't help then.
I would need a step by step instruction to reproduce it. And possibly the script as well or a sample script which shows the issue.
Don't get me wrong. I'm not asking for it because I really do NOT want to look into that issue
that's just what I would need to do so.
If it doesn't happen often I recommend to just ignore it...
I would need a step by step instruction to reproduce it. And possibly the script as well or a sample script which shows the issue.
Don't get me wrong. I'm not asking for it because I really do NOT want to look into that issue

If it doesn't happen often I recommend to just ignore it...

Perphaps on the next CS2D version, add a boolean check on that initialising check as such:
And then, when the game is trying to end, due to any reason, just check if
How's that? It should be quite easy to add, and prevent weird things like this from happening, at least I'd hope.
Also, this is quite a big script, reproducing it, is less than likely.
Code:
1
2
3
2
3
IS_STARTING = true
Run all startround initialising...
IS_STARTING = false
Run all startround initialising...
IS_STARTING = false
And then, when the game is trying to end, due to any reason, just check if
IS_STARTING
is not set to true in order to proceed.How's that? It should be quite easy to add, and prevent weird things like this from happening, at least I'd hope.
Also, this is quite a big script, reproducing it, is less than likely.
Look at me standing, here on my own again



