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

Solved Stack Error?


Post New Thread Reply   
 
Thread Tools Display Modes
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-24-2018 , 07:59   Re: Stack Error?
Reply With Quote #11

"static" on global variables (and functions) means their scope is restricted to file scope, meaning you can't use them outside of the file that declared them.

Also, seeing that locals in that function take only 16 bytes, I'm sure there's something else that's wrong.
Does it happen every time that function gets called or is it random? What is g_iPlayerTeam? You are missing many things that the posted code references.

You should cut your plugin to the minimum possible amount of code that's able to reproduce that issue so we can test it out.
__________________

Last edited by klippy; 02-24-2018 at 08:05.
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-24-2018 , 09:36   Re: Stack Error?
Reply With Quote #12

Quote:
Originally Posted by KliPPy View Post
"static" on global variables (and functions) means their scope is restricted to file scope, meaning you can't use them outside of the file that declared them.

Also, seeing that locals in that function take only 16 bytes, I'm sure there's something else that's wrong.
Does it happen every time that function gets called or is it random? What is g_iPlayerTeam? You are missing many things that the posted code references.

You should cut your plugin to the minimum possible amount of code that's able to reproduce that issue so we can test it out.
It happens randomly, but says it happens in Ham_Spawn, which can't be, because Ham_Spawn is called just at player spawn.

g_iPlayerTeam is an array used for new player teams
PHP Code:
#define MAX_PLAYERS 32

static Float:g_fTeamGlowMAX_PLAYERS ][ ];

new 
g_iPlayerTeamMAX_PLAYERS ];

public 
fw_HamSpawnPostid )
{
    if( 
g_iPlayerTeamid ] != NO_TEAM )
    {
        new 
Float:fRender];
        
pevidpev_rendercolorfRender );

        new 
iTeam g_iPlayerTeamid ];
        
        if( ( 
fRender] != g_fTeamGlowiTeam ][ ] ) || ( fRender] != g_fTeamGlowiTeam ][ ] ) || ( fRender] != g_fTeamGlowiTeam ][ ] ) )
        {
            
set_user_renderingidkRenderFxGlowShellfloatroundg_fTeamGlowiTeam ][ ] ), floatroundg_fTeamGlowiTeam ][ ] ), floatroundg_fTeamGlowiTeam ][ ] ), kRenderNormal30 );
        }
    }
    return 
HAM_IGNORED;
}

public 
OnNewRound( )
{
    for( new 
iTeam=1iTeam <= g_iMaxTeamsiTeam++ )
    {
        
g_fTeamGlowiTeam ][ ] = random_float0.0255.0 );
        
g_fTeamGlowiTeam ][ ] = random_float0.0255.0 );
        
g_fTeamGlowiTeam ][ ] = random_float0.0255.0 );
    }

    new 
szPlayers32 ], iNum;
    
get_playersszPlayersiNum"a" );

    static 
iTempID;
    for( new 
iiNumi++ )
    {
        
iTempID szPlayers];
        
        
set_user_renderingiTempIDkRenderFxGlowShellfloatroundg_fTeamGlowg_iPlayerTeamiTempID ] ][ ] ), floatroundg_fTeamGlowg_iPlayerTeamiTempID ] ][ ] ), floatroundg_fTeamGlowg_iPlayerTeamiTempID ] ][ ] ), kRenderNormal30 );
        
        if( 
g_iPlayerTeamiTempID ] == NO_TEAM && get_user_teamiTempID ) != )
        {
            
FindAvailableTeamiTempID );
        }
    }
}

FindAvailableTeamid )
{
    for( new 
iTeam=1iTeam <= g_iMaxTeamsiTeam++ )
    {
        if( 
IsTeamAvailableiTeam ) )
        {
            
g_iPlayerTeamid ] = iTeam;
            
g_iTeammatesiTeam ]++;
            
            break;
        }
        continue;
    }
}

IsTeamAvailableiTeam )
{
    return 
g_iTeammatesiTeam ] < g_iPlayerPerTeam 0;

__________________
edon1337 is offline
Clauu
Senior Member
Join Date: Feb 2008
Location: RO
Old 02-24-2018 , 19:56   Re: Stack Error?
Reply With Quote #13

Regarding your case there is no point using static for Float:g_fTeamGlow
Leave it static only for Float:fRender[ 3 ], iTeam and maybe szPlayers[ 32 ], iNum depending how often that function will be called.
Code:
if( ( fRender[ 0 ] != g_fTeamGlow[ iTeam ][ 0 ] ) || ( fRender[ 1 ] != g_fTeamGlow[ iTeam ][ 1 ] ) || ( fRender[ 2 ] != g_fTeamGlow[ iTeam ][ 2 ] ) )
Are you sure that this is line 124?
Clauu is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-24-2018 , 20:37   Re: Stack Error?
Reply With Quote #14

