gtkd-developers / GtkD

GtkD is a D binding and OO wrapper of GTK+ originally created by Antonio Monteiro
http://gtkd.org
Other
322 stars 71 forks source link

GLib-CRITICAL and GLib-GObject-CRITICAL errors when unit testing. #124

Closed SingingBush closed 9 years ago

SingingBush commented 9 years ago

I am working on an app that depends on gtk-d 3.1.4 and uses dunit for testing. When running dub test on travis-ci.org I'm getting the following errors in the logs:

> Running unit tests

(process:1915): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.32.4/./gobject/gtype.c:2722: You forgot to call g_type_init()

(process:1915): GLib-GObject-CRITICAL **: /build/buildd/glib2.0-2.32.4/./gobject/gtype.c:2722: You forgot to call g_type_init()

(process:1915): GLib-GObject-CRITICAL **: g_type_interface_add_prerequisite: assertion `G_TYPE_IS_INTERFACE (interface_type)' failed

(process:1915): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed

(process:1915): GLib-GObject-CRITICAL **: g_type_add_interface_static: assertion `G_TYPE_IS_INSTANTIATABLE (instance_type)' failed

(process:1915): GLib-CRITICAL **: g_once_init_leave: assertion `result != 0' failed

(process:1915): GLib-GObject-CRITICAL **: g_object_new: assertion `G_TYPE_IS_OBJECT (object_type)' failed

./__test__library__(_D4core7runtime18runModuleUnitTestsUZ19unittestSegvHandlerUNbiPS4core3sys5posix6signal9siginfo_tPvZv+0x38)[0x951504]

Error executing command test:

Program exited with code -11

The command "dub test --compiler=dmd" exited with 2.
MikeWey commented 9 years ago

Do you have some code i could try? I'm currently not running into any problems running unittests.

SingingBush commented 9 years ago

The code that I'm working on is dfract. When I run dub test on my machine (Fedora 22) it runs fine, it's just on travis (Ubuntu 12.04 LTS) that I get the problem.

MikeWey commented 9 years ago

The problem is that the D runtime runs the unittests before calling main, while the GTK/GObject runtime is initialized there. This means that when running unittests on code using GtkD you are calling GTK/GObject functions without initializing there runtime. Now with newer versions of GObject >= 2.36 the type system is initialized automatically, and the error above isn't triggered, although other errors might occur when testing different parts of GtkD/GTK.

For this error you could try calling gobject.Type.Type.init() at the start of the unittest.

SingingBush commented 9 years ago

thanks for the info. after some communication with the guys at travis-ci I've got my build working again. They've finally got Ubuntu 14.04 build agents (as well as mac osx) so the available dependencies are a lot more up to date.

in case you're interested, the following travis.yml is what I am now using:

language: d

sudo: required

services:
 - docker

before_install:
 - "if [ ${TRAVIS_OS_NAME} = 'linux' ]; then sudo apt-get update -qq; fi"
 - "if [ ${TRAVIS_OS_NAME} = 'linux' ]; then sudo apt-get install -y libcairo2-dev libgdk-pixbuf2.0-dev libgtk-3-0; fi"
 - "if [ ${TRAVIS_OS_NAME} = 'osx' ]; then brew update; fi"
 - "if [ ${TRAVIS_OS_NAME} = 'osx' ]; then brew install glib cairo pango gtk+3; fi"

d:
 - dmd
# - gdc
 - ldc

os:
 - linux
 - osx

matrix:
  allow_failures:
    - os: osx