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

Solved Problem with Natives related to plugin loading order


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 04-10-2017 , 02:02   Problem with Natives related to plugin loading order
Reply With Quote #1

Been hitting my head on the wall for a while now and I finally figured it out.

To start off:
* I have two plugins, called Plugin1 and Plugin2 with filenames Plugin1.smx and Plugin2.smx respectively.
* Each plugin has one native, called Native1 and Native2 respectively, and both natives are created in AskPluginLoad2.
* Plugin1 is loaded before Plugin2 according to the order of "sm plugins list."

How both plugins work:
  1. In Plugin1's AllPluginStart, Native2 is called
  2. Then in Plugin2, Native2's callback is called, which then calls Native1
  3. An error emerges from Plugin2 stating that Native1 "Native is not bound"
  4. Shut down the server
* The next change is done to change the order at which the plugins load. From my testing, SM loads plugins based on aphabetic order (or as far as I could tell)
  1. Rename Plugin1's file from Plugin1 to Plugin4
  2. Rename Plugin2's file to Plugin3
  3. Restart the server
  4. Both plugins now work correctly


Now I do not know why this even happens in the first place, however, should it really happen? I mean we have no documentation about the importance of the order of the loaded plugins.

Also is there a way to actually fix this so that the load order does not matter for both plugins?

To affirm, I am using the latest SM stable build, and I have also tried the same thing with the latest dev build and the results were the same either way. I also checked the compiler version. I was also using a CSGO dedicated server.

From my own tests:
Errors


Logs


plugins
Attached Files
File Type: sp Get Plugin or Get Source (test1.sp - 332 views - 1.4 KB)
File Type: sp Get Plugin or Get Source (test2.sp - 306 views - 1.3 KB)
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.

Last edited by pokemonmaster; 04-10-2017 at 15:16. Reason: solved.
pokemonmaster is offline
sdz
Senior Member
Join Date: Feb 2012
Old 04-10-2017 , 02:27   Re: Problem with Natives related to plugin loading order
Reply With Quote #2

Make sure you're exposing your plugins API and marking natives as optional, I had this issue with one of my plugins when I first started working with natives

https://wiki.alliedmods.net/Creating...eMod_Scripting)

furthermore make sure you have these in your include files (obviously replacing coldshop with what you use in RegPluginLibrary:
PHP Code:
#if defined _coldshop_included_
  #endinput
#endif
#define _coldshop_included_

public void __pl_coldshop_SetNTVOptional()
{
    
MarkNativeAsOptional("GetClientRank");
    
MarkNativeAsOptional("GetClientPoints");
    
MarkNativeAsOptional("GetClientSubscription");

    
MarkNativeAsOptional("SetClientRank");
    
MarkNativeAsOptional("SetClientPoints");
    
MarkNativeAsOptional("SetClientSubscription");
}

//and

public SharedPlugin __pl_coldshop =
{
    
name "coldshop",
    
file "cold_store.smx",
//    #if defined REQUIRE_PLUGIN
//        required = 1,
//    #else
        
required 0,
//    #endif
}; 

Last edited by sdz; 04-10-2017 at 02:31.
sdz is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 04-10-2017 , 06:47   Re: Problem with Natives related to plugin loading order
Reply With Quote #3

Quote:
Originally Posted by pokemonmaster View Post
  1. In Plugin1's AllPluginStart, Native2 is called
You need to be calling the native in OnAllPluginsLoaded, not OnPluginStart as your current code is doing.

Quote:
Originally Posted by pokemonmaster View Post
From my testing, SM loads plugins based on aphabetic order (or as far as I could tell)
Load order is undefined, if you are treating it as anything other than random you will get bitten in the ass by it.
SourceMod has 2-pass plugin loading, hence the importance of AskPluginLoad2 and OnAllPluginsLoaded for plugin inter-dependency (especially as you have a circular dependency here).
__________________
asherkin is offline
pokemonmaster
princess milk
Join Date: Nov 2010
Location: Somewhere in this world
Old 04-10-2017 , 15:16   Re: Problem with Natives related to plugin loading order
Reply With Quote #4

Quote:
Originally Posted by asherkin View Post
You need to be calling the native in OnAllPluginsLoaded, not OnPluginStart as your current code is doing.
Thanks. I didn't even thinking about using OnAllPluginsLoaded in the first place. seems like I'm still stuck to habits from AMXX.

Quote:
Load order is undefined, if you are treating it as anything other than random you will get bitten in the ass by it.
SourceMod has 2-pass plugin loading, hence the importance of AskPluginLoad2 and OnAllPluginsLoaded for plugin inter-dependency (especially as you have a circular dependency here).
Got it. Thank again.
__________________
اَشْهَدُ اَنْ لَّآ اِلٰهَ اِلَّا اللہُ وَحْدَه لَا شَرِيْكَ لَه وَ اَشْهَدُ اَنَّ مُحَمَّدًا عَبْدُه وَرَسُوْلُه
No longer active in AMXX. Sorry.
pokemonmaster 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 20:53.


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