Maniphest T54479

Pyplot crash when saving plot.
Closed, Resolved

Assigned To
Campbell Barton (campbellbarton)
Authored By
Roberto Casalegno (yobirob)
Mar 31 2018, 6:30 PM
Tags
  • BF Blender
Subscribers
Campbell Barton (campbellbarton)
Ray Molenkamp (LazyDodo)
Roberto Casalegno (yobirob)

Description

System Information
Dell Inspiron 7577 laptop
Win10Pro 64bit 16GBRAM -
video NVIDIA GeForce GTX 1050 Ti 4GB + Intel(R) HD Graphics 630 1GB

Blender Version
2.79 5bd8ac9

Short description of error
Using matplotlib.pyplot module, the savefig gives a hard crash in Blender. Problem seems the disabling of tkinter in embedded python.

Exact steps for others to reproduce the error
In attached .blend file, simply run the script (5 python lines).

Event Timeline

Roberto Casalegno (yobirob) created this task.Mar 31 2018, 6:30 PM
Ray Molenkamp (LazyDodo) assigned this task to Campbell Barton (campbellbarton).Mar 31 2018, 6:47 PM
Ray Molenkamp (LazyDodo) added subscribers: Campbell Barton (campbellbarton), Ray Molenkamp (LazyDodo).

we ship with tkinter disabled, however we have been doing this since before i took over as platform maintainer, @Campbell Barton (campbellbarton) you remember the history on this?

Roberto Casalegno (yobirob) added a comment.Apr 2 2018, 1:13 PM

we ship with tkinter disabled, however we have been doing this since before i took over as platform maintainer, @Campbell Barton (campbellbarton) you remember the history on this?

I have scripts from mid 2015 running in BGE using matpltlib tkinter backend, working fine. I haven't more recently tested this pyplot routines because I took tkinter for granted.
I can be more precise tomorrow when I'l be back at office.
Moreover, I would stress how use of python plotting routine as pyplot can be useful in scientific use of Blender/BGE (like I do).

Campbell Barton (campbellbarton) added a comment.EditedApr 4 2018, 8:33 AM

The reason not to use tkinter is as follows.

  • It's optional when installing Python (or was last time I installed Python on win32). So it's possible to have a Python installation without it (on Linux distributions too)
  • It takes up space in the Blender download ~4mb (See: https://wiki.blender.org/index.php/Dev:2.5/Source/Python/API/Py3.1_Migration).
  • Having add-ons use tk isn't likely to give a good user experience (popups that block blender UI). Better we focus on improving Blender's UI.

Would rather continue to keep this removed, Python developers can include any extra modules they need.


Not sure we should keep this report open. We can't be responsible for 3rd party modules crashing because of missing modules.

At least there should be some evidence this crash is caused by an error in Blender.

Roberto Casalegno (yobirob) added a comment.Apr 4 2018, 10:57 AM

Agree on reasons of leaving tkinter out (even if the "size" one is a little weak, with today networking/hdd).

But I only suggested tkinter as an indirect cause of the crash. In my crash.blend file there is no reference to tkinter, as I used Agg backend. It is anyway true that Blender crashes while using a 3rd part module, so close this issue would be licit: I would just underline we are talking of python and matplotlib, a widely used package, that could deserve a little more attention than others.

I think it would be very useful to simply find a workaround, without changing any policy in Blender Python options/packages. I will surely help doing this, if you don't decide to close this report (Python guy here, not C/++, that's why I need some help debugging).

Roberto Casalegno (yobirob) added a comment.Apr 9 2018, 1:57 PM

Ok, some more info:

On Linux (openSUSE 42.2 x86_64), work with output file like eps,svg,pdf. Gives error with png format (no crash anyway):

libpng warning: Application was compiled with png.h from libpng-1.6.21
libpng warning: Application  is  running with png.c from libpng-1.2.50
libpng error: Incompatible libpng version in application and library
Traceback (most recent call last):
  File "/Text", line 8, in <module>
  File "/home/yobilens/tempo/blender-2.79b-linux-glibc219-x86_64/2.79/python/lib/python3.5/site-packages/matplotlib/pyplot.py", line 710, in savefig
    res = fig.savefig(*args, **kwargs)
  File "/home/yobilens/tempo/blender-2.79b-linux-glibc219-x86_64/2.79/python/lib/python3.5/site-packages/matplotlib/figure.py", line 2035, in savefig
    self.canvas.print_figure(fname, **kwargs)
  File "/home/yobilens/tempo/blender-2.79b-linux-glibc219-x86_64/2.79/python/lib/python3.5/site-packages/matplotlib/backend_bases.py", line 2263, in print_figure
    **kwargs)
  File "/home/yobilens/tempo/blender-2.79b-linux-glibc219-x86_64/2.79/python/lib/python3.5/site-packages/matplotlib/backends/backend_agg.py", line 528, in print_png
    self.figure.dpi, metadata=metadata)
RuntimeError: Could not create write struct

On windows I have crash no matter what format I select, both blender or bge (maybe this is obvious), and no matter which graphic card (Intel or nvidia) I use.
Here is the ouput from Win Err Reg (sorry for the italian):

Nome dell'applicazione che ha generato l'errore: blender.exe, versione: 2.7.9.0, timestamp: 0x59b6936d
Nome del modulo che ha generato l'errore: ucrtbase.dll, versione: 10.0.16299.248, timestamp: 0xe71e5dfe
Codice eccezione: 0xc0000409
Offset errore 0x000000000006a508
ID processo che ha generato l'errore: 0x4e00
Ora di avvio dell'applicazione che ha generato l'errore: 0x01d3cff62bb9ba6b
Percorso dell'applicazione che ha generato l'errore: D:\YobiMinds\Software\blender-2.79-windows64\blender-2.79-windows64\blender.exe
Percorso del modulo che ha generato l'errore: C:\WINDOWS\System32\ucrtbase.dll
ID segnalazione: 1a9f9666-e2fa-484b-af9a-e71adbd75ccb
Ray Molenkamp (LazyDodo) added a comment.Apr 10 2018, 1:51 AM

can't speak for linux but, installing any binary python addon is gonna be troublesome on windows, due to blender copy being compiled with the msvc2013 compiler while the official one is build using msvc2015, if there's any crt object (file handle, pointer, etc etc) passed between the two run-times things will go south rather quickly, and besides suggesting you grab a vc14 build off the build bot, there's really nothing I can do about it.

Roberto Casalegno (yobirob) added a comment.Apr 10 2018, 4:45 PM
In T54479#492718, @Ray Molenkamp (LazyDodo) wrote:

[...] suggesting you grab a vc14 build off the build bot, there's really nothing I can do about it.[...]

Works. It writes every format, even png. I didn't tested it in linux yet, but this is solving the issue in Windows.

Roberto Casalegno (yobirob) changed the task status from Unknown Status to Resolved.Apr 11 2018, 5:22 PM