Skip to content

Fix polymorphic deallocation#1340

Open
WeiPhil wants to merge 1 commit into
wjakob:masterfrom
WeiPhil:master
Open

Fix polymorphic deallocation#1340
WeiPhil wants to merge 1 commit into
wjakob:masterfrom
WeiPhil:master

Conversation

@WeiPhil
Copy link
Copy Markdown

@WeiPhil WeiPhil commented May 9, 2026

Hi,
Recently, I ran into an allocator mismatch crash during cleanup (specifically during Python garbage collection) when working with Mitsuba:

  1. A dynamic subclass like PrincipledBsdf is compiled with alignas(16) for SIMD operations.
  2. But its memory lifetime is handed over to Python as a raw, base Bsdf* pointer (so that Python takes over and deallocates it).

Since the current deallocator in nanobind does placement destructors + raw operator delete(void*) on base pointers, standard C++ dynamic delete routing seems to be bypassed during cleanup. On cleanup, this unfortunately crashes with a mismatched free in our internal build configuration where the default compiler alignment is 8.

I've worked on a fix that has been working for us internally as it reverts to standard type-safe deallocations when classes have virtual destructors.

To be honest, I'm not 100% sure this is the best fix for this niche problem, but it was the only way I could find to keep the allocators happy.

Let me know what you think or if you have a better alternative!
Best,
Philippe

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