Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

GLTF: Fix bad pointer to ImporterMeshInstance3D root node at runtime #98048

Merged
merged 1 commit into from
Dec 16, 2024

Conversation

aaronfranke
Copy link
Member

@aaronfranke aaronfranke commented Oct 10, 2024

Fixes #98038

This bug was caused by the root node getting deleted by GLTFDocumentExtensionConvertImporterMesh at runtime only. I added some code to handle this in GLTFDocument::generate_scene, which calls a function in that long-named class which used to be a part of import_post but is now its own function (this is more readable anyway, IMO). I also enhanced the function a bit, now it will do a partial convert instead of giving up if the mesh is somehow null.

Note that in this PR, I opted for a specific solution, not a general one. In general, we do not expect that users should be replacing nodes after the scene has been generated, instead they should just generate the correct nodes the first time. The ImporterMeshInstance3D class in Godot is the one big exception to this rule.

@fire
Copy link
Member

fire commented Oct 10, 2024

The design is ok, did not review the technical code yet

@lyuma
Copy link
Contributor

lyuma commented Oct 11, 2024

I don't really understand any of the changes this is making, except for one: using a different codepath to replace the root node without crashing.

I think what I'd prefer is to add a check in GLTFDocumentExtensionConvertImporterMesh::import_post to return the replaced root node if it differs from p_root.

We might need to change an API to do this, but the ability to arbitrarily replace the root node with any other type of node would be miles better than a special case in GLTFDocument for ImporterMeshInstance3D.

@aaronfranke aaronfranke force-pushed the gltf-runtime-root-imp-mesh branch 2 times, most recently from fda72b4 to 8f8558a Compare December 2, 2024 12:48
@aaronfranke aaronfranke force-pushed the gltf-runtime-root-imp-mesh branch from 8f8558a to de87ca5 Compare December 16, 2024 02:06
@akien-mga
Copy link
Member

I think this can be fine as a stopgap solution, but I agree with @lyuma that the API could be improved. The changes in gltf_document.cpp seem a bit like a hack, though I'm not deeply familiar with how that process is intended to go.

@Repiteo Repiteo merged commit ddaef7a into godotengine:master Dec 16, 2024
20 checks passed
@Repiteo
Copy link
Contributor

Repiteo commented Dec 16, 2024

Thanks!

@aaronfranke
Copy link
Member Author

It is my opinion that this little hack is fine, because ImporterMeshInstance3D should be the only case where a generated node is not the same at import time compared to runtime. For everything else, we don't have an "Importer" version of the node. And, in fact, I would argue we should get rid of ImporterMeshInstance3D, and instead just use set_meta on MeshInstance3D to store the ImporterMesh3D.

@aaronfranke aaronfranke deleted the gltf-runtime-root-imp-mesh branch December 16, 2024 23:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

GLTFDocument loader returns Freed Object at runtime
5 participants