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

Solved stack error


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-09-2021 , 12:17   stack error
Reply With Quote #1

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

Last edited by lexzor; 05-09-2021 at 14:18.
lexzor is offline
Shadows Adi
AlliedModders Donor
Join Date: Aug 2019
Location: Romania
Old 05-09-2021 , 13:51   Re: stack error
Reply With Quote #2

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
__________________


Accepting Paid Requests, contact PM.

MVP Of The Round View project on GITHUB / AlliedModders
CSGO REMAKE ~ CSGO MOD [STABLE + SOURCE CODE]

Last edited by Shadows Adi; 05-09-2021 at 13:53.
Shadows Adi is offline
lexzor
Veteran Member
Join Date: Nov 2020
Old 05-09-2021 , 14:18   Re: stack error
Reply With Quote #3

Oh, thanks, i didn't know that! Solved.

Also, thank you for your reading files method from mvp plugin.
lexzor 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 12:53.


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