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

String Explode : Segmentation Fault


Post New Thread Reply   
 
Thread Tools Display Modes
Author Message
ish12321
Veteran Member
Join Date: May 2016
Old 01-10-2018 , 14:27   String Explode : Segmentation Fault
Reply With Quote #1

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)
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
ish12321
Veteran Member
Join Date: May 2016
Old 01-13-2018 , 10:24   Re: String Explode : Segmentation Fault
Reply With Quote #2

Any help?
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
klippy
AlliedModders Donor
Join Date: May 2013
Location: Serbia
Old 01-13-2018 , 10:29   Re: String Explode : Segmentation Fault
Reply With Quote #3

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.
__________________
klippy is offline
HamletEagle
AMX Mod X Plugin Approver
Join Date: Sep 2013
Location: Romania
Old 01-13-2018 , 10:42   Re: String Explode : Segmentation Fault
Reply With Quote #4

Post a simple test plugin. I don't get any crash only with the code you provided.
__________________
HamletEagle is offline
ish12321
Veteran Member
Join Date: May 2016
Old 01-15-2018 , 08:17   Re: String Explode : Segmentation Fault
Reply With Quote #5

Quote:
Originally Posted by KliPPy View Post
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
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-18-2018 , 11:36   Re: String Explode : Segmentation Fault
Reply With Quote #6

What is your plugin's "Stack/heap size"?
__________________
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
ish12321
Veteran Member
Join Date: May 2016
Old 01-18-2018 , 16:16   Re: String Explode : Segmentation Fault
Reply With Quote #7

Solved ! Was declaring variable in a loop causing that
__________________
['O|s|G'] | Death Wins a.k.a Ish Chhabra was here
ish12321 is offline
PRoSToTeM@
Veteran Member
Join Date: Jan 2010
Location: Russia, Ivanovo
Old 01-18-2018 , 19:07   Re: String Explode : Segmentation Fault
Reply With Quote #8

@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.
__________________

Last edited by PRoSToTeM@; 01-18-2018 at 19:13.
PRoSToTeM@ is offline
Send a message via ICQ to PRoSToTeM@ Send a message via Skype™ to PRoSToTeM@
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 17:20.


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