Closed JoinedSenses closed 5 years ago
Yes - this bit of confusing design came from the original built-in implementation of tf2items_manager, as it pre-creates all the override handles when parsing the config file. The normal SM handle ownership rules apply, your plugin creates the handle and TF2Items_OnGiveNamedItem
isn't explicitly documented as taking ownership so it is your plugin's responsibility to delete the handle. A common approach is to store the handle globally and free it on the next call to TF2Items_OnGiveNamedItem
, but a timer should work fine.
How long should the timer wait before freeing the handle? Would there be a problem if it inadvertently frees it before the next call to TF2Items_OnGiveNamedItem
?
It doesn't matter, the contents of the handle is only used by the code invoking the forward, so as the VM is single-threaded, by the time anything can call into SourcePawn again it is safe to delete it.
Good to know, thanks!
https://github.com/asherkin/TF2Items/blob/d81b0ff7e98b197431ff13f1a16a6989c5ae2032/extension/extension.cpp#L184
Is it intentional that the extension does not free the handle of the overridden item during
TF2Items_OnGiveNamedItem
? There isn't any documentation on the intentions here. My workaround is to create a timer and free the handle: