Sorry to bump into this pretty old thread of mine. The reason is, the random crash is still happening. Even worst, now it's occasionally freezes.
The crash usually happens inside an SDL_Thread. The thread is for printing with LaTeX and CUPS while the main application does some sort of animation and progress bar. This is what's inside the thread's function:
Code:
int CMainApp::printNow(void *data)
{
/// @todo implement me
CMainApp *pMyApp=static_cast<CMainApp*>(data);
pMyApp->createTempLatex(); //Create temporary latex file
pMyApp->createTempPostScript(); //Create temporary postscript file
pMyApp->printPostScriptFile(); //Print with CUPS
return 1;
}
The createTempLatex() is only a function that create a LaTeX file as an output like this:
Code:
void CMainApp::createTempLatex()
{
fstream filestr;
filestr.open ("./temp-print.tex", fstream::out);
fstream<<"\\begin{document}"<<endl;
..... //The body of the LaTeX file
fstream<<"\\end{document}"<<endl;
filestr.close();
}
And inside the createTempPostScript() function there's 2 system calls for converting the Latex to a DVI file, and a DVI to PS file like this:
Code:
void CMainApp::createTempPostScript()
{
system("latex temp-print.tex -halt-on-error");
system("dvips temp-print -Pcmz -t landscape -o temp-print.ps");
}
And the printPostScriptFile() is for sending the PS file to the CUPS spooling queue for printing.
I don't know what's wrong with it but this thread function randomly generates crashes. Often it worked fine until few printings. But every now and then it will crash. And the crash is always in this printing routine.
The crash itself is not always a segmentation error. This is what usually
happen if the application crashed:
1. Back to terminal with segmentation error
2. Hangs up. The animation and progress bar are not working. The event
handler also not working. It's like the system freezes out.
3. Infinite loop. The event handler, animation, and progress bar are
working. But because the application needed the thread to finish before
going to the next state, it will stay inside the current state (printing
state). This always happens if the thread is still doing its stuffs in one
of the system calls yet SDL_WaitThread() has been called.
Can anybody give me some help here? How do you usually solve this kind of
problem? Thanks in advance.