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

astc-encoder-py causes Blender crashes on specific systems #11

Closed
mos9527 opened this issue Oct 27, 2024 · 4 comments
Closed

astc-encoder-py causes Blender crashes on specific systems #11

mos9527 opened this issue Oct 27, 2024 · 4 comments

Comments

@mos9527
Copy link
Owner

mos9527 commented Oct 27, 2024

NOTE: This is an ongoing investigation that does not affect the overall operability of the plugin.

astc-encoder-py crashes on my own PC (running Windows 11/10.0.26100.0), tested with

  • Blender 4.2.2 LTS Release build (MSVC 2019)
  • Blender 4.3 Beta Release build (MSVC 2019)


Appendix: Minimal reproducible example (w/ astc-encoder-py 0.1.8 installed) in Blender Python Console:

from astc_encoder import (
    ASTCConfig,
    ASTCContext,
    ASTCImage,
    ASTCProfile,
    ASTCSwizzle,
    ASTCType,
)
config = ASTCConfig(ASTCProfile.LDR_SRGB, 4, 4)
context = ASTCContext(config)
img = bytes(b'\x00' * 4 * 512 * 512)
size = (512,512,1)
image = ASTCImage(ASTCType.U8,*size, data=img)
swizzle = ASTCSwizzle.from_str("RGBA")

# --> acquires a lock, crashes
comp = context.compress(image, swizzle)
image_dec = ASTCImage(ASTCType.U8, *size)

# --> acquires a lock, crashes
context.decompress(comp, image_dec, swizzle)

The initial fix is to migrate all ASTC decoding to the legacy texture2ddecoder, which does not involve synchronization primitives.

@mos9527
Copy link
Owner Author

mos9527 commented Oct 29, 2024

@mos9527
Copy link
Owner Author

mos9527 commented Oct 29, 2024

Update: The release version of Blender (4.2.2 LTS in this example) loads it's own msvcp140.dll redistribution
image
Which is built with Visual Studio 2019, as suggested by Die
image
Yet astc-encoder-py (or any Python extension built with MSVC and uses MS's STL for that matter, locally or with the latest toolset (Visual Studio 2022) would require the STL lib to be up to date; Otherwise (as in this case where ~2022 header is dynamically linked with a ~2019 lib) such combinations are considered forbidden,see:

In this case, locking std::mutex with a 2019 VC redist and a Python extension/DLL built with 2022 headers fails since the (newer) header implements std::mutex::mutex (properly) as constexpr, while the 2019 one initializes it statically, which explains the uninitialized mutex as stated by the preliminary debug report.

@mos9527
Copy link
Owner Author

mos9527 commented Oct 29, 2024

Update: With a updated astc-encoder-py build with _DISABLE_CONSTEXPR_MUTEX_CONSTRUCTOR flag (https://github.com/mos9527/astc-encoder-py/commit/5cce309d200f66f770a54856ad544308ef702a4e), this enabled the addon to work on stock relases builds of Blender.

@mos9527
Copy link
Owner Author

mos9527 commented Nov 5, 2024

Update: Upstream has implemented their solution in K0lb3/astc-encoder-py#2

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

No branches or pull requests

1 participant