GTK CSS color assertion failure: color->type == COLOR_TYPE_LITERAL

I have buttons which add and remove a css_class name when toggled. After some more advanced CSS modifications (e.g. box shadows, filters), when I toggle the button, thus removing Style 2, I get a color error that crashes the program:

Gtk:ERROR:../../../gtk/gtkcsscolorvalue.c:790:gtk_css_color_value_get_rgba: assertion failed: (color->type == COLOR_TYPE_LITERAL)
Bail out! Gtk:ERROR:../../../gtk/gtkcsscolorvalue.c:790:gtk_css_color_value_get_rgba: assertion failed: (color->type == COLOR_TYPE_LITERAL)

This function is in turn invoked by _gtk_css_color_value_resolve() in gtkcsscolorvalue.c. The application is on 2 displays, this error only happens on the 1st display.

This is the CSS attribute whose removal (which occurs when Style2 is removed) causes the error:
filter: drop-shadow(6px 6px 8px gray);

Hi! Could you share a minimal reproducer?

Yes, I spent some time preparing it so please take a look.

#include <gtk/gtk.h>

short lnum, rnum;

static void stop_toggle (GtkToggleButton *source, gpointer user_data) {
    if (gtk_toggle_button_get_active(source)) {
        gtk_button_set_has_frame(GTK_BUTTON(source), TRUE);
        gtk_widget_add_css_class(GTK_WIDGET(source), "stop_button_pressed");
    else {
        gtk_widget_remove_css_class(GTK_WIDGET(source), "stop_button_pressed"); 
        gtk_button_set_has_frame(GTK_BUTTON(source), FALSE);
static void make_toggles (GtkWidget * window, unsigned char type) {
    GtkWidget * stop_box;
    GtkWidget * box_row;
    GtkWidget * label; GtkWidget * stop;
    short i; short dnum;

    stop_box = gtk_box_new(GTK_ORIENTATION_VERTICAL, 20);
    gtk_widget_set_margin_bottom(stop_box, 0);
    if (type) {
        dnum = rnum;
    else {
        dnum = lnum;
    box_row = gtk_box_new(GTK_ORIENTATION_HORIZONTAL, 2);
    gtk_widget_set_margin_top(box_row, 10);
    gtk_box_append(GTK_BOX(stop_box), box_row);
    for (i = 0; i < dnum; i++) {
        char lb[6];
        snprintf((char *)&lb, 5, "%d", i);
        label = gtk_label_new((char *)&lb);
        gtk_label_set_wrap(GTK_LABEL(label), TRUE);
        gtk_label_set_justify(GTK_LABEL(label), GTK_JUSTIFY_CENTER);
        stop = gtk_toggle_button_new();
        char name[14]; name[0] = '\0';
        if (type) {
            snprintf(name, 14, "%d_rstops", i);
        else {
            snprintf(name, 14, "%d_lstops", i);
        gtk_widget_set_name(stop, name);
        gtk_widget_add_css_class(stop, "stop_button");
        gtk_widget_set_name(label, "stop_label");
        gtk_widget_set_margin_start(stop, 10* 7 + 5); 
        gtk_button_set_child(GTK_BUTTON(stop), label);
        g_signal_connect(stop, "toggled", G_CALLBACK(stop_toggle), NULL);
        gtk_box_append(GTK_BOX(box_row), stop);   
    gtk_widget_set_name(stop_box, "window_main");
    gtk_window_set_child (GTK_WINDOW (window), stop_box);
static void app_startup(GtkApplication* app) {
    rnum = 10;
    lnum = 10;
static void activate (GtkApplication* app, gpointer user_data) {
    GtkWidget *lwindow;
    GtkWidget *rwindow;

    lwindow = gtk_application_window_new(app);
    rwindow = gtk_application_window_new (app);
    gtk_window_set_title (GTK_WINDOW (lwindow), "Left Panel");
    gtk_window_set_title (GTK_WINDOW (rwindow), "Right Panel");
    GdkDisplay * display; GListModel* monitors;
    display = gdk_display_get_default();
    monitors = gdk_display_get_monitors(display);
    GdkMonitor * monitor = (GdkMonitor *) g_list_model_get_item(monitors, 0);
    GdkMonitor * monitor2 = (GdkMonitor *) g_list_model_get_item(monitors, 1);
    GtkCssProvider * cssProvider = gtk_css_provider_new();
    gtk_css_provider_load_from_path(cssProvider, "styling.css");
    gtk_style_context_add_provider_for_display(gtk_widget_get_display(lwindow), GTK_STYLE_PROVIDER(cssProvider),
    gtk_style_context_add_provider_for_display(gtk_widget_get_display(rwindow), GTK_STYLE_PROVIDER(cssProvider),
    make_toggles(lwindow, (unsigned char) 0);
    make_toggles(rwindow, (unsigned char) 1);
    gtk_window_fullscreen_on_monitor(GTK_WINDOW(lwindow), monitor2);
    gtk_window_fullscreen_on_monitor(GTK_WINDOW(rwindow), monitor);
    gtk_widget_show(lwindow); gtk_widget_show (rwindow);

int main(int argc, char **argv) {
    GtkApplication *app;
    int status;

    app = gtk_application_new("lcs.console", G_APPLICATION_DEFAULT_FLAGS);
    g_signal_connect(app, "startup", G_CALLBACK(app_startup), NULL);
    g_signal_connect (app, "activate", G_CALLBACK (activate), NULL);
    status = g_application_run (G_APPLICATION (app), argc, argv);
    g_object_unref (app);

    return status;

And the stylesheet:

#window_main {
    /*background-image: url("dark2.jpg");*/
    background-color: indigo;

.stop_button {
    /*background-image: url("marble.jpg");*/
    background-color: white;
    background-size: 100% 100%;
    background-position: center center;
    border-radius: 5%; /*use to make circular*/
    border: 20px;
    color: black;
    box-shadow: inset 5px 5px 10px darkgray;
    /*font-weight: bold;*/
    font-size: x-large;
    font-family: Garamond;
    min-width: 90px;
    padding: 10px;

.stop_button_pressed {
    /*background-image: url("marble_glow.jpg");*/
    background-color: yellow;
    background-size: 100% 100%;
    background-position: center center;
    border-radius: 5%;
    filter: drop-shadow(6px 6px 8px gray); 
   /* border: 15px;*/
    /*border-style: inset;*/
    box-shadow: inset 5px 5px 10px gray;
    border-color: black;
    color: black;
    /*font-weight: bold;*/
    font-family: Garamond;
    font-size: x-large;
    /*min-height: 150px;*/
    min-width: 90px;
    padding: 10px;
#section_label {
    font-size: x-large;
    color: white;

#stopbox {
   /* perspective: 200px; UNSUPPORTED PROPERTY*/
.flow_box {
    /*background: url(wood.jpg);*/
GtkToggleButton {
    color: red;
1 Like

Thanks, can confirm the issue!

I’m going to open an issue in GitLab and hopefully also an MR to fix it

1 Like

Here we are: Assertion failed: (color->type == COLOR_TYPE_LITERAL) (#5798) · Issues · GNOME / gtk · GitLab

1 Like

This topic was automatically closed 30 days after the last reply. New replies are no longer allowed.