-
-
Notifications
You must be signed in to change notification settings - Fork 168
Fix concurrent issue of ASTC context #292
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
Conversation
| if len(selection) == 0: | ||
| raise NotImplementedError( | ||
| f"Not implemented texture format: {texture_format.name}" | ||
| f"Not implemented texture format: {texture_format}" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Good catch, I forgot that texture_format could still be an int.
As the int number isn't that telling imo, it would be better to cast the format to the enum and print it's name if possible, and only show the number if that is not possible.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If the int can be cast to the enum, it is very likely to be a known format that has been implemented. In other words, the unimplemented texture format is very likely to be not castable. So showing the int value is enough.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Not all of them are implemented atm, but so far I haven't seen any of those in the wild either.
So I guess it's indeed fine to keep it as is as int.
K0lb3
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the PR and the fixes.
I just want to see two little changes overall, reducing the lock scope to the specific context usage and replacing Union[foo, None] with Optional[foo].
|
Thanks a lot 👍 |
Summary
This PR mainly fixes the concurrent issue of ASTC context in
Texture2DConverter. By the way, it also fixes some type errors and type hints inTexture2DConverter.1. ASTC Context Concurrent Issue
How do I discovered this issue:
After upgrading UnityPy (from 1.18 to 1.20) in my project ArkUnpacker, I noticed that, when using multithreading to extract images, the application has an unpredictable chance to crash without any stacktrace (just like you shutdown the application in the Task Manager forcibly).
With the extensive debugging, I finally determined that it is the asynchronous access to the ASTC context that causes the problem.
This issue was caused by this commit d38b5f6 which introduced
astc_encoderfor texture decoding.How to fix it:
Simply adding a
threading.Lockto the dictASTC_CONTEXTS.2. Type Errors
There are two potential type errors. See my commit for detailed changes. Here comes the explanation:
texture_formatmay be an integer.