mitsuba-renderer / mitsuba3

Mitsuba 3: A Retargetable Forward and Inverse Renderer
https://www.mitsuba-renderer.org/
Other
2.1k stars 246 forks source link

Python ScopedThreadEnvironment not working #1263

Closed dvicini closed 3 months ago

dvicini commented 3 months ago

The ScopedThreadEnvironment seems broken in Python currently. Reproducer:

import mitsuba as mi
mi.set_variant("llvm_ad_rgb")

env = mi.ThreadEnvironment()
with mi.ScopedSetThreadEnvironment(env):
  mi.Log(mi.LogLevel.Warn, "Log from a thread env")

This prints:

2024-08-12 14:58:04 WARN  main  [Thread] Destructor called while thread 'main' was still running
2024-08-12 14:58:04 WARN  py0   [thread_env2.py:6] <module>: Log from a thread env
Traceback (most recent call last):
  File ".../mitsuba3/build/thread_env2.py", line 5, in <module>
    with mi.ScopedSetThreadEnvironment(env):
TypeError: __exit__(): incompatible function arguments. The following argument types are supported:
    1. __exit__(self, arg0: object, arg1: object, arg2: object, /) -> None

Invoked with types: mitsuba.ScopedSetThreadEnvironment, NoneType, NoneType, NoneType

Likely just an issue in the bindings, but not immediately obvious to me what causes this. Aside of that, it seems that there are currently no tests exercising the ScopedThreadEnvironment in Python.

dvicini commented 3 months ago

Found the issue: Nanobind requires explicit "_a.none()" annotation to pass None values. Will submit a PR shortly

dvicini commented 3 months ago

Addressed in PR #1264