Raised This Month: $ Target: $400
 0% 

Stack error with hook_cvar_change


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
addicted2sex
Senior Member
Join Date: May 2009
Location: localhost
Old 12-26-2015 , 20:17   Re: Stack error with hook_cvar_change
Reply With Quote #1

Quote:
Originally Posted by luxor View Post
hello, i receive stack error when i'm trying to set any value for rcon_password.
what i was doing wrong ?

Code:
#include <amxmisc>

#if AMXX_VERSION_NUM < 183 
    #assert AMX Mod X v1.8.3 or later library required!
#endif 

public plugin_init()
{
	register_plugin
	(
		.plugin_name = "Block changing rcon_password",
		.version     = "1.0",
		.author      = "lüxor"
	);
	
	hook_cvar_change(get_cvar_pointer("rcon_password"), "setDefaultValue");
}

public setDefaultValue(PointerCvar, const OldValue[], const NewValue[])
{
	set_pcvar_string(PointerCvar, OldValue);
}

Console :
Code:
] restart
Server logging data to file logs\L1227013.log
L 12/27/2015 - 01:11:05: -------- Mapchange to de_dust2 --------
[AMXX] Loaded 1 admin from file
Executing AMX Mod X Configuration File 
Scrolling message displaying frequency: 10:00 minutes
] rcon_password
"rcon_password" is "123"
] rcon_password meow
L 12/27/2015 - 01:12:02: [AMXX] Displaying debug trace (plugin "block_changing_rcon_pass.amxx", version "1.0")
L 12/27/2015 - 01:12:02: [AMXX] Run time error 3: stack error
Because you're changing the cvar itself when it is changed. The situation is the following:
  • "rcon_password" is changed to "meow"
  • setDefaultValue() is called
  • setDefaultValue is setting "rcon_password" to the old value and because of the change setDefaultValue() is called again

because of that an "infinite recursion" appears and the stack overflows
__________________
Let 7he gr0ovE r3Lease y0ur m!nd

Last edited by addicted2sex; 12-26-2015 at 20:32.
addicted2sex 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 17:52.


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