Skip to main content
gamedev.net
🔒 Locked

[C++] Thread keeps exiting.

Started by blueshogun96 5 replies 1.1k views
Original Post
blueshogun96
blueshogun96
For some reason, my thread keeps terminating without warning.  I have  absolutely no idea what the problem is.  All I know is that the thread  terminates whenever I attempt to use/access a string (be it std::string  or char*).  The thread was created with _beginthreadex.  Furthermore, I  was writing an ogg vorbis player for bgm using a thread for audio  processing; and the code was posted by another user in this thread:

http://www.gamedev.net/topic/221938-here-is-a-class-for-streaming-ogg-vorbis-in-directsound-bsd-license/

I don't know what could cause the thread to terminate.  But it terminates right here for me:

[code]bool CDirectSoundOgg::Allocate() {
     //----- open OGG file
     //get a handle to the file

    FILE *fileHandle = fopen(GetFileName().c_str(), "rb");
...



I even wrote some code to print out the filename using  OutputDebugString, but it dies there too.  When the string is accessed,  the debug output tells me that the thread has terminated (code  0x0).  Been at this for a while, and can't find any solutions.  This  sucks.  Any ideas?  Thanks.

Btw, if you need my code that I wrote personally, I can post that too.
blueshogun96
blueshogun96
Wow, why did my OP turn into that mass of gibberish?? Oh well.

Just in case you're having trouble reading that, I was just saying that I wrote an ogg vorbis player based on the code below:

http://www.gamedev.net/topic/221938-here-is-a-class-for-streaming-ogg-vorbis-in-directsound-bsd-license/

And the thread keeps terminating when I attempt to use a string (be it std::string or char*). I have no idea what's going on. This sucks. Any ideas? Thanks.
rip-off
rip-off
You'll need to give more information than that. Have you tried using a debugger?
blueshogun96
blueshogun96
How do you debug threads? I'm not used to using these.

Pressing F10 to enable step by step debugging never allows me to debug the thread, or do I have to do something special for that?

Oh, does this help?  In the debug output, it tells me that the thread terminated with code 0x0, which does not appear to be an error.  I tried using OutputDebugString to view the string contents before it attempts to open the .ogg file.  As soon as it gets to that point, the thread will also terminate.

...

OutputDebugString( "OggStream::Allocate(): Opening file " );
OutputDebugString( strFilename.c_str() );
OutputDebugString( "\n" );

...

Whenever the string is accessed, it does.  I'm not sure what else to say.
Red Ant
Red Ant

Bump.


If you're debugging In Visual Studio, there should be a debug window that allows you to switch between the various threads of the program you're debugging. You can switch simply by double-clicking the thread you want to go to.

Anyway, I'm suspecting that something you do causes an exception to be thrown in your thread, and since you're not catching it, it flies right up to the thread's top level function and terminates the thread. Build a try-catch into your thread's entry function and set a breakpoint in the catch {} block to see if this suspicion is correct.


EDIT: Oh wait, does your whole program terminate or only that one thread?
Bow_vernon
Bow_vernon
Maybe you can check the thread function and watch the termination case. Are you doing it right? and maybe you could post some code here so we could see what's going on...

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.