From a01217f2671f68bc2638d8e5c48c34551a817e3a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Tue, 5 Jan 2010 20:51:58 +0000 Subject: [PATCH] fixes --- library/DFProcess-linux-SHM.cpp | 3 ++- shmserver/shms-linux.cpp | 18 +++++++++++------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/library/DFProcess-linux-SHM.cpp b/library/DFProcess-linux-SHM.cpp index d8bb9a46a..4d60bdb48 100644 --- a/library/DFProcess-linux-SHM.cpp +++ b/library/DFProcess-linux-SHM.cpp @@ -193,7 +193,7 @@ SHMProcess::SHMProcess(vector & known_versions) shmctl(d->my_shmid, IPC_STAT, &descriptor); if(descriptor.shm_nattch != 2)// badness { - fprintf(stderr,"dfhack: %d : invalid no. of processes connected\n", descriptor.shm_nattch); + fprintf(stderr,"dfhack: %d : invalid no. of processes connected\n", (int) descriptor.shm_nattch); fprintf(stderr,"detach: %d",shmdt(d->my_shm)); return; } @@ -236,6 +236,7 @@ SHMProcess::SHMProcess(vector & known_versions) gcc_barrier // at this point, DF is stopped and waiting for commands. make it run again ((shm_cmd *)d->my_shm)->pingpong = DFPP_RUNNING; + shmdt(d->my_shm); // detach so we don't attach twice when attach() is called } bool SHMProcess::isSuspended() diff --git a/shmserver/shms-linux.cpp b/shmserver/shms-linux.cpp index d7debcbd2..395d50ffc 100644 --- a/shmserver/shms-linux.cpp +++ b/shmserver/shms-linux.cpp @@ -83,8 +83,8 @@ static int (*_SDL_Flip)(void * some_ptr) = 0; // various crud int counter = 0; int errorstate = 0; -char *shm; -int shmid; +char *shm = 0; +int shmid = 0; void SHM_Init ( void ) { @@ -139,7 +139,7 @@ extern "C" void SDL_GL_SwapBuffers(void) { if(_SDL_GL_SwapBuffers) { - if(((shm_cmd *)shm)->pingpong != DFPP_RUNNING) + if(!errorstate && ((shm_cmd *)shm)->pingpong != DFPP_RUNNING) { SHM_Act(); } @@ -153,7 +153,7 @@ extern "C" int SDL_Flip(void * some_ptr) { if(_SDL_Flip) { - if(((shm_cmd *)shm)->pingpong != DFPP_RUNNING) + if(!errorstate && ((shm_cmd *)shm)->pingpong != DFPP_RUNNING) { SHM_Act(); } @@ -169,8 +169,11 @@ extern "C" void SDL_Quit(void) { _SDL_Quit(); } - fprintf(stderr,"dfhack: DF called SwapBuffers %d times\n", counter); - SHM_Destroy(); + if(!errorstate) + { + fprintf(stderr,"dfhack: DF called SwapBuffers %d times\n", counter); + SHM_Destroy(); + } } // hook - called at program start, initialize some stuffs we'll use later @@ -203,7 +206,8 @@ bool isValidSHM() { shmid_ds descriptor; shmctl(shmid, IPC_STAT, &descriptor); - return descriptor.shm_nattch == 1; + fprintf(stderr,"ID %d, attached: %d\n",shmid, descriptor.shm_nattch); + return (descriptor.shm_nattch == 2); } uint32_t getPID() {