Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Core/GameEngine/Source/Common/System/XferSave.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -91,7 +91,7 @@ XferSave::~XferSave( void )
{

next = m_blockStack->next;
m_blockStack->deleteInstance();
deleteInstance(m_blockStack);
m_blockStack = next;

} // end while
Expand Down Expand Up @@ -247,7 +247,7 @@ void XferSave::endBlock( void )
fseek( m_fileFP, currentFilePos, SEEK_SET );

// delete the block data as it's all used up now
top->deleteInstance();
deleteInstance(top);

} // end endBlock

Expand Down
28 changes: 10 additions & 18 deletions Generals/Code/GameEngine/Include/Common/GameMemory.h
Original file line number Diff line number Diff line change
Expand Up @@ -756,17 +756,21 @@ class MemoryPoolObject

public:

void deleteInstance()
static void deleteInstance(MemoryPoolObject* mpo)
{
if (this)
if (mpo)
{
MemoryPool *pool = this->getObjectMemoryPool(); // save this, since the dtor will nuke our vtbl
this->~MemoryPoolObject(); // it's virtual, so the right one will be called.
pool->freeBlock((void *)this);
MemoryPool *pool = mpo->getObjectMemoryPool(); // save this, since the dtor will nuke our vtbl
mpo->~MemoryPoolObject(); // it's virtual, so the right one will be called.
pool->freeBlock((void *)mpo);
}
}
};

inline void deleteInstance(MemoryPoolObject* mpo)
{
MemoryPoolObject::deleteInstance(mpo);
}


// INLINING ///////////////////////////////////////////////////////////////////
Expand Down Expand Up @@ -906,22 +910,10 @@ class MemoryPoolObjectHolder
MemoryPoolObjectHolder(MemoryPoolObject *mpo = NULL) : m_mpo(mpo) { }
void hold(MemoryPoolObject *mpo) { DEBUG_ASSERTCRASH(!m_mpo, ("already holding")); m_mpo = mpo; }
void release() { m_mpo = NULL; }
~MemoryPoolObjectHolder() { m_mpo->deleteInstance(); }
~MemoryPoolObjectHolder() { deleteInstance(m_mpo); }
};


// ----------------------------------------------------------------------------
/**
Sometimes you want to make a class's destructor protected so that it can only
be destroyed under special circumstances. MemoryPoolObject short-circuits this
by making the destructor always be protected, and the true delete technique
(namely, deleteInstance) always public by default. You can simulate the behavior
you really want by including this macro
*/
#define MEMORY_POOL_DELETEINSTANCE_VISIBILITY(ARGVIS)\
ARGVIS: void deleteInstance() { MemoryPoolObject::deleteInstance(); } public:


#define EMPTY_DTOR(CLASS) inline CLASS::~CLASS() { }

#endif // _GAME_MEMORY_H_
9 changes: 7 additions & 2 deletions Generals/Code/GameEngine/Include/Common/GameMemoryNull.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,12 +108,17 @@ class MemoryPoolObject

public:

void deleteInstance()
static void deleteInstance(MemoryPoolObject* mpo)
{
delete this;
delete mpo;
}
};

inline void deleteInstance(MemoryPoolObject* mpo)
{
MemoryPoolObject::deleteInstance(mpo);
}


