My WTF coding or not?



  • Hi!

    I'm looking for some advice, since I've run out of ideas.

    Here's the problem: I'm working on a hobby project, which will eventually become an audio sequencer. The project was originally started in C++, using MinGW under Win2k, and after some time I ran into a little problem: Sometimes I got a BSOD at the exact same instant I closed my application: BAD_POOL_CALLER, 0x2c, BAD_POOL_REQUEST. This started to happen after I started working on the (then) OpenGL-UI which I had planned for this application.

    Eventually I scrapped the program, this being one of the reasons, and after some time I converted some code to D and started again with some big changes in the concept. Ok, after I started working on the UI again (this time using SDL instead of OpenGL) the exact same bluescreens are back, occuring under exactly the same condition: at the exact same instant I press the ESC key to close the program. Now, there are sometimes days without BSOD and sometimes I get 2-3 BSOD a day. When working on other stuff or gaming or whatever I get NO bluescreens at all, the system is cleaned regularly and runs usually very smoothly without any problems, these bluescreens are the only ones I get.

    Unfortunately I can't provide a test case, since I can't replicate this behavior in any way, so I'll give you a brief description of the system: my development machine is a Win2k machine, I am (currently) using SDL for audio output (until I get ASIO up and running, the old system used WDM, so it can't be an issue with SDL, I guess), and using SDL for drawing the UI. Audio calculation and GUI rendering are done in two threads, the audio rendering thread sleeps and wakes up when the audio callback is called from the driver (so the audio thread always can prepare audio data in advance), the GUI render thread runs in an endless loop and sleeps for a couple of microseconds, while keyboard and mouse input are handled in the main thread (which stays in the SDL main loop after initializing everything). All interfacing functions are secured in critical sections. When shutting down, the main thread waits for the other two threads to exit before calling the destructors. One thing to note is that D uses a garbage collector, which might possibly be a problem (although the guys in the D newsgroup don't think so and I got the same bluescreens in C++ - with manual memory management).

    I hope someone can point out the problem - since if I can't solve this the whole thing is useless and I can scrap it again. I mean, who wants a program that randomly crashes the machine when it exits? Any help would be very appreciated.

    Oh, and happy new year to all!

    -mike (long-time TDWTF lurker)



  • [quote user="vertex"]Hi! I'm looking for some advice, since I've run out of ideas.
    Audio calculation and GUI rendering are done in two threads, the audio rendering thread sleeps and wakes up when the audio callback is called from the driver (so the audio thread always can prepare audio data in advance), the GUI render thread runs in an endless loop and sleeps for a couple of microseconds, while keyboard and mouse input are handled in the main thread (which stays in the SDL main loop after initializing everything). All interfacing functions are secured in critical sections. When shutting down, the main thread waits for the other two threads to exit before calling the destructors. One thing to note is that D uses a garbage collector, which might possibly be a problem (although the guys in the D newsgroup don't think so and I got the same bluescreens in C++ - with manual memory management).

    I hope someone can point out the problem - since if I can't solve this the whole thing is useless and I can scrap it again. I mean, who wants a program that randomly crashes the machine when it exits? Any help would be very appreciated.

    Oh, and happy new year to all!

    -mike (long-time TDWTF lurker)[/quote]

    coming from the basis that my .NET threaded applications tend to crash on shutdown i'd be willing to bet some copper coins that that's where the problem is. I may be overstepping my bounds here, but are you absoloutly sure that there isn't some WTFery in the "make sure the other two threads are exited"? Maybe a sentinel-type main loop that merely spawns the watcher for the gui and audio, and if stuff gets really bad just dump everything from the sentinel?

    Main(){

    watcher.thread.start()

    while(watcher.thread.isRunning){

    //monitor for unusalness in here

    //check for alt-f4, esc, etc, audio driver errors...

    } end while

    watcher.thread.kill()

    exit(0)

    }

    watcher should have your gui.thread.start and your audio.thread.start (or whatever you want to call it)

    I had to do this when writing a serverless chat program, because the thread that accepted connections would kill everything if something went wrong with the handshaking. essentially i started 3 seperate threads, one for incoming, one for outgoing, and one to monitor everything for sane-ness.

    I'd post code, but half is in C# and half is in VB.NET, and what i said already gets my point across.

    anyhow i am sorry if this is so far off topic that you want to harm me.

     

    --genewitch



  • A regular user-space program should NEVER be able to crash the system, if it does it's an OS or driver bug. Have you tried it on a different machine? In your case, this thread seems promising. If that's not the problem, I suggest Googling around for bits of error messages, names of devices you have, etc.



  • I'd say you making a invalid request to the driver when you shutdown you application. Maybe you haven't handle the request correctly(i.e haven't returned the correct value).

    Another reason could be because M$ has change it's specifications without anyone knowing and is sending a different request to the driver (somehow display a little message or log one. This is first to see if your handler is being called and second test where about it is getting up to before it crashes (which means that you can narrow down the possibilities as to where the problem could be)).

    Or you haven't shut the driver down at all and the OS is trying to shut it down for you (which your not handling the shutdown properly).



  • I just did a quick Google search and found the following article which may be of any help



  • Thanks for the replies and the links!

    I'll check that out as soon as I have recovered from the new year party ... :)

    @GeneWitch: Could be a problem. Both threads work like this:

    bool running = true;

    while (running)

    {

    // do stuff

    }

    When shutting down, I set the running flags to false and wake the threads up, so that they can leave the while loop and wait() for them to exit. Maybe I should make a critical section for the member function that sets the running flag. I'll try that. Biggest problem of course is that I need to wait 4-5 days after a change to see if it has worked.

    @iwpg: On my laptop I never got that problem. But then, I didn't start/stop the program as often as on my development machine. I'll give it a try and see if I can crash my laptop too.

    -mike


Log in to reply
 

Looks like your connection to What the Daily WTF? was lost, please wait while we try to reconnect.