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

Solved Invalid CVAR pointer


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-17-2017 , 08:06   Invalid CVAR pointer
Reply With Quote #1

Error message:
Code:
L 12/17/2017 - 13:57:30: Invalid CVAR pointer
L 12/17/2017 - 13:57:30: [AMXX] Displaying debug trace (plugin "gpz_mk_vi.amxx")
L 12/17/2017 - 13:57:30: [AMXX] Run time error 10: native error (native "get_pcvar_num")
L 12/17/2017 - 13:57:30: [AMXX]    [0] aef3ocm2.sma.p::roundStart (line 1600)
PHP Code:
/*
    * NOTE: Pulled out part of reported error from code. There are more cvar definitions and the one in roundStart() only gives error.
*/
// Miscellaneous
#define ADMIN_CVARACCESS ADMIN_BAN

// Created the var
new g_clearShells;

// Defined the var
public plugin_init()
{
       
register_logevent("roundStart"2"0=World triggered""1=Round_Start");

       
g_clearShells register_cvar("tm_clear_shells""1"ADMIN_CVARACCESS);
}

public 
roundStart()
{
    if(!
g_restartRound)
    {
        
server_cmd("sv_restartround 1");
        
g_restartRound true;
    }
    
    if(
get_pcvar_num(g_clearShells) > 0// <-- Reported in console
    
{
        new 
ent = -1;
        
        while((
ent find_ent_by_class(ent"ashell")))
        {
            if(
is_valid_ent(ent))
                
remove_entity(ent);
        }
    }

What am I missing?

Last edited by redivcram; 12-20-2017 at 12:53.
redivcram is offline
E1_531G
Senior Member
Join Date: Dec 2017
Old 12-17-2017 , 08:18   Re: Invalid CVAR pointer
Reply With Quote #2

https://www.amxmodx.org/api/cvars/register_cvar

Flags for Cvar are not ADMIN_* flags.
__________________
My English is A0
E1_531G is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-17-2017 , 08:25   Re: Invalid CVAR pointer
Reply With Quote #3

Quote:
Originally Posted by E1_531G View Post
https://www.amxmodx.org/api/cvars/register_cvar

Flags for Cvar are not ADMIN_* flags.
I pulled out needed code from the original, didn't post the full code, don't think It's needed anymore. (Edited first post).

Every other cvar has the same 3rd parameter and has no such problem. This one in roundStart() is only troubling.
redivcram is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 12-17-2017 , 08:39   Re: Invalid CVAR pointer
Reply With Quote #4

Quote:
Originally Posted by redivcram View Post
I pulled out needed code from the original, didn't post the full code, don't think It's needed anymore. (Edited first post).
That's bad. Maybe your plugin_init() isn't finishing its execution since there is a runtime error in it and because of that your cvar doesn't get registered.

Quote:
Originally Posted by redivcram View Post
Every other cvar has the same 3rd parameter and has no such problem. This one in roundStart() is only troubling.
It doesn't matter, with ADMIN_BAN you are actually passing in FCVAR_EXTDLL which is already set for your cvar. You just got lucky here, you should always pass a value that parameter expects. Use FCVAR_* flags there, not ADMIN_* flags.
__________________

Last edited by klippy; 12-17-2017 at 08:39.
klippy is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-17-2017 , 09:28   Re: Invalid CVAR pointer
Reply With Quote #5

Ohhhh, I totally misunderstood the 3rd parameter for all these years lol. I removed 3rd parameters in each cvar definition and still get the same error, though.
redivcram is offline
OciXCrom
Veteran Member
Join Date: Oct 2013
Location: Macedonia
Old 12-17-2017 , 10:22   Re: Invalid CVAR pointer
Reply With Quote #6

Then the error is somewhere else. Maybe something in plugin_init() is wrong and the function stops before reaching the register_cvar() function.
__________________
OciXCrom is offline
Send a message via Skype™ to OciXCrom
siriusmd99
Veteran Member
Join Date: Oct 2013
Location: Republic of Moldova
Old 12-20-2017 , 05:43   Re: Invalid CVAR pointer
Reply With Quote #7

Maybe you accidentally modified g_clearShells pointer somewhere in your code and now it's not a cvar pointer anymore. Use ctrl+ f and try to find maybe you accidentally used it somewhere else.
siriusmd99 is offline
redivcram
Veteran Member
Join Date: Jul 2014
Location: Serbia
Old 12-20-2017 , 12:52   Re: Invalid CVAR pointer
Reply With Quote #8

Came across a post by accident. They say defining cvars should be above registering forwards, events, etc.
Did so and everything works fine now.

@siriusmd99

I always check my codes like that. The search option is a good friend.
redivcram 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 16:53.


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