/**
Initialize the memory manager. Construct a new MemoryPoolFactory and
Expand Down
4 changes: 2 additions & 2 deletions Generals/Code/GameEngine/Include/Common/Overridable.h
Original file line number Diff line number Diff line change
Expand Up @@ -108,7 +108,7 @@ class Overridable : public MemoryPoolObject
{
if ( m_isOverride )
{
deleteInstance();
deleteInstance(this);
return NULL;
}
else if ( m_nextOverride )
Expand All @@ -123,7 +123,7 @@ class Overridable : public MemoryPoolObject
__inline Overridable::~Overridable()
{
if (m_nextOverride)
m_nextOverride->deleteInstance();
deleteInstance(m_nextOverride);
}


Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Include/Common/ThingTemplate.h
Original file line number Diff line number Diff line change
Expand Up @@ -159,7 +159,7 @@ class AudioArray
{
for (Int i = 0; i < TTAUDIO_COUNT; ++i)
if (m_audio[i])
m_audio[i]->deleteInstance();
deleteInstance(m_audio[i]);
}

AudioArray(const AudioArray& that)
Expand Down
7 changes: 4 additions & 3 deletions Generals/Code/GameEngine/Include/GameLogic/Object.h
Original file line number Diff line number Diff line change
Expand Up @@ -158,8 +158,6 @@ class Object : public Thing, public Snapshot
{

MEMORY_POOL_GLUE_WITH_USERLOOKUP_CREATE(Object, "ObjectPool" )
/// destructor is non-public in order to require the use of TheGameLogic->destroyObject()
MEMORY_POOL_DELETEINSTANCE_VISIBILITY(protected)

public:

Expand Down Expand Up @@ -386,7 +384,7 @@ class Object : public Thing, public Snapshot
Bool isInList(Object **pListHead) const;

// this is intended for use ONLY by GameLogic.
void friend_deleteInstance() { deleteInstance(); }
static void friend_deleteInstance(Object* object) { deleteInstance(object); }

@Mauller Mauller May 17, 2025

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Same heres as mentioned above, might be better to use mpo as the argument name. Although this one is talking about actual object class objects, but maybe the argument should be of type MemoryPoolObject*?

@xezon xezon May 17, 2025

Copy link
Copy Markdown
Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I actually intentionally put Object* here, because it is meant to destroy an Object, and not some other type right?

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah it makes sense, i was considering that the underlying deleteInstance expects a MemoryPoolObject so that gets hidden in a way. But i think an Object is always a MemoryPoolObject so it shouldn't be an issue.


/// cache the partition module (should be called only by PartitionData)
void friend_setPartitionData(PartitionData *pd) { m_partitionData = pd; }
Expand Down Expand Up @@ -765,6 +763,9 @@ class Object : public Thing, public Snapshot

}; // end class Object

// deleteInstance is not meant to be used with Object in order to require the use of TheGameLogic->destroyObject()
void deleteInstance(Object* object) CPP_11(= delete);
Comment thread
Mauller marked this conversation as resolved.
Outdated

// describe an object as an AsciiString: e.g. "Object 102 (KillerBuggy) [GLARocketBuggy, owned by player 2 (GLAIntroPlayer)]"
AsciiString DebugDescribeObject(const Object *obj);

Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Include/GameLogic/ObjectIter.h
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ enum IterOrderType CPP_11(: Int)
{
// do something with other
}
iter->deleteInstance(); // you own it, so you must delete it
deleteInstance(iter); // you own it, so you must delete it

note that the iterator is required to deal intelligently with deleted objects;
in particular, next() will check if an obj has been killed and simply skip it.
Expand Down
6 changes: 3 additions & 3 deletions Generals/Code/GameEngine/Source/Common/Audio/GameAudio.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -188,7 +188,7 @@ AudioManager::~AudioManager()
for (it = m_allAudioEventInfo.begin(); it != m_allAudioEventInfo.end(); ++it) {
AudioEventInfo *eventInfo = (*it).second;
if (eventInfo) {
eventInfo->deleteInstance();
deleteInstance(eventInfo);
eventInfo = NULL;
}
}
Expand Down Expand Up @@ -811,7 +811,7 @@ AudioRequest *AudioManager::allocateAudioRequest( Bool useAudioEvent )
void AudioManager::releaseAudioRequest( AudioRequest *requestToRelease )
{
if (requestToRelease) {
requestToRelease->deleteInstance();
deleteInstance(requestToRelease);
}
}

Expand Down Expand Up @@ -894,7 +894,7 @@ void AudioManager::removeLevelSpecificAudioEventInfos(void)

if ( it->second->isLevelSpecific() )
{
it->second->deleteInstance();
deleteInstance(it->second);
m_allAudioEventInfo.erase( it );
}

Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Source/Common/GameEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -536,7 +536,7 @@ void GameEngine::reset( void )
if(background)
{
background->destroyWindows();
background->deleteInstance();
deleteInstance(background);
background = NULL;
}
}
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Source/Common/GlobalData.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1061,7 +1061,7 @@ GlobalData::~GlobalData( void )
DEBUG_ASSERTCRASH( TheWritableGlobalData->m_next == NULL, ("~GlobalData: theOriginal is not original\n") );

if (m_weaponBonusSet)
m_weaponBonusSet->deleteInstance();
deleteInstance(m_weaponBonusSet);

if( m_theOriginal == this ) {
m_theOriginal = NULL;
Expand Down
2 changes: 1 addition & 1 deletion Generals/Code/GameEngine/Source/Common/INI/INI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1151,7 +1151,7 @@ void INI::parseDynamicAudioEventRTS( INI *ini, void * /*instance*/, void *store,
{
if (*theSound)
{
(*theSound)->deleteInstance();
deleteInstance(*theSound);
*theSound = NULL;
}
}
Expand Down
8 changes: 4 additions & 4 deletions Generals/Code/GameEngine/Source/Common/MessageStream.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ GameMessage::~GameMessage( )
for( arg = m_argList; arg; arg=nextArg )
{
nextArg = arg->m_next;
arg->deleteInstance();
deleteInstance(arg);
}

// detach message from list
Expand Down Expand Up @@ -678,7 +678,7 @@ GameMessageList::~GameMessageList()
// set list ptr to null to avoid it trying to remove itself from the list
// that we are in the process of nuking...
msg->friend_setList(NULL);
msg->deleteInstance();
deleteInstance(msg);
}
}

Expand Down Expand Up @@ -1064,7 +1064,7 @@ void MessageStream::propagateMessages( void )
next = msg->next();
if (disp == DESTROY_MESSAGE)
{
msg->deleteInstance();
deleteInstance(msg);
}
}
else
Expand Down Expand Up @@ -1151,7 +1151,7 @@ void CommandList::destroyAllMessages( void )
for( msg=m_firstMessage; msg; msg=next )
{
next = msg->next();
msg->deleteInstance();
deleteInstance(msg);
}

m_firstMessage = NULL;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ void NameKeyGenerator::freeSockets()
for (Bucket *b = m_sockets[i]; b; b = next)
{
next = b->m_nextInSocket;
b->deleteInstance();
deleteInstance(b);
}
m_sockets[i] = NULL;
}
Expand Down
Loading