Skip to content

Commit

Permalink
17.8-dev8
Browse files Browse the repository at this point in the history
Fix skeletal mesh vobs memory leak (e.g. when saving game)
  • Loading branch information
SaiyansKing committed Jun 22, 2022
1 parent 20cf841 commit 1220f78
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 12 deletions.
1 change: 1 addition & 0 deletions D3D11Engine/D3D11GraphicsEngine.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -2281,6 +2281,7 @@ XRESULT D3D11GraphicsEngine::OnStartWorldRendering() {
// TODO: Only get them once!
if ( Engine::GAPI->GetRendererState().RendererSettings.DrawParticleEffects ) {
std::vector<zCVob*> decals;
zCCamera::GetCamera()->Activate();
Engine::GAPI->GetVisibleDecalList( decals );

// Draw stuff like candle-flames
Expand Down
27 changes: 16 additions & 11 deletions D3D11Engine/GothicAPI.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ GothicAPI::GothicAPI() {
MainThreadID = GetCurrentThreadId();

_canRain = false;
_canClearVobsByVisual = true;
}

GothicAPI::~GothicAPI() {
Expand Down Expand Up @@ -664,7 +665,7 @@ void GothicAPI::OnGeometryLoaded( zCPolygon** polys, unsigned int numPolygons )

/** Called when the game is about to load a new level */
void GothicAPI::OnLoadWorld( const std::string& levelName, int loadMode ) {
_canClearVobsByVisual = true;
//_canClearVobsByVisual = true;
if ( (loadMode == 0 || loadMode == 2) && !levelName.empty() ) {
std::string name = levelName;
const size_t last_slash_idx = name.find_last_of( "\\/" );
Expand Down Expand Up @@ -757,7 +758,7 @@ void GothicAPI::OnWorldLoaded() {
Engine::GraphicsEngine->OnUIEvent( BaseGraphicsEngine::UI_OpenEditor );
#endif

_canClearVobsByVisual = false;
//_canClearVobsByVisual = false;
}

void GothicAPI::LoadRendererWorldSettings( GothicRendererSettings& s ) {
Expand Down Expand Up @@ -1512,23 +1513,23 @@ void GothicAPI::OnRemovedVob( zCVob* vob, zCWorld* world ) {
for ( unsigned int i = 0; i < nodes->size(); i++ ) {
BspInfo* node = (*nodes)[i];
if ( vi ) {
for ( std::vector<VobInfo*>::iterator bit = node->IndoorVobs.begin(); bit != node->IndoorVobs.end(); ++bit ) {
for ( auto bit = node->IndoorVobs.begin(); bit != node->IndoorVobs.end(); ++bit ) {
if ( (*bit) == vi ) {
(*bit) = node->IndoorVobs.back();
node->IndoorVobs.pop_back();
break;
}
}

for ( std::vector<VobInfo*>::iterator bit = node->Vobs.begin(); bit != node->Vobs.end(); ++bit ) {
for ( auto bit = node->Vobs.begin(); bit != node->Vobs.end(); ++bit ) {
if ( (*bit) == vi ) {
(*bit) = node->Vobs.back();
node->Vobs.pop_back();
break;
}
}

for ( std::vector<VobInfo*>::iterator bit = node->SmallVobs.begin(); bit != node->SmallVobs.end(); ++bit ) {
for ( auto bit = node->SmallVobs.begin(); bit != node->SmallVobs.end(); ++bit ) {
if ( (*bit) == vi ) {
(*bit) = node->SmallVobs.back();
node->SmallVobs.pop_back();
Expand All @@ -1538,15 +1539,15 @@ void GothicAPI::OnRemovedVob( zCVob* vob, zCWorld* world ) {
}

if ( li && nodes ) {
for ( std::vector<VobLightInfo*>::iterator bit = node->Lights.begin(); bit != node->Lights.end(); ++bit ) {
for ( auto bit = node->Lights.begin(); bit != node->Lights.end(); ++bit ) {
if ( (*bit)->Vob == static_cast<zCVobLight*>(vob) ) {
(*bit) = node->Lights.back();
node->Lights.pop_back();
break;
}
}

for ( std::vector<VobLightInfo*>::iterator bit = node->IndoorLights.begin(); bit != node->IndoorLights.end(); ++bit ) {
for ( auto bit = node->IndoorLights.begin(); bit != node->IndoorLights.end(); ++bit ) {
if ( (*bit)->Vob == static_cast<zCVobLight*>(vob) ) {
(*bit) = node->IndoorLights.back();
node->IndoorLights.pop_back();
Expand All @@ -1556,8 +1557,8 @@ void GothicAPI::OnRemovedVob( zCVob* vob, zCWorld* world ) {
}

if ( svi && nodes ) {
for ( std::vector<SkeletalVobInfo*>::iterator bit = node->Mobs.begin(); bit != node->Mobs.end(); ++bit ) {
if ( (*bit)->Vob == static_cast<zCVobLight*>(vob) ) {
for ( auto bit = node->Mobs.begin(); bit != node->Mobs.end(); ++bit ) {
if ( (*bit)->Vob == vob ) {
(*bit) = node->Mobs.back();
node->Mobs.pop_back();
break;
Expand All @@ -1566,7 +1567,6 @@ void GothicAPI::OnRemovedVob( zCVob* vob, zCWorld* world ) {
}
}
}
SkeletalVobMap.erase( vob );

// Erase the vob from the section
if ( vi && vi->VobSection ) {
Expand Down Expand Up @@ -1601,7 +1601,12 @@ void GothicAPI::OnRemovedVob( zCVob* vob, zCWorld* world ) {
auto vit = VobMap.find( vob );
if ( vit != VobMap.end() ) {
delete (*vit).second;
VobMap.erase( vob );
VobMap.erase( vit );
}
auto svit = SkeletalVobMap.find( vob );
if ( svit != SkeletalVobMap.end() ) {
delete (*svit).second;
SkeletalVobMap.erase( svit );
}

// delete light info, if valid
Expand Down
2 changes: 1 addition & 1 deletion D3D11Engine/pch.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ using namespace DirectX;

#define ENABLE_TESSELATION 0

#define VERSION_NUMBER "17.8-dev7"
#define VERSION_NUMBER "17.8-dev8"
__declspec(selectany) const char* VERSION_NUMBER_STR = VERSION_NUMBER;

extern bool FeatureLevel10Compatibility;
Expand Down

0 comments on commit 1220f78

Please sign in to comment.