diff --git a/LEGO1/lego/legoomni/src/common/legogamestate.cpp b/LEGO1/lego/legoomni/src/common/legogamestate.cpp index fb50b5ef..2eed281c 100644 --- a/LEGO1/lego/legoomni/src/common/legogamestate.cpp +++ b/LEGO1/lego/legoomni/src/common/legogamestate.cpp @@ -203,6 +203,8 @@ LegoGameState::~LegoGameState() } delete[] m_savePath; + + delete LegoOmni::GetInstance()->GetUserActor(); } // FUNCTION: LEGO1 0x10039780 diff --git a/LEGO1/lego/legoomni/src/video/legophonemepresenter.cpp b/LEGO1/lego/legoomni/src/video/legophonemepresenter.cpp index 6ea4d36d..4fb45695 100644 --- a/LEGO1/lego/legoomni/src/video/legophonemepresenter.cpp +++ b/LEGO1/lego/legoomni/src/video/legophonemepresenter.cpp @@ -157,6 +157,7 @@ void LegoPhonemePresenter::EndAction() TextureContainer()->EraseCached(phoneme->GetCachedTextureInfo()); TextureContainer()->EraseCached(phoneme->GetTextureInfo()); cursor.Destroy(); + phoneme = NULL; } else { phoneme->SetCount(phoneme->GetCount() - 1); @@ -167,5 +168,9 @@ void LegoPhonemePresenter::EndAction() CharacterManager()->ReleaseActor(m_roiName.GetData()); } } + else { + delete phoneme; + phoneme = NULL; + } } } diff --git a/LEGO1/lego/sources/misc/legocontainer.cpp b/LEGO1/lego/sources/misc/legocontainer.cpp index 693f9b27..142160a4 100644 --- a/LEGO1/lego/sources/misc/legocontainer.cpp +++ b/LEGO1/lego/sources/misc/legocontainer.cpp @@ -119,7 +119,7 @@ void LegoTextureContainer::EraseCached(LegoTextureInfo* p_textureInfo) if ((*it).first == p_textureInfo) { (*it).second = FALSE; - if (p_textureInfo->m_texture->Release() == TRUE) { + if (p_textureInfo->m_texture->Release() == 1) { delete p_textureInfo; m_cached.erase(it); } diff --git a/LEGO1/tgl/d3drm/light.cpp b/LEGO1/tgl/d3drm/light.cpp index cdb577f1..a26a8623 100644 --- a/LEGO1/tgl/d3drm/light.cpp +++ b/LEGO1/tgl/d3drm/light.cpp @@ -43,7 +43,13 @@ inline Result LightSetColor(IDirect3DRMFrame2* pLight, float r, float g, float b result = ResultVal(lights->GetElement(0, &light)); assert(Succeeded(result)); - return ResultVal(light->SetColorRGB(r, g, b)); + lights->Release(); + + result = ResultVal(light->SetColorRGB(r, g, b)); + + light->Release(); + + return result; } // FUNCTION: LEGO1 0x100a37e0 diff --git a/miniwin/src/d3drm/d3drmmesh.cpp b/miniwin/src/d3drm/d3drmmesh.cpp index 2765971c..d3b48a70 100644 --- a/miniwin/src/d3drm/d3drmmesh.cpp +++ b/miniwin/src/d3drm/d3drmmesh.cpp @@ -25,16 +25,6 @@ HRESULT Direct3DRMMeshImpl::Clone(int flags, GUID iid, void** object) auto* clone = new Direct3DRMMeshImpl(*this); - for (auto& group : clone->m_groups) { - // Reusing the same texture and material on the new mesh instead of cloning them might not be correct - if (group.texture) { - group.texture->AddRef(); - } - if (group.material) { - group.material->AddRef(); - } - } - *object = static_cast(clone); return DD_OK; } @@ -154,12 +144,13 @@ HRESULT Direct3DRMMeshImpl::SetGroupMaterial(D3DRMGROUPINDEX groupIndex, IDirect return DDERR_INVALIDPARAMS; } + material->AddRef(); + auto& group = m_groups[groupIndex]; if (group.material) { group.material->Release(); } - material->AddRef(); m_groups[groupIndex].material = material; return DD_OK; } @@ -170,15 +161,13 @@ HRESULT Direct3DRMMeshImpl::SetGroupTexture(D3DRMGROUPINDEX groupIndex, IDirect3 return DDERR_INVALIDPARAMS; } + texture->AddRef(); + auto& group = m_groups[groupIndex]; if (group.texture) { group.texture->Release(); } - texture->AddRef(); - if (group.texture) { - group.texture->Release(); - } group.texture = texture; group.version++; return DD_OK; diff --git a/miniwin/src/ddraw/ddsurface.cpp b/miniwin/src/ddraw/ddsurface.cpp index 9e710596..58ee938a 100644 --- a/miniwin/src/ddraw/ddsurface.cpp +++ b/miniwin/src/ddraw/ddsurface.cpp @@ -232,13 +232,14 @@ HRESULT DirectDrawSurfaceImpl::SetPalette(LPDIRECTDRAWPALETTE lpDDPalette) m_texture->Changed(FALSE, TRUE); } + lpDDPalette->AddRef(); + if (m_palette) { m_palette->Release(); } m_palette = lpDDPalette; SDL_SetSurfacePalette(m_surface, ((DirectDrawPaletteImpl*) m_palette)->m_palette); - m_palette->AddRef(); return DD_OK; } diff --git a/miniwin/src/ddraw/framebuffer.cpp b/miniwin/src/ddraw/framebuffer.cpp index 2602e218..82022649 100644 --- a/miniwin/src/ddraw/framebuffer.cpp +++ b/miniwin/src/ddraw/framebuffer.cpp @@ -214,13 +214,14 @@ HRESULT FrameBufferImpl::SetPalette(LPDIRECTDRAWPALETTE lpDDPalette) MINIWIN_NOT_IMPLEMENTED(); } + lpDDPalette->AddRef(); + if (m_palette) { m_palette->Release(); } m_palette = lpDDPalette; SDL_SetSurfacePalette(m_transferBuffer->m_surface, ((DirectDrawPaletteImpl*) m_palette)->m_palette); - m_palette->AddRef(); return DD_OK; } diff --git a/miniwin/src/internal/d3drmobject_impl.h b/miniwin/src/internal/d3drmobject_impl.h index 6cd449fe..3b4a02f9 100644 --- a/miniwin/src/internal/d3drmobject_impl.h +++ b/miniwin/src/internal/d3drmobject_impl.h @@ -21,8 +21,8 @@ struct Direct3DRMObjectBaseImpl : public T { it->first(this, it->second); } m_callbacks.clear(); + SDL_free(m_name); } - SDL_free(m_name); return this->T::Release(); } HRESULT AddDestroyCallback(D3DRMOBJECTCALLBACK callback, void* arg) override