Greetings all,
ERROR: Program received signal 'SIGSEGV', Segmentation fault.
I am having some issues with the following code creating the above fault in Code::Blocks. It is for a chatbox I am using for a network chat program where the vector is filled with the strings of text for each line of the chat log. I don't see why its throwing a segmentation fault as I am not trying write to any memory at all with this routine.
The line creating the error is [if(iter->empty());]. If I remove that line then it will still throw the fault at the DrawText function call.
Can anyone help me out? It's been a nightmare for me at the moment trying to debug it!
FYI -> I am coding in Code::Blocks on Ubuntu. Program uses SDL, particularly the 'net' and 'thread' headers. The DrawText function is simply a wrapper for TTF_RenderTextBlended() and SDL_BlitSurface, but I know the error isn't in the DrawText function directly because I have used it with many other projects with no issues.
Everything I check points towards there being an issue with the strings in the vector, but I cannot work out what?
void GUI_ChatBox::Render(SDL_Surface *screen)
{
int line = 0;
for(vector<string>::reverse_iterator iter = L.rbegin(); iter != L.rend(); ++iter)
{
if(iter->empty())
continue;
++line;
DrawText(screen, iter->c_str(), x, (y + height) - (line * CHAR_HEIGHT));
}
}
L in the above example was short for - LineBuffer. Only one other function interacts with it and that is the function used to add text to the vector. Here it is:
void GUI_ChatBox::AddText(std::string text)
{
++index;
if(index >= maxLines)
{
index = maxLines;
LineBuffer.erase(LineBuffer.begin());
}
LineBuffer.push_back(text);
}
That function will usually receive a char* array as the std::string parameter, but I have done this elsewhere with no issues.