gegl_init() is a trap for the unwary in Python plug-ins non-interactive
I have been updating some Python scripts from GIMP V2.10 to V2.99 and have used the Python scripts supplied in the V2.99.7 GIMP sources as examples. This applies to the Python scripts included in GIMP sources downloaded 15.9.2021 - commit 148fbb22 and earlier versions.
Two of the scripts would work successfully when run interactively but failed with a segmentation fault in both of the non-interactive modes when the script called get_buffer() for a drawable (line 135). I found that the problem didn't occur if the script called GimpUi.init(). I then narrowed this down to needing a call of babl.init().
To save others having to investigate the same problem I suggest that the Python scripts (fogify.py and goat-exercise-py3.py for example) that ship with GIMP should be modified (I will do this and submit a merge request if requested).
The easiest modification would be to move the call of GimpUi.init() into the common path of the code that handles interactive and non-interactive modes.
The other approach would be to import babl (as per line 38 of the attached script) and then call Babl.init() (as per lines 200 and 201) if running in one of the non-interactive modes.
If the attached script is run interactively and then via "Filters/Repeat Last" it should work without a problem. If this is repeated with lines 200 and 201 commented out it will fail when run non-interactively.