开发者

linux system crash after game exit

I run my game on linux system of TV, when I exit game, the system will crash.

from the output log, I know my game has been quite, but system crash following.

the main function like below:

int main(int argc, char** argv)
{
 ......

 SDL_Quit();

 printf("Log: exit end. \n);// it's printed on console
 return 0;
}

I can find the output log about Log: exit end. So the game has been exit right?

I found the game exit will only crash after create threads.

Here is the run function in thread below:

   while ( pThread->m_running )
    {
        string str;
        string cmdStr;

        if ( pThread->GetSendMsg(str, cmdStr) )
        {
            string returnStr = Connection::DealHttpSendMsg( str, cmdStr );

            pThread->AddReturnMsg( returnStr ); 

            haveData开发者_运维技巧 = true;
        }
        else
        {
            SDL_Delay(100);

            haveData = false;
        }
    }

My question is that if the m_running is alway true. so when I exit the game, the thread is still running. Will it cause the crash?


It will if that thread tries to access resources that are being simultaneously destroyed by the main thread.

Just quitting the app won't crash it if you have a worker thread that does nothing.

#include <stdio.h>
#include <unistd.h>
#include <pthread.h>

void* run_me(void*)
{
    while (1) 
    { 
       printf("Sleeping..\n");
       sleep(1);
    }
}

int main()
{
    pthread_t my_thread;

    pthread_create(&my_thread, NULL, &run_me, NULL);
    sleep(2);

    return 0;
}


return 0; terminates only the main thread. Try to use exit(0) instead.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