Skip to content

Commit c5699a6

Browse files
Fix primitive node picking non existant primitive and mesh indexes
Handle primitive node not picking a non-existant primitive group and mesh index which can happen if the resource load fails (mesh) but the model continues to load.
1 parent b7182a9 commit c5699a6

File tree

4 files changed

+16
-5
lines changed

4 files changed

+16
-5
lines changed

code/render/coregraphics/meshloader.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,6 @@ class MeshLoader : public Resources::ResourceLoader
3737

3838
/// setup mesh from nvx3 file in memory
3939
void SetupMeshFromNvx(const Ptr<IO::Stream>& stream, const MeshResourceId entry);
40-
4140
};
4241

4342
} // namespace CoreGraphics

code/render/models/nodes/primitivenode.cc

Lines changed: 14 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -45,13 +45,23 @@ PrimitiveNode::Load(const Util::FourCC& fourcc, const Util::StringAtom& tag, con
4545

4646
// Load directly, since the model is already loaded on a thread, this is fine
4747
//this->primitiveGroupIndex = 0;
48-
this->res = Resources::CreateResource(meshName, tag, nullptr, nullptr, true);
48+
this->res = Resources::CreateResource(
49+
meshName,
50+
tag,
51+
[this](Resources::ResourceId)
52+
{
53+
this->loadSuccess = true;
54+
},
55+
nullptr,
56+
true
57+
);
4958

5059
}
5160
else if (FourCC('MSHI') == fourcc)
5261
{
5362
CoreGraphics::MeshResourceId meshRes = this->res;
54-
IndexT meshIndex = reader->ReadUInt();
63+
uint index = reader->ReadUInt();
64+
IndexT meshIndex = this->loadSuccess ? index : 0;
5565
this->mesh = MeshResourceGetMesh(meshRes, meshIndex);
5666

5767
this->vbo = CoreGraphics::MeshGetVertexBuffer(this->mesh, 0);
@@ -66,7 +76,8 @@ PrimitiveNode::Load(const Util::FourCC& fourcc, const Util::StringAtom& tag, con
6676
else if (FourCC('PGRI') == fourcc)
6777
{
6878
// primitive group index
69-
this->primitiveGroupIndex = reader->ReadUInt();
79+
uint index = reader->ReadUInt();
80+
this->primitiveGroupIndex = this->loadSuccess ? index : 0;
7081
this->primGroup = CoreGraphics::MeshGetPrimitiveGroups(this->mesh)[this->primitiveGroupIndex];
7182
}
7283
else

code/render/models/nodes/primitivenode.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,7 @@ class PrimitiveNode : public ShaderStateNode
3939
Resources::ResourceId res;
4040
CoreGraphics::MeshId mesh;
4141
uint16_t primitiveGroupIndex;
42+
bool loadSuccess = false;
4243

4344
CoreGraphics::BufferId vbo, ibo;
4445
IndexT baseVboOffset, attributesVboOffset, iboOffset;

code/resource/resources/resourceloader.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -184,7 +184,7 @@ class ResourceLoader : public Core::RefCounted
184184
Util::FixedArray<_PlaceholderResource> placeholders;
185185

186186
/// get placeholder based on resource name
187-
virtual Resources::ResourceId GetPlaceholder(const Resources::ResourceName& name);
187+
Resources::ResourceId GetPlaceholder(const Resources::ResourceName& name);
188188

189189
/// these types need to be properly initiated in a subclass Setup function
190190
Util::StringAtom placeholderResourceName;

0 commit comments

Comments
 (0)