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

Segmentation Fault When Importing matplotlib.pyplot After mitsuba #1482

Open
JY251 opened this issue Feb 2, 2025 · 1 comment
Open

Segmentation Fault When Importing matplotlib.pyplot After mitsuba #1482

JY251 opened this issue Feb 2, 2025 · 1 comment

Comments

@JY251
Copy link

JY251 commented Feb 2, 2025

Description:

I encountered a segmentation fault when importing matplotlib.pyplot after importing mitsuba. The issue occurs at the line where matplotlib.pyplot is imported.

Steps to Reproduce:

  1. Install mitsuba and matplotlib in the same Python environment.
  2. Run the following script:
    print("OK1")
    import mitsuba as mi
    print("OK2")
    import matplotlib.pyplot as plt  # Segmentation Fault Here
    print("OK3")

Expected Behavior:

The script should run without any segmentation faults, and all print statements (OK1, OK2, OK3) should be displayed.

Actual Behavior:

A segmentation fault occurs at the line where matplotlib.pyplot is imported.

Environment:

  • Python version: [3.10.12]
  • Operating System: [Ubuntu 22.04.3 LTS]
  • mitsuba version: [3.6.2]
  • matplotlib version: [3.10.0]

Solution:

Reordering the imports resolved the issue. Specifically, importing matplotlib.pyplot before mitsuba prevents the segmentation fault:

import matplotlib.pyplot as plt  # Import matplotlib first
print("OK1")
import mitsuba as mi
print("OK2")
@merlinND
Copy link
Member

merlinND commented Feb 2, 2025

Hello @JY251,

I suspect this has something to do with the libstdc++ / libc++ incompatibility in exception handling.
Did you build Mitsuba yourself using Clang? If so, when importing Mitsuba first, the libc++ exception handlers are used. But Matplotlib throws libstdc++ format exceptions, which causes a segfault when handled.

The workaround I can think of:

  • Build Mitsuba with GCC (which uses libstdc++)
  • Downgrade Matplotlib to an earlier version which doesn't throw such an exception
  • Remove the source of the exception (only possible if the exception is not meant to be thrown; it might actually be part of the normal functioning of Matplotlib).

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

2 participants