diff --git a/src/command.c b/src/command.c index 0067ccf7e..6b71dce73 100644 --- a/src/command.c +++ b/src/command.c @@ -655,7 +655,7 @@ static void COM_Alias_f(void) CONS_Printf(M_GetText("All aliases that start with \x87'%s'\x80 are:\n"), begin); int count = 0; - for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + for (cmdalias_t *head = com_alias; head != NULL; head = head->next) { if (strncmp(begin, head->name, szBegin) == 0) { @@ -676,7 +676,7 @@ static void COM_Alias_f(void) /* Display alias subtext, show all aliases. */ CONS_Printf(M_GetText("alias : create a shortcut command that executes other command(s)\n")); - for (cmdalias_t *head = com_alias; head->next != NULL; head = head->next) + for (cmdalias_t *head = com_alias; head != NULL; head = head->next) { CONS_Printf(alias_format, head->name, head->value); } diff --git a/src/d_clisrv.c b/src/d_clisrv.c index d2edf6997..9c8a78144 100644 --- a/src/d_clisrv.c +++ b/src/d_clisrv.c @@ -1777,6 +1777,9 @@ static void SV_SendPlayerInfo(INT32 node) static void SV_SendMapIcon(INT32 node) { + if (node == 0) + return; + doomdata_t *netbuffer = DOOMCOM_DATA(doomcom); const char *map = va("%sP", G_BuildMapName(gamemap)); diff --git a/src/d_main.c b/src/d_main.c index c46ef0c44..ab10af215 100644 --- a/src/d_main.c +++ b/src/d_main.c @@ -679,6 +679,9 @@ void D_SRB2Loop(void) for (;;) { + if (I_Interrupted()) + I_Quit(); + // capbudget is the minimum precise_t duration of a single loop iteration precise_t capbudget; precise_t elapsed; diff --git a/src/dedicated/i_system.c b/src/dedicated/i_system.c index 31eaf0346..5edb71a99 100644 --- a/src/dedicated/i_system.c +++ b/src/dedicated/i_system.c @@ -1075,11 +1075,19 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) +static volatile sig_atomic_t interrupted = 0; + +boolean I_Interrupted(void) +{ + return interrupted; +} + +static void quit_handler(int num) { signal(num, SIG_DFL); //default signal action raise(num); - I_Quit(); + //I_Quit(); + interrupted = true; } #ifdef HAVE_LIBBACKTRACE diff --git a/src/g_demo.c b/src/g_demo.c index f828d0343..a714f8e48 100644 --- a/src/g_demo.c +++ b/src/g_demo.c @@ -2795,7 +2795,7 @@ void G_DoPlayDemo(char *defdemoname) demobuf.p += 4; // Extrainfo location // ...*map* not loaded? - if (!gamemap || (gamemap > NUMMAPS) || !mapheaderinfo[gamemap-1] || !(mapheaderinfo[gamemap-1]->menuflags & LF2_EXISTSHACK)) + if (!gamemap || (gamemap > NUMMAPS) || (W_CheckNumForName(G_BuildMapName(gamemap)) == LUMPERROR)) { snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); CONS_Alert(CONS_ERROR, "%s", msg); @@ -2836,6 +2836,16 @@ void G_DoPlayDemo(char *defdemoname) return; } + // ...*map* not loaded? + if (!gamemap || (gamemap > NUMMAPS) || !mapheaderinfo[gamemap-1] || !(mapheaderinfo[gamemap-1]->menuflags & LF2_EXISTSHACK)) + { + snprintf(msg, 1024, M_GetText("%s features a course that is not currently loaded.\n"), pdemoname); + CONS_Alert(CONS_ERROR, "%s", msg); + M_StartMessage(msg, M_ReturnToTitleFromError, MM_EVENTHANDLER); + G_ResetDemoPlayback(); + return; + } + // Set color for (i = 0; i < MAXSKINCOLORS; i++) { diff --git a/src/i_system.h b/src/i_system.h index 7084c655f..68d51f022 100644 --- a/src/i_system.h +++ b/src/i_system.h @@ -29,7 +29,6 @@ extern "C" { */ #define MAX_QUIT_FUNCS 16 - /** \brief Graphic system had started up */ extern UINT8 graphics_started; @@ -191,6 +190,8 @@ INT32 I_StartupSystem(void); */ void I_ShutdownSystem(void); +boolean I_Interrupted(void); + /** \brief The I_GetDiskFreeSpace function \param freespace a INT64 pointer to hold the free space amount diff --git a/src/m_aatree.c b/src/m_aatree.c index f78355eaf..7fb847aab 100644 --- a/src/m_aatree.c +++ b/src/m_aatree.c @@ -49,17 +49,19 @@ aatree_t *M_AATreeAlloc(UINT32 flags) return aatree; } -static void M_AATreeFree_Node(aatree_node_t *node) +static void M_AATreeFree_Node(aatree_node_t *node, bool is_string) { - if (node->left) M_AATreeFree_Node(node->left); - if (node->right) M_AATreeFree_Node(node->right); + if (node->left) M_AATreeFree_Node(node->left, is_string); + if (node->right) M_AATreeFree_Node(node->right, is_string); + if (is_string) + Z_Free(node->value); Z_Free(node); } void M_AATreeFree(aatree_t *aatree) { if (aatree->root) - M_AATreeFree_Node(aatree->root); + M_AATreeFree_Node(aatree->root, (aatree->flags & AATREE_STRING) == AATREE_STRING); Z_Free(aatree); } diff --git a/src/p_setup.c b/src/p_setup.c index bf40afe9d..5b4c2796b 100644 --- a/src/p_setup.c +++ b/src/p_setup.c @@ -812,6 +812,8 @@ static void P_LoadSectors(UINT8 *data) ss->tag = SHORT(ms->tag); ss->flags |= SF_FLIPSPECIAL_FLOOR; + + ss->soundorg.thinker.function = (actionf_p1)P_MobjThinker; } // set the sky flat num diff --git a/src/s_sound.c b/src/s_sound.c index 5bc830252..651d579b8 100644 --- a/src/s_sound.c +++ b/src/s_sound.c @@ -772,9 +772,14 @@ void S_UpdateSounds(void) volume = c->volume; // 8 bits internal volume precision sep = NORM_SEP; + if (P_MobjWasRemoved(c->origin)) + { + // origin was removed, stop the music + S_StopChannel(cnum); + } // check non-local sounds for distance clipping // or modify their params - if (c->origin) + else { boolean itsUs = false; diff --git a/src/sdl/i_system.cpp b/src/sdl/i_system.cpp index 23a32af40..8a9b8bd69 100644 --- a/src/sdl/i_system.cpp +++ b/src/sdl/i_system.cpp @@ -1670,21 +1670,19 @@ FUNCNORETURN static ATTRNORETURN void signal_handler(INT32 num) } #endif -FUNCNORETURN static ATTRNORETURN void quit_handler(int num) -{ -#ifdef HAVE_THREADS - if (g_main_thread_id != std::this_thread::get_id()) - { - // Do not attempt any sort of recovery if this signal triggers off the main thread - signal(num, SIG_DFL); - raise(num); - exit(-2); - } -#endif +static volatile sig_atomic_t interrupted = 0; +boolean I_Interrupted(void) +{ + return interrupted; +} + +static void quit_handler(int num) +{ signal(num, SIG_DFL); //default signal action raise(num); - I_Quit(); + //I_Quit(); + interrupted = true; } static void I_RegisterSignals(void) @@ -1851,17 +1849,20 @@ INT32 I_StartupSystem(void) return 0; } +boolean is_quitting = false; + // // I_Quit // FUNCNORETURN void ATTRNORETURN I_Quit(void) { - static SDL_bool quiting = SDL_FALSE; - /* prevent recursive I_Quit() */ - if (quiting) goto death; + if (is_quitting) + abort(); + + is_quitting = true; SDL_ShowCursor(SDL_TRUE); - quiting = SDL_FALSE; + I_ShutdownConsole(); M_SaveConfig(NULL); //save game config, cvars.. D_SaveBan(); // save the ban list @@ -1888,7 +1889,7 @@ FUNCNORETURN void ATTRNORETURN I_Quit(void) } if (myargmalloc) free(myargv); // Deallocate allocated memory -death: + W_Shutdown(); exit(0); } diff --git a/src/sdl/i_video.c b/src/sdl/i_video.c index 61c7fc744..6c99067f5 100644 --- a/src/sdl/i_video.c +++ b/src/sdl/i_video.c @@ -2182,7 +2182,8 @@ void I_ShutdownGraphics(void) SDL_DestroyWindow(window); window = NULL; - SDL_QuitSubSystem(SDL_INIT_VIDEO); + if (SDL_WasInit(SDL_INIT_VIDEO) == SDL_INIT_VIDEO) + SDL_QuitSubSystem(SDL_INIT_VIDEO); framebuffer = SDL_FALSE; } diff --git a/src/sdl/mixer_sound.c b/src/sdl/mixer_sound.c index 529b47399..c455aab01 100644 --- a/src/sdl/mixer_sound.c +++ b/src/sdl/mixer_sound.c @@ -237,7 +237,8 @@ void I_ShutdownSound(void) Mix_Quit(); #endif - SDL_QuitSubSystem(SDL_INIT_AUDIO); + if (SDL_WasInit(SDL_INIT_AUDIO) == SDL_INIT_AUDIO) + SDL_QuitSubSystem(SDL_INIT_AUDIO); #ifdef HAVE_LIBGME if (gme)