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

Fix creating multiple asset instances #7269 #7288

Merged
merged 3 commits into from
Oct 23, 2023
Merged

Conversation

z3moon
Copy link
Contributor

@z3moon z3moon commented Oct 23, 2023

No description provided.

@z3moon z3moon added the internal Issue/PR does not affect clients label Oct 23, 2023
@z3moon z3moon requested a review from pixelflinger October 23, 2023 20:43
@z3moon z3moon linked an issue Oct 23, 2023 that may be closed by this pull request
libs/gltfio/src/AssetLoader.cpp Show resolved Hide resolved
The temporary variable has been used to store the current instance of
FFilamentAsset being loaded for easy access from internal methods.  This
causes a crash as to a complex scenario as follows.

val asset1 = assetLoader.createAsset(assetBuffer1)
val instance1 = assetLoader.createInstance(asset1)
val asset2 = assetLoader.createAsset(assetBuffer2)
val instance2 = assetLoader.createInstance(asset1)

As the first step of fixing this issue, remove the transient property
`mAsset` from FAssetLoader. This commit alone doesn't resolve the issue,
and more commits are following.

Consolidate the low level version of createInstance, which takes a
pointer to cgltf_data type, into the high level version as the latter
one uses a parameter for FFilamentAsset instead of referencing mAsset.

Update all other relevant methods to take a FFilamentAsset pointer
instead of cgltf_data.

This partially fixes #7269
There's no functional change in this commit.

Make some parameter names more legible by renaming them and put output
parameters to the right of their function.
The transient property `mRootNotes` in FAssetLoader is built when a new
root asset is created and referenced whenever a new instance is created.
So it incurs an undefined behavior when a previously created asset tries
creating a new instance after a newly created asset has already created
via the same asset loader.

Move this transient property to each asset so that they can reference it
when a new instance is created.

This partially fixes #7269
@z3moon z3moon force-pushed the zm/multi-asset-instances branch from 6345c1f to 3d02d89 Compare October 23, 2023 21:49
@z3moon z3moon merged commit d3016ad into main Oct 23, 2023
@z3moon z3moon deleted the zm/multi-asset-instances branch October 23, 2023 22:30
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
internal Issue/PR does not affect clients
Projects
None yet
Development

Successfully merging this pull request may close these issues.

gltfio: Can't create multiple asset instances
3 participants