Raised This Month: $ Target: $400
 0% 

Run time error 3 - Stack Error - is there a pragma I need?


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 05-05-2006 , 13:44   Run time error 3 - Stack Error - is there a pragma I need?
Reply With Quote #1

In war3ft this line is giving me a stack error:

new szEachLine[150][128];

Is there a pragma I can use so my plugin is given more memory? I'm salty...

TY,
Josh
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
BAILOPAN
Join Date: Jan 2004
Old 05-05-2006 , 13:45  
Reply With Quote #2

Please tell me that line isn't in a function.

I don't want to have to hurt you.
BAILOPAN is offline
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 05-05-2006 , 13:57  
Reply With Quote #3

haha yea its in a function.. is that the problem?

Code:
public WC3_EnableModule( module_name[] ) {     new const szModulesINI[] = "addons/amxmodx/configs/modules.ini";         // Assuming a max of 400 lines and each line is less than 256 characters... if not... TOO BAD     new szEachLine[150][128];     new line = 0, len, iTotalLines = 0;     if ( file_exists( szModulesINI ) )     {         while ( ((line = read_file( szModulesINI, line, szEachLine[iTotalLines++], 31, len)) != 0) && iTotalLines < 150 ){}     }     // Now we have every line of modules.ini in our szEachLine variable, w00t     // Check out each line please     for ( new i = 0; i < iTotalLines; i++ )     {         // Module Name Found         if ( contain( szEachLine[i], module_name ) != -1 )         {             // Semicolon before module name found             if ( contain( szEachLine[i], ";" ) != -1 )             {                 new len = strlen( szEachLine[i] ), pos = 0;                 new szTemp[128];                 for ( new j = 1; j < len; j++ )                 {                     pos += ( szTemp[pos], 127 - pos, "%c", szEachLine[i][j] );                 }                 copy( szEachLine[i], 127, szTemp );             }         }     }     // Check out each line please     for ( new i = 0; i < iTotalLines; i++ )     {         server_print( szEachLine[i] );     } }
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
BAILOPAN
Join Date: Jan 2004
Old 05-05-2006 , 14:03  
Reply With Quote #4

not only is there no need to waste memory, you should use the 'static' keyword on large local variables.
BAILOPAN is offline
Greenberet
AMX Mod X Beta Tester
Join Date: Apr 2004
Location: Vienna
Old 05-05-2006 , 14:05  
Reply With Quote #5

Code:
public WC3_EnableModule( module_name[] ) {     // you should make them static or global     new const szModulesINI[] = "addons/amxmodx/configs/modules.ini";     new const szTempINI[] = "addons/amxmodx/configs/modules_temp.ini";     static szLine[256];     //******************************************************************************     new rFile = fopen( szModulesINI, "r" );     if( !rFile )         return 0;             new wFile = fopen( szTempINI, "w" );     if( !wFile )         return 0;         //******************************************************************************     new pos;     while( !feof( rFile ) )     {         fgets( rFile, szLine, 255 );         pos = 0;         if( containi( szLine, module_name ) != -1 && szLine[0] == ';')             pos = 1;             fputs( wFile, szLine[pos] );     }     //******************************************************************************     fclose( rFile );     fclose( wFile );         delete_file( szModulesINI );         return rename_file( szTempINI, szModulesINI )}

compiled fine with 0 errors and 0 warnings.
not tested, but should work

edit:
i had an mistake in the code *fixed*
Greenberet is offline
Send a message via ICQ to Greenberet Send a message via MSN to Greenberet
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 05-05-2006 , 14:09  
Reply With Quote #6

You see, that's a lot of memory. 150*128*4 = 76800 = 75 kB on the stack... Should be avoided when possible (although the compiler _should_ have computed the estimated stack size correctly in this case I think.. hmm.)

Instead, you could only hold a buffer for one line and process them on the fly ( in the body of the loop which has read_file in its condition ). This way you also wouldn't need to re-evaluate the length of each line (read_file fills it in the last parameter). I was also a bit surprised that you reserved a 128 byte buffer for each line and then told read_file to return 31 characters at max. You may want to use a constant for the line buffer length so you don't have to change it in two places (but then do constant+1 in the buffer declaration).

You may also want to try using the new file natives.
Also, the // Semicolon before module name found comment was misleading I'm afraid.

Well, my thoughts.
__________________
hello, i am pm
PM is offline
Urahara
Member
Join Date: Apr 2006
Old 05-05-2006 , 14:12  
Reply With Quote #7

Ohayo Geesu-chan!

There are many better ways to do this!

first off you should start by not using a predefined path to the module.ini; using the stocks provided by amxx is much cleaner and portable!

second off this could easily be accomplished with a simple read and if statement instead of thatconvoluted mess ill post an example later from mai pluginz
__________________

Urahara's Shop is open! For all your needs:
http://urahara.amxmodx.org/forums/
Projects:
Ururu AntiCheat
MetaScript Library
Jinta Hax
Urahara is offline
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 05-05-2006 , 14:17  
Reply With Quote #8

OK I have it working fine now...

Suggestions? Besides using the amxx natives to get the filename

Code:
// Assuming a max of 150 lines and each line is less than 256 characters... if not... TOO BAD new szEachLine[150][256]; public WC3_EnableModule( module_name[] ) {     new const szModulesINI[] = "addons/amxmodx/configs/modules.ini";     new line = 0, len, iTotalLines = 0;     if ( file_exists( szModulesINI ) )     {         while ( ((line = read_file( szModulesINI, line, szEachLine[iTotalLines++], 255, len)) != 0) && iTotalLines < 150 ){}     }     // Now we have every line of modules.ini in our szEachLine variable, w00t     // Check out each line please     for ( new i = 0; i < iTotalLines; i++ )     {         // Module Name Found         if ( contain( szEachLine[i], module_name ) != -1 )         {             // Semicolon before module name found             if ( contain( szEachLine[i], ";" ) != -1 )             {                 new len = strlen( szEachLine[i] ), pos = 0;                 new szTemp[256];                 for ( new j = 1; j < len; j++ )                 {                     add( szTemp, 255, szEachLine[i][j], 1 );                     //pos += ( szTemp[pos], 255 - pos, "%c", szEachLine[i][j] );                 }                 copy( szEachLine[i], 255, szTemp );             }         }     }     unlink( "addons/amxmodx/configs/modules.ini" );     // Check out each line please     for ( new i = 0; i < iTotalLines; i++ )     {         write_file( "addons/amxmodx/configs/modules.ini", szEachLine[i] );     } }
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
PM
hello, i am pm
Join Date: Jan 2004
Location: Canalization
Old 05-05-2006 , 14:51  
Reply With Quote #9

lol, sometimes i shout but no one seems to hear...

My suggestions are still the same.

Specifically, don't use that much memory. Do one line at a time.
Read, process, write. This is even less code because write_file overwrites the line you tell it to overwrite.

Unless I am missing something crucial, there's really no need to waste 75 kB of memory on this. And if I am, you could at least be so kind and point it out to me.

Thank you.
__________________
hello, i am pm
PM is offline
Geesu
Veteran Member
Join Date: Mar 2004
Location: Cincinnati, OH
Old 05-05-2006 , 15:08  
Reply With Quote #10

PM are u referring to use like fopen/fseek/fputc?

I tried this initially, but I wasn't able to successfully do it, so I switched to this way...

O shit I think I just realized it.. since u specify the line number in read_file/write_file...

LOL yea ur right, I am retarded, thanks
__________________
Need war3ft help? DO NOT PM ME... Check the forums
Geesu is offline
Send a message via AIM to Geesu Send a message via MSN to Geesu
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 05:00.


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