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

LODIndexFence #2330

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open

LODIndexFence #2330

wants to merge 5 commits into from

Conversation

cNori
Copy link
Contributor

@cNori cNori commented Mar 17, 2024

fixes 2 cases
case 1 index was invalid
case 2 model was not ready for use
this this case the code with wait it will print a information about this

[ 00:00:26.749 ]: [Warning] Can't get Model LODs, Model is not initialized yet. awaiting...
[ 00:00:26.751 ]: [Info] Model is now initialized... took ~1ms

it not always triggered looks like it is something to do with async loading of the asset its 90% time triggering when model is first loaded and is not existing the the scene

awaiting time is dependent on model complexity

@Menotdan
Copy link
Contributor

What exactly are you doing to cause the issue this is trying to fix? This doesn't seem like a good solution..

@cNori
Copy link
Contributor Author

cNori commented Mar 18, 2024

What exactly are you doing to cause the issue this is trying to fix? This doesn't seem like a good solution..

model.Model.GetBox(Transform.Identity); when is called in OnAwake is has chanse to crash the engine even if index provided is valid but model is not ready yet
to read the LODs
to trigger it 90% the time the model with is loaded cannot be in the scene
call to PrefabMenager.Spawn()
attath a script wich calls to model.Model.GetBox(Transform.Identity); in OnAwake to the prefab
and test it it might not trigger at all then try difrent model.

also if provided LOD index is out of range it will also crash
this is current behavior of the engine

@mafiesto4
Copy link
Member

The correct way to access any asset data is to ensure it has been loaded - Content load task might modify the asset before so code that doesn't check might fail due to memory/threading issues. Use asset.WaitForLoaded() that returns true if asset is not loaded properly.

@mafiesto4 mafiesto4 added the content Game content and assets label Mar 18, 2024
@cNori
Copy link
Contributor Author

cNori commented Mar 18, 2024

The correct way to access any asset data is to ensure it has been loaded - Content load task might modify the asset before so code that doesn't check might fail due to memory/threading issues. Use asset.WaitForLoaded() that returns true if asset is not loaded properly.

i will try it if it fails i will follow up

@Menotdan
Copy link
Contributor

I'm still not sure what the point of the LODIndexFence function is, you should just be able to use WaitForLoaded() directly in the problematic code, and then once it's loaded (if it succeeds), you can check if the index is valid.

@cNori
Copy link
Contributor Author

cNori commented Mar 18, 2024

I'm still not sure what the point of the LODIndexFence function is, you should just be able to use WaitForLoaded() directly in the problematic code, and then once it's loaded (if it succeeds), you can check if the index is valid.

there is not cheeks casualty saying u need to use WaitFor Loaded unless u know why this is happening remember some devs are beginners and might just keep crashing the engine

one of the rules of software engineering is don't trust user input
2.
code should not allows to access invalid index in first place it makes the code kinda explosive in case asserts are disabled the os will slap u instead of flax errors

@Menotdan
Copy link
Contributor

there is not cheeks casualty saying u need to use WaitFor Loaded unless u know why this is happening remember some devs are beginners and might just keep crashing the engine

one of the rules of software engineering is don't trust user input 2. code should not allows to access invalid index in first place it makes the code kinda explosive in case asserts are disabled the os will slap u instead of flax errors

I'm not sure how using an engine provided function to handle waiting for engine provided asset loading is trusting user input lol (unless I'm misunderstanding something you said)

And yes you shouldn't allow access to an invalid index, that's what calling the IsValidIndex() function is for.

@cNori
Copy link
Contributor Author

cNori commented Mar 18, 2024

I'm not sure how using an engine provided function to handle waiting for engine provided asset loading is trusting user input lol (unless I'm misunderstanding something you said)

in this case it will say it cant load it so asset missing or something else is wrong

other aprouthe is just to throw a error and, let the user deal with it

@Menotdan
Copy link
Contributor

Menotdan commented Mar 18, 2024

in this case it will say it cant load it so asset missing or something else is wrong

other aprouthe is just to throw a error and, let the user deal with it

Yes, WaitForLoaded() will complain if it can't load the asset. This is normal behavior and should be standardized across the engine. If you don't like how that error is reported, you can change it (in a separate PR preferrably). The asset failing to load is independent of handling the model LOD indices. I suggest simply adding WaitForLoaded() on the functions which are currently causing crashes, and then once you've called WaitForLoaded() (and handling errors), check if the LOD index is valid.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
content Game content and assets
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants