libvips / php-vips

php binding for libvips
MIT License
615 stars 25 forks source link

GLib-GObject-CRITICAL: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed #139

Closed WalterWoshid closed 2 years ago

WalterWoshid commented 2 years ago

PHP Version: 8.1.3 PHP ini: ffi.enable=true Also true for php -i Framework: Laravel 9.4.1 Environment: WSL 2 Docker Docker OS: Ubuntu-20.04 libvips-dev: 8.10.5-2ubuntu1 jcupitt/vips: v2.0.0

I'm receiving this error in my console, while trying to run the below code.

(.:21): GLib-GObject-CRITICAL **: 22:13:34.813: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed

$image = \Jcupitt\Vips\Image::newFromFile(resource_path('HQ-Heidi.png'));
$width = $image->width;
$height = $image->height;

It is repeating very fast and also I have to stop PHP, because the request runs for too long.

Edit: The beginning of the logs

(.:22): GLib-GObject-WARNING **: 22:20:57.385: cannot register existing type 'VipsObject'

(.:22): GLib-CRITICAL **: 22:20:57.385: g_once_init_leave: assertion 'result != 0' failed

(.:22): GLib-GObject-CRITICAL **: 22:20:57.385: g_type_register_static: assertion 'parent_type > 0' failed

(.:22): GLib-CRITICAL **: 22:20:57.385: g_once_init_leave: assertion 'result != 0' failed

EDIT: FIXED

I fixed it by installing the pecl extension for vips

sudo pecl install vips
# Add vips.so to your php.ini
sudo echo 'extension="vips.so"' > /etc/php/8.1/cli/conf.d/20-vips.ini

I will let this issue stay open, either this should be documented or there should be a fix?

jcupitt commented 2 years ago

Hi @WalterWoshid,

I've not tried php-vips2 in WSL yet, I'll have a quick go. It might be a lavarel issue (perhaps it's not starting up the extension correctly?). The PECL extension should not be necessary, though perhaps that's ensuring that init happens in this case.

Did you try the example programs? Eg.:

https://github.com/libvips/php-vips/blob/master/examples/watermark-text.php

I see:

$ ./watermark-text.php ~/pics/PNG_transparency_demonstration.png x.png "hello world!"

To make:

x

jcupitt commented 2 years ago

Ah it seems I can't install WSL2, that's a shame. I run win10 under virtualbox, and it doesn't support nested VMs.

So (just guessing) I think perhaps what's happening is that Lavarel is not pulling in php-vips early enough. Is there some way to change the config to make the vendor autoload happen sooner? That might fix it.

lucasnetau commented 2 years ago

I've trigger the same assertion with a different environment:

GLib-GObject-CRITICAL **: 01:54:46.648: g_boxed_type_register_static: assertion 'g_type_from_name (name) == 0' failed

Leading to a SIGSEV child 6 exited on signal 11 (SIGSEGV) after 669.163951 seconds from start

PHP Version: 8.0.17 PHP ini: ffi.enable=true Framework: SlimPHP Environment: Docker (Debian 11) Docker OS: Amazon Linux release 2 (Karoo) libvips-dev: 8.10.5-2 jcupitt/vips: v2.0.1

It does not always occur, only on some requests, identical requests complete fine.

lucasnetau commented 2 years ago

Triggered it a second time, this time with another GLib error

(.:1965): GLib-GObject-WARNING : 02:11:06.006: cannot register existing type 'VipsObject' (.:1965): GLib-CRITICAL : 02:11:06.006: g_once_init_leave: assertion 'result != 0' failed (.:1965): GLib-GObject-CRITICAL : 02:11:06.006: g_type_register_static: assertion 'parent_type > 0' failed (.:1965): GLib-CRITICAL : 02:11:06.006: g_once_init_leave: assertion 'result != 0' failed

The two constructors I am use plus methods are:

Vips\Image::newFromBuffer -> height -> width

Vips\Image::thumbnail_buffer -> height -> width -> writeToBuffer

kleisauke commented 2 years ago

See: https://github.com/libvips/php-vips/issues/142#issuecomment-1188960441.

kleisauke commented 2 years ago

libvips 8.13 ought to fix this. @WalterWoshid Would you be able to test again?