Skip to content

Fix: onnxruntime DLL crash and version incompatibility on Blender 4.x / 5.x (Windows)#56

Open
Snowii3D wants to merge 1 commit intoHugoTini:masterfrom
Snowii3D:fix/onnxruntime-blender4-5
Open

Fix: onnxruntime DLL crash and version incompatibility on Blender 4.x / 5.x (Windows)#56
Snowii3D wants to merge 1 commit intoHugoTini:masterfrom
Snowii3D:fix/onnxruntime-blender4-5

Conversation

@Snowii3D
Copy link
Copy Markdown

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

…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
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

Successfully merging this pull request may close these issues.

1 participant