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

[SOLVED] Unintended bug/ Hookevent calling callbacks


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 03-20-2015 , 00:11   [SOLVED] Unintended bug/ Hookevent calling callbacks
Reply With Quote #1

I believe there may be a bug with sm 1.6.4+ that is causing a lot of problems with plugins hooking events, but i'm not 100% sure,

It seems that any time a plugin is loaded from server boot / when sourcemod is starting up, hookevent will call the callback it is hooking. If it stack traces there, well.. since it's usually in OnPluginStart, very bad things will happen (like nothing will get initialized). Reloading the plugin later, does not exhibit this behavior. This happens for me a lot because I usually call my hookevents right after I register my convars, and then I allocate my arrays. I do not intend for hookevent to call the events (like round start or whatever):

I tested with this:
Spoiler


From server start:
Spoiler


From reload:
Spoiler
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.

Last edited by friagram; 03-20-2015 at 01:43.
friagram is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-20-2015 , 00:55   Re: Unintended bug/ Hookevent calling callbacks
Reply With Quote #2

You're a little off the mark, MaxClients isn't initialised until you're in OnMapStart, so your plugin is never initialising the array when loaded at server start. You just need to move your loop, OnMapStart is always called even for late-loaded plugin (which is why the late-load works, MaxClients has already been initialised).

EDIT: It's always worked this way.
__________________

Last edited by asherkin; 03-20-2015 at 00:57.
asherkin is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 03-20-2015 , 01:14   Re: Unintended bug/ Hookevent calling callbacks
Reply With Quote #3

On late load maxclients is set properly, and used to work (i think) ?
It will anyways now.

In this situation I would only need the array initialized once, so if onpluginstart is too early I would have to use onallpluginsloaded or something.

Also, if you look at the debug, event round start is being called (why is it even being called?), this is causing the stack trace.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Dr. Greg House
Professional Troll,
Part-Time Asshole
Join Date: Jun 2010
Old 03-20-2015 , 01:22   Re: Unintended bug/ Hookevent calling callbacks
Reply With Quote #4

Because waitingforplayers.
__________________
Santa or Satan?

Watch out when you're paying people for private requests! Most stuff already exists and you can hardly assess the quality of what you'll get, and if it's worth the money.
Dr. Greg House is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 03-20-2015 , 01:30   Re: Unintended bug/ Hookevent calling callbacks
Reply With Quote #5

If it's waitingforplayers causing it to fire (before the map loads during plugin start right when I hook it) that is odd behavior).
Anyways, its not a big problem, i can just allocate the array to a static value in this situation
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
asherkin
SourceMod Developer
Join Date: Aug 2009
Location: OnGameFrame()
Old 03-20-2015 , 10:43   Re: [SOLVED] Unintended bug/ Hookevent calling callbacks
Reply With Quote #6

Not OnPluginStart, not OnAllPluginsLoaded, OnMapStart.
OnMapStart is where MaxClients is guaranteed to be initialised.
OnMapStart is the first time you can use it.

It does indeed work before that on a late load, that's because the hook backing OnMapStart has (obviously) already happened, SourceMod is just triggering OnMapStart in your plugin on late load so you can always use it for exactly this purpose.

The behaviour of game events is not affected by SourceMod, it is all up to the game. WFP is indeed considered the first round in TF2.
__________________

Last edited by asherkin; 03-20-2015 at 10:43.
asherkin is offline
WildCard65
Veteran Member
Join Date: Aug 2013
Location: Canada
Old 03-20-2015 , 13:39   Re: [SOLVED] Unintended bug/ Hookevent calling callbacks
Reply With Quote #7

Quote:
Originally Posted by asherkin View Post
Not OnPluginStart, not OnAllPluginsLoaded, OnMapStart.
OnMapStart is where MaxClients is guaranteed to be initialised.
OnMapStart is the first time you can use it.

It does indeed work before that on a late load, that's because the hook backing OnMapStart has (obviously) already happened, SourceMod is just triggering OnMapStart in your plugin on late load so you can always use it for exactly this purpose.

The behaviour of game events is not affected by SourceMod, it is all up to the game. WFP is indeed considered the first round in TF2.
I think I noticed that behaviour of tf2 and events in ff2.
__________________
WildCard65 is offline
friagram
Veteran Member
Join Date: Sep 2012
Location: Silicon Valley
Old 03-20-2015 , 14:13   Re: [SOLVED] Unintended bug/ Hookevent calling callbacks
Reply With Quote #8

It's probably just a case of me never having to initialize client variables that early before, usually i'd do it later on client connect or round start. Anyways, I can just set the array to initialize to like 36 or somesuch number that will always be greater than tf2s maxclient possible count.
__________________
Profile - Plugins
Add me on steam if you are seeking sp/map/model commissions.
friagram is offline
Mathias.
Veteran Member
Join Date: Aug 2010
Location: Canada is my city
Old 03-20-2015 , 16:42   Re: [SOLVED] Unintended bug/ Hookevent calling callbacks
Reply With Quote #9

Quote:
Originally Posted by friagram View Post
It's probably just a case of me never having to initialize client variables that early before, usually i'd do it later on client connect or round start. Anyways, I can just set the array to initialize to like 36 or somesuch number that will always be greater than tf2s maxclient possible count.
do you not listen to what people wrote you?
Mathias. 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 23:16.


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