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

SDK_OnAllLoaded fires twice


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 08-02-2016 , 04:55   SDK_OnAllLoaded fires twice
Reply With Quote #1

I have a problem with this function.
PHP Code:
void ExtTest::SDK_OnAllLoaded()
{
    
SM_GET_LATE_IFACE(SDKHOOKSg_pSDKHooks);
    if (
g_pSDKHooks != NULL)
    {
        
g_pSM->LogMessage(myself"SDK_OnAllLoaded");    
        
g_pSDKHooks->AddEntityListener(&entlistener);
    }

This function fires when the extension is loaded and after mapchange. g_p SDKHooks doesn't check duplicate listeners, and I have to check it manually, or my server crashes after unloading the extension. The point is that the example extenson doesn't have such check, I mean this one: sourcemod-master\extensions\tf2 .So I'm a bit confused. It's either my mistake, or there is a bug in the tf2 extension.

Related question - can I move g_pSDKHooks->AddEntityListener(&entlistener) to the SDK_OnLoad function? or there will be consequences

Last edited by kadet.89; 08-02-2016 at 04:57.
kadet.89 is offline
Send a message via Skype™ to kadet.89
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 08-02-2016 , 06:55   Re: SDK_OnAllLoaded fires twice
Reply With Quote #2

Yes, you can request interface pointers in SDK_OnLoad, the following things should be noted:

1) Getting interface pointers in SDK_OnAllLoaded generally mean optional dependency
2) Getting interface pointers in SDK_OnLoad is generally paired with a call to sharesys->AddDependency (before interface request)
3) SM_GET_IFACE is usable only in SDK_OnLoad and is used to get required dependencies (see point 2 for pre-requisite)
4) SM_GET_LATE_IFACE is used generally for optional dependencies (hence best used in SDK_OnAllLoaded)
__________________

Last edited by WildCard65; 08-02-2016 at 06:55.
WildCard65 is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 08-02-2016 , 10:55   Re: SDK_OnAllLoaded fires twice
Reply With Quote #3

Looks like there might be a bug, but it would only affect late-loaded extensions.

https://github.com/alliedmodders/sou....cpp#L305-L309

Should possibly be calling this->MarkAllLoaded() instead of m_pAPI->OnExtensionsAllLoaded().
__________________
asherkin is offline
kadet.89
Veteran Member
Join Date: Nov 2012
Location: Serbia
Old 08-03-2016 , 05:32   Re: SDK_OnAllLoaded fires twice
Reply With Quote #4

WildCard65, thanks, it works!
asherkin, You are right, the function fires only once if the extension is loaded by *.autoloader

Last edited by kadet.89; 08-03-2016 at 05:35.
kadet.89 is offline
Send a message via Skype™ to kadet.89
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 02:54.


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