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

" handle.ScheduleUpdateOnce" will make unity crash when Texture.Reinitialize() if not executed Texture.Apply() #5

Open
CortexCore opened this issue Dec 23, 2024 · 5 comments · May be fixed by #7
Labels
bug Something isn't working

Comments

@CortexCore
Copy link

CortexCore commented Dec 23, 2024

if (Thumbnail.TryGetValue(fileName, out var thumbnail))
                {
                    thumbnail.Reinitialize(newThumbnail.width, newThumbnail.height);
                   //if don't apply,will make unity crash and cannot find any related log
                    thumbnail.Apply();
                    
                   var handle = ThumbnailApplyAsyncHandles.GetOrAdd(fileName, _ => new TextureApplyAsyncHandle(thumbnail));
                
                    thumbnail.SetPixels32(newThumbnail.GetPixels32());
                    
                    //thumbnail.Apply();
                    
                    //if don't Apply Texture before,will make unity crash
                    handle.ScheduleUpdateOnce();
@CortexCore CortexCore changed the title Make Unity crash while Texture.Reinit Make Unity crash while execute Texture.Reinitialize and not Texture.Apply Dec 23, 2024
@CortexCore CortexCore changed the title Make Unity crash while execute Texture.Reinitialize and not Texture.Apply " handle.ScheduleUpdateOnce" will make unity crash when Texture.Reinitialize() if not executed Texture.Apply() Dec 23, 2024
@CortexCore
Copy link
Author

sry about that I can't accurate description in title

@gilzoide
Copy link
Owner

Hey @CortexCore, thanks for the report.
When you reinitialize a texture, its pixel data is release and reinitialized. The TextureApplyAsyncHandle stores a pointer to the texture's pixel data, so you should Dispose of your TextureApplyAsyncHandle and create a new one after you reinitialize the texture instead of reusing it.

I don't know if there's a good way for this package to detect texture reinitialization and reinitialize itself as well 🤔 Maybe we can store and check if the data pointer changed to reinitialize the handle. Rechecking for texture reinitialization every frame for every scheduled handle seems like an unnecessary overhead to me, its quite the corner case.
Adding a TextureApplyAsyncHandle.Reinitialize method and document that it should be called whenever you reinitialize the texture is another option.

What do you think? Any suggestions?

@gilzoide gilzoide added the bug Something isn't working label Dec 23, 2024
@CortexCore
Copy link
Author

thanks for your reply
okey, guess just figured out why the ScheduleUpdateOnce will crash unity and how avoid this situation
my wanted is new a texture like proxy first, then use TextureApplyAsyncHandle to apply it at runtime, sounds like a lazy load

so I think dispose TextureApplyAsyncHandle and new texture is not a perfect solution.

that's how I think use TextureApplyAsyncHandle will make the "repaint" progress faster.

🤔I think add a function like TextureApplyAsyncHandle.Reinitialize or TextureApplyAsyncHandle.MarkAsDirty is a good options,
Rechecking for texture reinitialization every frame for every scheduled handle is too unnecessary like you said.

@gilzoide
Copy link
Owner

Hey @CortexCore, in the PR above I added the TextureApplyAsyncHandle.Reinitialize method that you should call after reinitializing your texture. It is in the feature/reinitialize-handle branch, if you could please test it and report if it works properly before merging, I'd appreciate it.

@CortexCore
Copy link
Author

Your update is much appreciated, I'll test it against this time and submit a test report here : D

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
2 participants