Raised This Month: $51 Target: $400
 12% 

Forward for plugin end?


Post New Thread Reply   
 
Thread Tools Display Modes
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 01-22-2017 , 12:15   Re: Forward for plugin end?
Reply With Quote #21

Quote:
Originally Posted by Chdata View Post
This is why I don't bother to try contributing anything to the SM team
I'm not sure why you're trying to incite a flame war, but stop. The only comment in this thread from a member of the SM team in regards to any suggestions presented here is Fyren suggesting the ownership relationship is backwards (which is correct).

As for Plugin handles, the Handle documentation states:
Quote:
Plugin Handles should not be cached globally, as plugins can become unloaded, and the Handle will be invalid.
They should only be used within the forward they were retrieved (or passed as a parameter).

Trying to implement garbage collection into a language with no concept of destructors or finalizers and with explicit ownership is always going to be difficult - it was discussed back in 2009 and decided against for SM as a whole.

I see several viable paths forward for Dynamic:
  • Dynamic stops trying to save badly written plugins from leaking memory (removing the "garbage collector"), maintains ownership of objects it creates so that other plugins unloading does release Handles out from under it. I think everyone would consider this sane, anyone writing plugins knows not to leak their handles.
  • We add a way for plugins to register a new Handle type - with an associated destruction callback. This would allow Dynamic to be made aware when a plugin has unloaded, and encapsulate it's per-plugin resources in that Handle as well. Probably reasonable, would need a lot of discussion.
  • Expose IPluginListener to plugins so Dynamic can clean up its own state. Probably not going to happen, it is fragile for this use case and is generally counter to plugin interdependency design in SourceMod.
  • Make plugin handles cloneable, which would allow Dynamic to clone the plugin handles it caches and use them with at least GetPluginStatus after unload. I do not know how complex this would be to implement, but is probably the most likely option after "do nothing, change Dynamic".
__________________
asherkin is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 01-22-2017 , 12:35   Re: Forward for plugin end?
Reply With Quote #22

Quote:
Originally Posted by asherkin View Post
  • Expose IPluginListener to plugins so Dynamic can clean up its own state. Probably not going to happen, it is fragile for this use case and is generally counter to plugin interdependency design in SourceMod.
This option does exist in ExtraPLAPI, but the main purpose of the forwards was for getting pubvars when a plugin is loaded and setting the handles to null on plugin being unloaded (otherwise plugin would be referencing a freed handle).
__________________
WildCard65 is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 01-22-2017 , 17:41   Re: Forward for plugin end?
Reply With Quote #23

Quote:
Originally Posted by asherkin View Post
  • Dynamic stops trying to save badly written plugins from leaking memory (removing the "garbage collector"), maintains ownership of objects it creates so that other plugins unloading does release Handles out from under it. I think everyone would consider this sane, anyone writing plugins knows not to leak their handles.
I just want to clarify that Dynamic owns all of it's Handles. Plugins using Dynamic simply get an ArrayList index to a master ArrayList which stores the base object data.

Quote:
Plugin Handles should not be cached globally, as plugins can become unloaded, and the Handle will be invalid.
I'm breaking this.

As each Dynamic instance initialises, the calling plugin Handle parsed through the native is cached for persistence checks in the garbage collector.

This allows a plugin to load, generate a complex namespace/dataset and unload, while leaving persistent objects behind that wont be collected as garbage.
__________________
Neuro Toxin is offline
Fyren
FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren FyrenFyrenFyrenFyrenFyren
Join Date: Feb 2106
Old 01-22-2017 , 22:22   Re: Forward for plugin end?
Reply With Quote #24

What are you actually using the plugin handle for?
Fyren is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 01-22-2017 , 23:01   Re: Forward for plugin end?
Reply With Quote #25

OnMapEnd/OnLibraryRemoved
> loop dynamic objects
>> if plugin failed/errored/unloaded
>>> dispose object

Code is here

Edit:

line 246 has: dynamic.OwnerPlugin being parsed to GetPluginStatus
__________________

Last edited by Neuro Toxin; 01-22-2017 at 23:02.
Neuro Toxin is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 01-23-2017 , 00:34   Re: Forward for plugin end?
Reply With Quote #26

Been thinking could I request:

bool GetPluginStatusEx(Handle plugin, PluginStatus &status);

Returns true if status found, return false on invalid handle.
__________________
Neuro Toxin is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-23-2017 , 14:24   Re: Forward for plugin end?
Reply With Quote #27

It sounds like what you really need is the ability to call regpluginlibrary for another plugin.
This would be easy to do if a second arg were passed allowing for the plugin's handle to be specified...
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 01-23-2017 , 16:05   Re: Forward for plugin end?
Reply With Quote #28

Then I have the opposite problem of having to hook OnPluginStart so I can force registration.
__________________
Neuro Toxin is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 01-24-2017 , 05:17   Re: Forward for plugin end?
Reply With Quote #29

Quote:
Originally Posted by Neuro Toxin View Post
Then I have the opposite problem of having to hook OnPluginStart so I can force registration.
https://sm.alliedmods.net/api/index....d=show&id=583&
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Neuro Toxin
Veteran Member
Join Date: Oct 2013
Location: { closing the void; }
Old 01-25-2017 , 03:27   Re: Forward for plugin end?
Reply With Quote #30

Aftee lots of thinking and trying to resolve my base issue I believe this is my most elegant solution.

Can someone confirm if this is an easy thing to accomplish. I've been looking at source but dont have a clue.
__________________
Neuro Toxin is offline
Reply



Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -4. The time now is 16:04.


Powered by vBulletin®
Copyright ©2000 - 2024, vBulletin Solutions, Inc.
Theme made by Freecode