[SDL] Random crashes inside an SDL_Thread

Ulrich Eckhardt doomster at knuut.de
Sun May 6 22:07:23 PDT 2007


On Monday 07 May 2007 04:48:40 benang at cs.its.ac.id wrote:
> void CMainApp::createTempLatex()
> {
>   fstream filestr;
>   filestr.open ("./temp-print.tex", fstream::out);

The 'out' is declared in std::ios_base in fact and only inherited here. If you 
used std::ofstream, you could save yourself the hassle of it.

>   fstream<<"\\begin{document}"<<endl;
>   .....  //The body of the LaTeX file
>   fstream<<"\\end{document}"<<endl;
>   filestr.close();

What, no error handling? Flush the stream and then check its streamstate. If 
its failbit or badbit are set, throw an appropriate exception. Also, I would 
have done the same after open(), because that one is most likely to fail.
BTW: If the rest of your app is like that, you have a lot of work to do!

> void CMainApp::createTempPostScript()
> {
>     system("latex temp-print.tex -halt-on-error");
>     system("dvips temp-print -Pcmz -t landscape -o temp-print.ps");
> }

Even system() returns something, though I'm not sure if it's the returnvalue 
of the called process. You might have to use some platform-specific hack to 
get to it.

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

Where? Look at the backtrace in a debugger! Does it access any shared 
resources?

> Often it worked fine until few printing. 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.

Impossible to help here. There could be any numer of things going wrong here 
and without some relevant information nobody will be able to help you. Also, 
if you can, provide a minimal(!) example - yours isn't, it's too small, i.e. 
incomplete.

Uli


More information about the SDL mailing list