Fix crash due to missing asset reference inside MeshAccelerationStructure
This commit is contained in:
@@ -288,6 +288,15 @@ bool MeshAccelerationStructure::RayCastBVH(int32 node, const Ray& ray, Real& hit
|
|||||||
return hit;
|
return hit;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
MeshAccelerationStructure::~MeshAccelerationStructure()
|
||||||
|
{
|
||||||
|
for (auto& e : _meshes)
|
||||||
|
{
|
||||||
|
if (e.Asset)
|
||||||
|
e.Asset->RemoveReference();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void MeshAccelerationStructure::Add(Model* model, int32 lodIndex)
|
void MeshAccelerationStructure::Add(Model* model, int32 lodIndex)
|
||||||
{
|
{
|
||||||
PROFILE_CPU();
|
PROFILE_CPU();
|
||||||
@@ -307,6 +316,8 @@ void MeshAccelerationStructure::Add(Model* model, int32 lodIndex)
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto& meshData = _meshes.AddOne();
|
auto& meshData = _meshes.AddOne();
|
||||||
|
meshData.Asset = model;
|
||||||
|
model->AddReference();
|
||||||
if (model->IsVirtual())
|
if (model->IsVirtual())
|
||||||
{
|
{
|
||||||
meshData.Indices = mesh.GetTriangleCount() * 3;
|
meshData.Indices = mesh.GetTriangleCount() * 3;
|
||||||
@@ -350,6 +361,7 @@ void MeshAccelerationStructure::Add(const ModelData* modelData, int32 lodIndex,
|
|||||||
}
|
}
|
||||||
|
|
||||||
auto& meshData = _meshes.AddOne();
|
auto& meshData = _meshes.AddOne();
|
||||||
|
meshData.Asset = nullptr;
|
||||||
meshData.Indices = mesh->Indices.Count();
|
meshData.Indices = mesh->Indices.Count();
|
||||||
meshData.Vertices = mesh->Positions.Count();
|
meshData.Vertices = mesh->Positions.Count();
|
||||||
if (copy)
|
if (copy)
|
||||||
@@ -370,6 +382,7 @@ void MeshAccelerationStructure::Add(const ModelData* modelData, int32 lodIndex,
|
|||||||
void MeshAccelerationStructure::Add(Float3* vb, int32 vertices, void* ib, int32 indices, bool use16BitIndex, bool copy)
|
void MeshAccelerationStructure::Add(Float3* vb, int32 vertices, void* ib, int32 indices, bool use16BitIndex, bool copy)
|
||||||
{
|
{
|
||||||
auto& meshData = _meshes.AddOne();
|
auto& meshData = _meshes.AddOne();
|
||||||
|
meshData.Asset = nullptr;
|
||||||
if (copy)
|
if (copy)
|
||||||
{
|
{
|
||||||
meshData.VertexBuffer.Copy((const byte*)vb, vertices * sizeof(Float3));
|
meshData.VertexBuffer.Copy((const byte*)vb, vertices * sizeof(Float3));
|
||||||
|
|||||||
@@ -20,6 +20,7 @@ class FLAXENGINE_API MeshAccelerationStructure
|
|||||||
private:
|
private:
|
||||||
struct Mesh
|
struct Mesh
|
||||||
{
|
{
|
||||||
|
Model* Asset;
|
||||||
BytesContainer IndexBuffer, VertexBuffer;
|
BytesContainer IndexBuffer, VertexBuffer;
|
||||||
int32 Indices, Vertices;
|
int32 Indices, Vertices;
|
||||||
bool Use16BitIndexBuffer;
|
bool Use16BitIndexBuffer;
|
||||||
@@ -57,6 +58,8 @@ private:
|
|||||||
bool RayCastBVH(int32 node, const Ray& ray, Real& hitDistance, Vector3& hitNormal, Triangle& hitTriangle) const;
|
bool RayCastBVH(int32 node, const Ray& ray, Real& hitDistance, Vector3& hitNormal, Triangle& hitTriangle) const;
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
~MeshAccelerationStructure();
|
||||||
|
|
||||||
// Adds the model geometry for the build to the structure.
|
// Adds the model geometry for the build to the structure.
|
||||||
void Add(Model* model, int32 lodIndex);
|
void Add(Model* model, int32 lodIndex);
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user