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:
In Plugin1's AllPluginStart, Native2 is called
Then in Plugin2, Native2's callback is called, which then calls Native1
An error emerges from Plugin2 stating that Native1 "Native is not bound"
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)
Rename Plugin1's file from Plugin1 to Plugin4
Rename Plugin2's file to Plugin3
Restart the server
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
Code:
L 04/10/2017 - 01:38:07: SourceMod error session started
L 04/10/2017 - 01:38:07: Info (map "de_dust2") (file "errors_20170410.log")
L 04/10/2017 - 01:38:07: [SM] Exception reported: Native is not bound
L 04/10/2017 - 01:38:07: [SM] Blaming: test2.smx
L 04/10/2017 - 01:38:07: [SM] Call stack trace:
L 04/10/2017 - 01:38:07: [SM] [1] TestNative_FirstNative
L 04/10/2017 - 01:38:07: [SM] [2] Line 34, C:\Users\Khaled\Desktop\test2.sp::TestNative_SecondTest
L 04/10/2017 - 01:38:07: [SM] [4] TestNative_SecondNative
L 04/10/2017 - 01:38:07: [SM] [5] Line 42, C:\Users\Khaled\Desktop\test1.sp::OnPluginStart
L 04/10/2017 - 01:38:07: [SM] Unable to load plugin "test1.smx": Error detected in plugin startup (see error logs)
L 04/10/2017 - 01:38:07: [SM] Unable to load plugin "test2.smx": Native "TestNative_FirstNative" was not found
L 04/10/2017 - 01:38:20: Error log file session closed.
Logs
Code:
L 04/10/2017 - 01:38:07: -------- Mapchange to de_dust2 --------
L 04/10/2017 - 01:38:07: [test1.smx] First Plugin [APL]: Feature Status: 1 .. 2
L 04/10/2017 - 01:38:07: [test2.smx] Second Plugin [APL]: Feature Status: 2 .. 1
L 04/10/2017 - 01:38:07: [test1.smx] First Plugin [OnPluginStart]: Feature Status: 1 .. 0
L 04/10/2017 - 01:38:07: [test2.smx] Second Native Called Correctly
L 04/10/2017 - 01:38:20: Log file closed.
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
You need to be calling the native in OnAllPluginsLoaded, not OnPluginStart as your current code is doing.
Quote:
Originally Posted by pokemonmaster
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).
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.