From 72cf7cef866e2588229bfe3a1d013b9dee907e5a Mon Sep 17 00:00:00 2001 From: Robert Beckebans Date: Wed, 23 Dec 2020 21:02:38 +0100 Subject: [PATCH] Smaller potential crashfixes from SS2 engine --- neo/CMakeLists.txt | 4 +- neo/idlib/containers/StaticList.h | 27 +++------- neo/sound/snd_world.cpp | 2 + neo/sys/sys_session_local.cpp | 90 ++++++++++++++++++++++++++++--- 4 files changed, 94 insertions(+), 29 deletions(-) diff --git a/neo/CMakeLists.txt b/neo/CMakeLists.txt index b8ee8396..26e811b6 100644 --- a/neo/CMakeLists.txt +++ b/neo/CMakeLists.txt @@ -251,8 +251,8 @@ elseif(MSVC) -D_CRT_SECURE_NO_DEPRECATE -D_CRT_NONSTDC_NO_DEPRECATE -D_CRT_SECURE_NO_WARNINGS - -D_MBCS - #-DUSE_OPENAL + -D_MBCS + #-DUSE_OPENAL -DUSE_EXCEPTIONS) ## Check for Version ## if( WINRT OR WINDOWS10 ) # Windows RT diff --git a/neo/idlib/containers/StaticList.h b/neo/idlib/containers/StaticList.h index 8e615599..574c81ef 100644 --- a/neo/idlib/containers/StaticList.h +++ b/neo/idlib/containers/StaticList.h @@ -405,8 +405,6 @@ Returns the index of the new element, or -1 when list is full. template ID_INLINE int idStaticList::Insert( type const& obj, int index ) { - int i; - assert( num < size ); if( num >= size ) { @@ -423,7 +421,7 @@ ID_INLINE int idStaticList::Insert( type const& obj, int index ) index = num; } - for( i = num; i > index; --i ) + for( int i = num; i > index; --i ) { list[i] = list[i - 1]; } @@ -445,14 +443,13 @@ Returns the size of the new combined list template ID_INLINE int idStaticList::Append( const idStaticList& other ) { - int i; int n = other.Num(); if( num + n > size ) { n = size - num; } - for( i = 0; i < n; i++ ) + for( int i = 0; i < n; i++ ) { list[i + num] = other.list[i]; } @@ -470,9 +467,7 @@ Adds the data to the list if it doesn't already exist. Returns the index of the template ID_INLINE int idStaticList::AddUnique( type const& obj ) { - int index; - - index = FindIndex( obj ); + int index = FindIndex( obj ); if( index < 0 ) { index = Append( obj ); @@ -491,9 +486,7 @@ Searches for the specified data in the list and returns it's index. Returns -1 template ID_INLINE int idStaticList::FindIndex( type const& obj ) const { - int i; - - for( i = 0; i < num; i++ ) + for( int i = 0; i < num; i++ ) { if( list[ i ] == obj ) { @@ -515,9 +508,7 @@ Searches for the specified data in the list and returns it's address. Returns NU template ID_INLINE type* idStaticList::Find( type const& obj ) const { - int i; - - i = FindIndex( obj ); + int i = FindIndex( obj ); if( i >= 0 ) { return ( type* ) &list[ i ]; @@ -539,9 +530,7 @@ on non-pointer lists will cause a compiler error. template ID_INLINE int idStaticList::FindNull() const { - int i; - - for( i = 0; i < num; i++ ) + for( int i = 0; i < num; i++ ) { if( list[ i ] == NULL ) { @@ -609,7 +598,7 @@ ID_INLINE bool idStaticList::RemoveIndex( int index ) /* ======================== -idList<_type_,_tag_>::RemoveIndexFast +idStaticList<_type_,_tag_>::RemoveIndexFast Removes the element at the specified index and moves the last element into its spot, rather than moving the whole array down by one. Of course, this doesn't maintain the order of @@ -685,7 +674,7 @@ void BreakOnListDefault(); /* ======================== -idList<_type_,_tag_>::Resize +idStaticList<_type_,_tag_>::Resize Allocates memory for the amount of elements requested while keeping the contents intact. Contents are copied using their = operator so that data is correctly instantiated. diff --git a/neo/sound/snd_world.cpp b/neo/sound/snd_world.cpp index 909d1be7..669e80af 100644 --- a/neo/sound/snd_world.cpp +++ b/neo/sound/snd_world.cpp @@ -935,9 +935,11 @@ void idSoundWorldLocal::ProcessDemoCommand( idDemoFile* readDemo ) break; } case SCMD_STATE: + { ReadFromSaveGame( readDemo ); UnPause(); break; + } case SCMD_PLACE_LISTENER: { idVec3 origin; diff --git a/neo/sys/sys_session_local.cpp b/neo/sys/sys_session_local.cpp index 0d2d0c9f..bbd33b16 100644 --- a/neo/sys/sys_session_local.cpp +++ b/neo/sys/sys_session_local.cpp @@ -3,6 +3,8 @@ Doom 3 BFG Edition GPL Source Code Copyright (C) 1993-2012 id Software LLC, a ZeniMax Media company. +Copyright (C) 2014-2016 Robert Beckebans +Copyright (C) 2014-2016 Kot in Action Creative Artel This file is part of the Doom 3 BFG Edition GPL Source Code ("Doom 3 BFG Edition Source Code"). @@ -137,11 +139,32 @@ idSessionLocal::idSessionLocal */ idSessionLocal::~idSessionLocal() { - delete processorSaveFiles; - delete processorLoadFiles; - delete processorDelete; - delete processorEnumerate; - delete sessionCallbacks; + // foresthale 2014-06-08: check before deleting these, the deletes were likely done in Shutdown already + if( processorSaveFiles ) + { + delete processorSaveFiles; + processorSaveFiles = NULL; + } + if( processorLoadFiles ) + { + delete processorLoadFiles; + processorLoadFiles = NULL; + } + if( processorDelete ) + { + delete processorDelete; + processorDelete = NULL; + } + if( processorEnumerate ) + { + delete processorEnumerate; + processorEnumerate = NULL; + } + if( sessionCallbacks ) + { + delete sessionCallbacks; + sessionCallbacks = NULL; + } } @@ -1583,11 +1606,20 @@ idSessionLocal::~idSession */ idSession::~idSession() { - delete signInManager; + if( signInManager ) + { + delete signInManager; + } signInManager = NULL; - delete saveGameManager; + if( saveGameManager ) + { + delete saveGameManager; + } saveGameManager = NULL; - delete dedicatedServerSearch; + if( dedicatedServerSearch ) + { + delete dedicatedServerSearch; + } dedicatedServerSearch = NULL; } @@ -1618,6 +1650,48 @@ idSessionLocal::Shutdown */ void idSessionLocal::Shutdown() { + // foresthale 2014-05-28: shut down saveGameManager early because the thread it owns will be terminated before the dtor is reached + if( signInManager ) + { + delete signInManager; + } + signInManager = NULL; + if( saveGameManager ) + { + delete saveGameManager; + } + saveGameManager = NULL; + if( dedicatedServerSearch ) + { + delete dedicatedServerSearch; + } + dedicatedServerSearch = NULL; + // foresthale 2014-06-08: delete these before we get to the dtor to prevent doexit crashes + if( processorSaveFiles ) + { + delete processorSaveFiles; + processorSaveFiles = NULL; + } + if( processorLoadFiles ) + { + delete processorLoadFiles; + processorLoadFiles = NULL; + } + if( processorDelete ) + { + delete processorDelete; + processorDelete = NULL; + } + if( processorEnumerate ) + { + delete processorEnumerate; + processorEnumerate = NULL; + } + if( sessionCallbacks ) + { + delete sessionCallbacks; + sessionCallbacks = NULL; + } } /*