Pekov
Pekov

Reputation: 537

Segmentation fault on call to `gdk_rgba_to_string()`

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?

Upvotes: 2

Views: 149

Answers (1)

Sergey Kalinichenko
Sergey Kalinichenko

Reputation: 727047

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);

Upvotes: 3

Related Questions