Quote:
You should cut your plugin to the minimum possible amount of code that's able to reproduce that issue so we can test it out.
__________________
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-25-2018 , 19:21   Re: Stack Error?
Reply With Quote #15

What I posted before was the literal minimum code.

PHP Code:
#include < amxmodx >
#include < hamsandwich >
#include < fakemeta >
#include < fun >

#define MAX_PLAYERS 32
#define NO_TEAM 0

new g_iPlayerPerTeam;
new 
g_iMaxTeams;

new 
g_iTeammatesMAX_PLAYERS ];
new 
g_iPlayerTeamMAX_PLAYERS ];

new 
Float:g_fTeamGlowMAX_PLAYERS ][ ];

new 
HamHook:g_iHamTakeDamageFw;

public 
plugin_init( )
{
    
register_plugin"CS Battle Royale Fake Teams""1.0""DoNii" );
    
    
register_event"HLTV""OnNewRound""a""1=0""2=0" ) ;
    
    
RegisterHamHam_TakeDamage"player""fw_HamSpawnPost");
    
    
g_iHamTakeDamageFw RegisterHamHam_TakeDamage"player""fw_HamTakeDamagePre");
    
DisableHamForwardg_iHamTakeDamageFw );
}

public 
plugin_cfg( )
{
    
EnableHamForwardg_iHamTakeDamageFw );
}

public 
client_disconnectid )
{
    if( 
g_iPlayerTeamid ] != NO_TEAM )
    {
        
g_iTeammatesg_iPlayerTeamid ] ]--;
        
g_iPlayerTeamid ] = NO_TEAM;
    }
    
g_iPlayerTeamid ] = NO_TEAM;
}

public 
client_connectid )
{
    
g_iPlayerTeamid ] = NO_TEAM;
    
FindAvailableTeamid );
}

public 
fw_HamSpawnPostid )
{
    if( ! 
is_user_aliveid ) )
    return 
HAM_IGNORED;

    if( 
g_iPlayerTeamid ] != NO_TEAM )
    {
        static 
Float:fRender];
        
pevidpev_rendercolorfRender );

        static 
iTeam;
        
iTeam g_iPlayerTeamid ];
        
        if( ( 
fRender] != g_fTeamGlowiTeam ][ ] ) || ( fRender] != g_fTeamGlowiTeam ][ ] ) || ( fRender] != g_fTeamGlowiTeam ][ ] ) )
        {
            
set_user_renderingidkRenderFxGlowShellfloatroundg_fTeamGlowiTeam ][ ] ), floatroundg_fTeamGlowiTeam ][ ] ), floatroundg_fTeamGlowiTeam ][ ] ), kRenderNormal30 );
        }
    }
    return 
HAM_IGNORED;
}

public 
fw_HamTakeDamagePreiVictimiInflictoriAttackerFloat:fDamageiDamageBits )
{    
    if( 
iVictim == iAttacker )
    return 
HAM_IGNORED;

    if( 
g_iPlayerTeamiVictim ] != g_iPlayerTeamiAttacker ] )
    {
        
ExecuteHamBHam_TakeDamageiVictimiInflictoriAttackerfDamageiDamageBits );
    }
    return 
HAM_SUPERCEDE;
}

public 
OnNewRound( )
{
    for( new 
iTeam=1iTeam <= g_iMaxTeamsiTeam++ )
    {
        
g_fTeamGlowiTeam ][ ] = random_float0.0255.0 );
        
g_fTeamGlowiTeam ][ ] = random_float0.0255.0 );
        
g_fTeamGlowiTeam ][ ] = random_float0.0255.0 );
    }

    static 
szPlayers32 ], iNum;
    
get_playersszPlayersiNum"a" );

    static 
iTempID;
    for( new 
iiNumi++ )
    {
        
iTempID szPlayers];
        
        
set_user_renderingiTempIDkRenderFxGlowShellfloatroundg_fTeamGlowg_iPlayerTeamiTempID ] ][ ] ), floatroundg_fTeamGlowg_iPlayerTeamiTempID ] ][ ] ), floatroundg_fTeamGlowg_iPlayerTeamiTempID ] ][ ] ), kRenderNormal30 );
        
        if( 
g_iPlayerTeamiTempID ] == NO_TEAM && ( get_user_teamiTempID ) == || get_user_teamiTempID ) == ) )
        {
            
FindAvailableTeamiTempID );
        }
    }
}

