develop
Petr Mrázek 2010-01-05 20:51:58 +00:00
parent d43adaef6c
commit a01217f267
2 changed files with 13 additions and 8 deletions

@ -193,7 +193,7 @@ SHMProcess::SHMProcess(vector <memory_info> & known_versions)
shmctl(d->my_shmid, IPC_STAT, &descriptor); shmctl(d->my_shmid, IPC_STAT, &descriptor);
if(descriptor.shm_nattch != 2)// badness 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)); fprintf(stderr,"detach: %d",shmdt(d->my_shm));
return; return;
} }
@ -236,6 +236,7 @@ SHMProcess::SHMProcess(vector <memory_info> & known_versions)
gcc_barrier gcc_barrier
// at this point, DF is stopped and waiting for commands. make it run again // at this point, DF is stopped and waiting for commands. make it run again
((shm_cmd *)d->my_shm)->pingpong = DFPP_RUNNING; ((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() bool SHMProcess::isSuspended()

@ -83,8 +83,8 @@ static int (*_SDL_Flip)(void * some_ptr) = 0;
// various crud // various crud
int counter = 0; int counter = 0;
int errorstate = 0; int errorstate = 0;
char *shm; char *shm = 0;
int shmid; int shmid = 0;
void SHM_Init ( void ) void SHM_Init ( void )
{ {
@ -139,7 +139,7 @@ extern "C" void SDL_GL_SwapBuffers(void)
{ {
if(_SDL_GL_SwapBuffers) if(_SDL_GL_SwapBuffers)
{ {
if(((shm_cmd *)shm)->pingpong != DFPP_RUNNING) if(!errorstate && ((shm_cmd *)shm)->pingpong != DFPP_RUNNING)
{ {
SHM_Act(); SHM_Act();
} }
@ -153,7 +153,7 @@ extern "C" int SDL_Flip(void * some_ptr)
{ {
if(_SDL_Flip) if(_SDL_Flip)
{ {
if(((shm_cmd *)shm)->pingpong != DFPP_RUNNING) if(!errorstate && ((shm_cmd *)shm)->pingpong != DFPP_RUNNING)
{ {
SHM_Act(); SHM_Act();
} }
@ -169,8 +169,11 @@ extern "C" void SDL_Quit(void)
{ {
_SDL_Quit(); _SDL_Quit();
} }
fprintf(stderr,"dfhack: DF called SwapBuffers %d times\n", counter); if(!errorstate)
SHM_Destroy(); {
fprintf(stderr,"dfhack: DF called SwapBuffers %d times\n", counter);
SHM_Destroy();
}
} }
// hook - called at program start, initialize some stuffs we'll use later // hook - called at program start, initialize some stuffs we'll use later
@ -203,7 +206,8 @@ bool isValidSHM()
{ {
shmid_ds descriptor; shmid_ds descriptor;
shmctl(shmid, IPC_STAT, &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() uint32_t getPID()
{ {