AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   Solved stack error (https://forums.alliedmods.net/showthread.php?t=332390)

lexzor 05-09-2021 12:17

stack error
 
hello. i Have this code:

PHP Code:

#define MAX_SKINS 9

enum _:TERO
{
    
szTModelName[256],
    
szTModelLocation[256],
    
szTModelPreview[256],
    
iTVIPOnly
}

if (
iFile)
    {
        new 
szData[256]
        new 
iSection
        
new szTempName[MAX_SKINS][256]
        new 
szTempLocation[MAX_SKINS][256]
        new 
szTempPreview[MAX_SKINS][256]
        new 
szTempVIP[MAX_SKINS][1]  
        new 
0

        iFilePointer 
fopen(g_szFile"rt")
        
        while(!
feof(iFilePointer))
        {
            
fgets(iFilePointerszDatacharsmax(szData))
            
trim(szData)
            
            if(
szData[0] == '#' || szData[0] == EOS || szData[0] == ';')
                continue
                
            if(
szData[0] == '[')
            {
                
iSection += 1
            
}
            
            switch(
iSection)
            {
                
                case 
TERO:
                {
                    if(
szData[0] != '[')
                    {
                        ++
i
                        
                        parse
(szDataszTempName[i-1], charsmax(szTempName[]), szTempLocation[i-1], charsmax(szTempLocation[]), szTempPreview[i-1], charsmax(szTempPreview[]), szTempVIP[i-1], charsmax(szTempVIP[]))
                        
formatex(g_TSkin[i-1][szTModelName], charsmax(g_TSkin[][szTModelName]),  szTempName[i-1])

                        
formatex(g_TSkin[i-1][szTModelLocation], charsmax(g_TSkin[][szTModelLocation]),  szTempLocation[i-1])

                        
formatex(g_TSkin[i-1][szTModelPreview], charsmax(g_TSkin[][szTModelPreview]),  szTempPreview[i-1])

                        
g_TSkin[i-1][iTVIPOnly] = str_to_num(szTempVIP[i-1])

                        
server_print("%s %s"g_TSkin[i-1][szTModelName], g_TSkin[i-1][szTModelLocation])
                        
server_print("%s %i"g_TSkin[i-1][szTModelPreview], g_TSkin[i-1][iTVIPOnly])
                    }
                }


and this is the error:
Code:

L 05/09/2021 - 19:12:31: [AMXX] Displaying debug trace (plugin "ceva.amxx", version "unknown")
L 05/09/2021 - 19:12:31: [AMXX] Run time error 3: stack error
L 05/09/2021 - 19:12:31: [AMXX]    [0] ceva.sma::plugin_precache (line 273)

line 273:
PHP Code:

new szTempName[MAX_SKINS][256

i tried to change variable size but wasn t enough..

some ideas ? I m doing same thing in same way in another plugin and it s working

Shadows Adi 05-09-2021 13:51

Re: stack error
 
You will get the same error on those lines too:
PHP Code:

        new szTempName[MAX_SKINS][256]
        new 
szTempLocation[MAX_SKINS][256]
        new 
szTempPreview[MAX_SKINS][256

because every variable has MAX_SKINS rows ( 9 ), each row has 256 lenght: 9 x 256 = 2304.
So, a stack error is thrown when you are declaring a big size variable locally, declare it globally and the error will disappear.
From my tests, I've discovered that you can declare a local variable with a maximum size of ~2100.

Edit: You don't need to assign that much size for just some locations and names, use 64 instead, should be more than enough

lexzor 05-09-2021 14:18

Re: stack error
 
Oh, thanks, i didn't know that! Solved.

Also, thank you for your reading files method from mvp plugin.


All times are GMT -4. The time now is 02:39.

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