Git Product home page Git Product logo

Comments (7)

ataulien avatar ataulien commented on August 22, 2024

I assume this was introduced when I added multithreaded bulk-caching in commit 468360f.

If you comment out the line here, does it still crash?

void OriginalGameResources::populateCache()
{
BsZenLib::CacheWholeVDFS(gVirtualFileSystem().getFileIndex());
}

It might worked for me be because I'm using the "low-fidelity" render-pipeline of bsf...

from regoth-bs.

KirmesBude avatar KirmesBude commented on August 22, 2024

EDIT: it is 74b53b0.
EDIT2: Looks like BsMaterial might have some dependency on running on the Core Thread
EDIT3: Yeah, I dont know. I guess for some CoreObject deconstructor is called, but I dont see where that happens for us.
On another note, I have a problem in the previous commits where I only see some black texture :D
No, that does not appear to be it.
I will try to find out which commit causes this, probably easier to go from there.

from regoth-bs.

KirmesBude avatar KirmesBude commented on August 22, 2024

By @mworchel in gitter:

void VisualSkeletalAnimation::destroyClonedMaterials()
{
  for (bs::HMaterial m : mClonedMaterials)
  {
    m->destroy();
  }
  mClonedMaterials.clear();
}

The m->destroy(); is the cause for the crash
Don't know why but it seems that the material core object is not deleted on the core thread. I would just skip the explicit destroy call and just clear the list of cloned materials. bs::HMaterial does reference counting anyway and if the material is not referenced anymore, it should be deleted...I hope

from regoth-bs.

crushack avatar crushack commented on August 22, 2024

Hi, thanks for the pointer, I've been trying to make this work on Friday.

To me, the VisualSkeletalAnimation::destroyClonedMaterials() method seems a bit weird using a member field. It seems to work for me with a bit of refactoring:

  void VisualSkeletalAnimation::cloneMaterials()
  {
    // Access the original materials for cloning
    const auto& materials = mMesh->getMaterials();

    bs::Vector<bs::HMaterial> clonedMaterials(materials.size());
    for (bs::UINT32 i = 0; i < (bs::UINT32)clonedMaterials.size(); i++)
    {
      clonedMaterials[i] = materials[i]->clone();
    }

    mSubRenderable->setMaterials(clonedMaterials);
  }

NOTE: I don't know the code or the libraries it's using very well, but I don't see why materials need to be destroyed, since this should be done by HRenderable, and I also don't see why they need to be memorized in VisualSkeletalAnimation

from regoth-bs.

ataulien avatar ataulien commented on August 22, 2024

I'm not sure whether resources are destroyed when they're not used anymore. If the visual changes meshes, materials would have to be cloned again. If we don't get the clones from the previous mesh deleted, we would have made us a memory leak.

If the cloned materials are really destroyed because of ref-counting, then destroying them manually is certainly wrong.

from regoth-bs.

mworchel avatar mworchel commented on August 22, 2024

HMaterial is a typedef of ResourceHandle<Material> which is in turn a typedef for TResourceHandle<Material, WeakHandle=false>. This class derives from TResourceHandleBase<false> and calls TResourceHandleBase<false>::releaseRef() in the destructor which is defined as

void releaseRef()
{
	if (mData)
	{
		std::uint32_t refCount = mData->mRefCount.fetch_sub(1, std::memory_order_release);

		if (refCount == 1)
		{
			std::atomic_thread_fence(std::memory_order_acquire);
			destroy();
		}
	}
};

So essentially it also calls destroy only that it has this atomic_thread_fence call which I'm not aware of the details. From the looks, this means no memory leaks should be introduced by PR #114 .

from regoth-bs.

crushack avatar crushack commented on August 22, 2024

Thanks Markus, makes sense, and the destructor probably gets called in this method:

template<bool Core>
void TRenderable<Core>::setMaterials(const Vector<MaterialType>& materials)
{
	UINT32 numMaterials = (UINT32)mMaterials.size();
	UINT32 min = std::min(numMaterials, (UINT32)materials.size());

	for (UINT32 i = 0; i < min; i++)
		mMaterials[i] = materials[i];

	for (UINT32 i = min; i < numMaterials; i++)
		mMaterials[i] = nullptr;

	_markDependenciesDirty();
	_markResourcesDirty();
	_markCoreDirty();
}

More precisely:

for (UINT32 i = min; i < numMaterials; i++)
	mMaterials[i] = nullptr;

from regoth-bs.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.