Segmentation fault on call to `gdk_rgba_to_string()`

Viewed 119

I tried to convert GdkRGBA to a gchar * with the function gdk_rgba_to_string(). For instance:

GdkRGBA *color_01;
gchar *color_string = gdk_rgba_to_string(color_01);

In my code, this one gives segmentation fault, why is that?

1 Answers

This code crashes because you need to allocate memory to a pointer, or to allocate the structure in automatic or static memory, for example

GdkRGBA color = {0};
gchar *color_as_string = gdk_rgba_to_string(&color);
Related