FindAvailableTeamid )
{
    for( new 
iTeam=1iTeam <= g_iMaxTeamsiTeam++ )
    {
        if( 
IsTeamAvailableiTeam ) )
        {
            
g_iPlayerTeamid ] = iTeam;
            
g_iTeammatesiTeam ]++;
            
            break;
        }
        continue;
    }
}

IsTeamAvailableiTeam )
{
    return 
g_iTeammatesiTeam ] < g_iPlayerPerTeam 0;

Fun fact it's not even showing me the line where the error is anymore, I realised it happens when I shoot at someone, but not sure whether that's the issue, I see nothing wrong with Ham_TakeDamage.
Quote:
L 02/26/2018 - 01:14:20: [AMXX] Displaying debug trace (plugin "CsBattleRoyaleFakeTeams.amxx")
L 02/26/2018 - 01:14:20: [AMXX] Run time error 3: stack error
__________________

Last edited by edon1337; 02-25-2018 at 19:21.
edon1337 is offline
Th3822
Member
Join Date: Jan 2013
Location: Venezuela
Old 02-25-2018 , 21:27   Re: Stack Error?
Reply With Quote #16

It looks like the issue is the recursion on the Ham_TakeDamage hook
it seems that you are trying to block damage incorrectly and in that code you call Ham_TakeDamage again with ExecuteHamB, so it does call all plugin's Ham_TakeDamage hooks again, repeating over and over again...

There is a warning about that on the .inc:
Quote:
Originally Posted by hamsandwich.inc
/**
* Executes the virtual function on the entity, this will trigger all hooks on that function.
* Be very careful about recursion!
* Look at the Ham enum for parameter lists.
*
* @param function The function to call.
* @param id The id of the entity to execute it on.
*/
native ExecuteHamB(Ham:function, this, any:...);
after looking at your code, there is no reason to calling Ham_TakeDamage again just to "allow" the damage, try using this:
PHP Code:
public fw_HamTakeDamagePreiVictimiInflictoriAttackerFloat:fDamageiDamageBits )
{
    if ( 
iVictim != iAttacker && g_iPlayerTeamiVictim ] == g_iPlayerTeamiAttacker ] )
    {
        return 
HAM_SUPERCEDE;
    }
    return 
HAM_IGNORED;

Th3822 is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-26-2018 , 05:11   Re: Stack Error?
Reply With Quote #17

Quote:
Originally Posted by Th3822 View Post
It looks like the issue is the recursion on the Ham_TakeDamage hook
it seems that you are trying to block damage incorrectly and in that code you call Ham_TakeDamage again with ExecuteHamB, so it does call all plugin's Ham_TakeDamage hooks again, repeating over and over again...

There is a warning about that on the .inc:


after looking at your code, there is no reason to calling Ham_TakeDamage again just to "allow" the damage, try using this:
PHP Code:
public fw_HamTakeDamagePreiVictimiInflictoriAttackerFloat:fDamageiDamageBits )
{
    if ( 
iVictim != iAttacker && g_iPlayerTeamiVictim ] == g_iPlayerTeamiAttacker ] )
    {
        return 
HAM_SUPERCEDE;
    }
    return 
HAM_IGNORED;

I'm not trying to block the damage, I'm trying to produce it.
What I want to do:
Code:
public fw_HamTakeDamagePre( iVictim, iInflictor, iAttacker, Float:fDamage, iDamageBits ) {     if( g_iPlayerTeam[ iVictim ] != g_iPlayerTeam[ iAttacker ] ) // enemies     {         // allow damage (doesnt matter whether they are both CT or T) you can't just return HAM_SUPERCEDE if they are both T or CT     }     return HAM_SUPERCEDE; // block friendlyfire }
__________________

Last edited by edon1337; 02-26-2018 at 05:12.
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-26-2018 , 05:16   Re: Stack Error?
Reply With Quote #18

Why not just let it the original call pass through instead of replicating it? That's exactly what Th3822's code does and is what you are trying to do.
__________________
klippy is offline
edon1337
Penguin Enthusiast
Join Date: Jun 2016
Location: Macedonia
Old 02-26-2018 , 06:09   Re: Stack Error?
Reply With Quote #19

Quote:
Originally Posted by KliPPy View Post
Why not just let it the original call pass through instead of replicating it? That's exactly what Th3822's code does and is what you are trying to do.
How is it what I'm asking for if all he's doing is returning HAM_IGNORED?
__________________
edon1337 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 02-26-2018 , 06:24   Re: Stack Error?
Reply With Quote #20

Quote:
Originally Posted by edon1337 View Post
How is it what I'm asking for if all he's doing is returning HAM_IGNORED?
Exactly. If you want to allow damage (as the comment in your previous post states) then all you have to do is return HAM_IGNORED.
__________________
klippy 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 08:49.


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