Fix: onnxruntime DLL crash and version incompatibility on Blender 4.x / 5.x (Windows)#56
Open
Snowii3D wants to merge 1 commit intoHugoTini:masterfrom
Open
Fix: onnxruntime DLL crash and version incompatibility on Blender 4.x / 5.x (Windows)#56Snowii3D wants to merge 1 commit intoHugoTini:masterfrom
Snowii3D wants to merge 1 commit intoHugoTini:masterfrom
Conversation
…ompatibility for Blender 4.x/5.x on Windows ## Problem The addon was broken on Blender 4.x+ for two reasons: 1. `onnxruntime==1.15.1` had no Python 3.11/3.12 wheel, causing a `ModuleNotFoundError` on import. 2. Upgrading directly to the latest onnxruntime (1.19+) caused a `DLL initialization routine failed` crash on Windows because those versions require the VS2022 C++ runtime, which is not bundled with Blender 4.x. ## Fix **`__init__.py`** - onnxruntime version is now selected dynamically based on the running Python version: - Python 3.11 / 3.12 (Blender 4.x) → `onnxruntime==1.18.1` (last version using the VS2019 runtime, compatible with Blender's bundled environment) - Python 3.13+ (Blender 5.x) → `onnxruntime==1.21.0` (minimum version with a Python 3.13 wheel) - Dependencies path is inserted at the **front** of `sys.path` so Blender's own paths can't shadow the installed package. - On Windows, both `os.add_dll_directory()` and `PATH` are updated to cover all Blender builds. - All stale `sys.modules` entries for the package and its submodules (e.g. `onnxruntime.capi`, `onnxruntime.capi._pybind_state`) are cleared before each import attempt, preventing a failed startup import from blocking later install-time imports. - `bl_info` minimum Blender version corrected back to `(4, 3, 2)`. ## Tested on - Blender 4.5 LTS, Windows 11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
The addon was broken on Blender 4.x+ for two reasons:
onnxruntime==1.15.1had no Python 3.11/3.12 wheel, causing aModuleNotFoundErroron import.DLL initialization routine failedcrash on Windows because those versions require the VS2022 C++ runtime, which is not bundled with Blender 4.x.Fix
__init__.pyonnxruntime==1.18.1(last version using the VS2019 runtime, compatible with Blender's bundled environment)onnxruntime==1.21.0(minimum version with a Python 3.13 wheel)sys.pathso Blender's own paths can't shadow the installed package.os.add_dll_directory()andPATHare updated to cover all Blender builds.sys.modulesentries for the package and its submodules (e.g.onnxruntime.capi,onnxruntime.capi._pybind_state) are cleared before each import attempt, preventing a failed startup import from blocking later install-time imports.bl_infominimum Blender version corrected back to(4, 3, 2).Tested on