AlliedModders

AlliedModders (https://forums.alliedmods.net/index.php)
-   Scripting Help (https://forums.alliedmods.net/forumdisplay.php?f=11)
-   -   String Explode : Segmentation Fault (https://forums.alliedmods.net/showthread.php?t=304298)

ish12321 01-10-2018 14:27

String Explode : Segmentation Fault
 
Code:
new szLineData[64][128];             str_explode_str(szInput, "\n", szLineData, sizeof(szLineData), sizeof(szLineData[]));

Code:
stock str_substr(const string[], start, output[], output_len, len = 0) {     if(len == 0 || len > output_len)     {         len = output_len;     }         return copy(output, len, string[start]); } stock str_explode(const string[], delimiter, output[][], output_size, output_len) {     new i, pos, len = strlen(string);         do     {         pos += (copyc(output[i++], output_len, string[pos], delimiter) + 1);     }     while(pos < len && i < output_size);         return i; } stock str_explode_str(const string[], const delimiter[], output[][], output_size, output_len) {     new delimiter_len = strlen(delimiter);         if(delimiter_len < 1)     {         return 0;     }     else if(delimiter_len == 1)     {         return str_explode(string, delimiter[0], output, output_size, output_len);     }         new i, pos, stop, len = strlen(string);         do     {         stop = contain(string[pos], delimiter) + pos;                 if(stop < pos)         {             stop = len;         }                 str_substr(string, pos, output[i], output_len, stop - pos);                 pos = stop + delimiter_len;     }     while(pos < len && ++i < output_size);         return i; }

I get this error
Quote:

Segmentation fault (core dumped)

ish12321 01-13-2018 10:24

Re: String Explode : Segmentation Fault
 
Any help?

klippy 01-13-2018 10:29

Re: String Explode : Segmentation Fault
 
Debug it. After every statement put a log_amx() call so you will get to know exactly at which statement it crashes. Then when you find out which statement it is, print any values that are used in that statement. Just a regular process of debugging that you should know yourself.

HamletEagle 01-13-2018 10:42

Re: String Explode : Segmentation Fault
 
Post a simple test plugin. I don't get any crash only with the code you provided.

ish12321 01-15-2018 08:17

Re: String Explode : Segmentation Fault
 
Quote:

Originally Posted by KliPPy (Post 2571689)
Debug it. After every statement put a log_amx() call so you will get to know exactly at which statement it crashes. Then when you find out which statement it is, print any values that are used in that statement. Just a regular process of debugging that you should know yourself.

new szLineData[64][128];
Before this line everything runs and on this it gives the error

PRoSToTeM@ 01-18-2018 11:36

Re: String Explode : Segmentation Fault
 
What is your plugin's "Stack/heap size"?

ish12321 01-18-2018 16:16

Re: String Explode : Segmentation Fault
 
Solved ! Was declaring variable in a loop causing that

PRoSToTeM@ 01-18-2018 19:07

Re: String Explode : Segmentation Fault
 
@ish12321 for me not only in loop. Looks like compiler calculates "max. usage", but doesn't use it for calculating "stack/heap size":
Code:

Stack/heap size:      16384 bytes; estimated max. usage=8266 cells (33064 bytes)
You can use "#pragma dynamic" to solve it:
Code:
#pragma dynamic 8266
Or (better) use static instead of new for big arrays.


All times are GMT -4. The time now is 16:36.

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