I’m trying to append text to a GtkTextView whenever I press a button (just for testing atm), but in one of the callbacks, I keep getting the following message:
(caliprint:19537): GLib-GObject-CRITICAL **: 22:04:19.253: g_param_value_validate: assertion 'G_IS_PARAM_SPEC (pspec)' failed
And here’s the function that generates the message:
//Connect Button
gboolean on_control_connect_pressed_callback( GtkWidget *object, gpointer user_data )
{
gui_context * context = (gui_context *)user_data;
//Disconnect
if( context->serial != NULL && serial_is_connected( context->serial ) )
{
log_printf(
context->control_log,
"Disconnecting from %s...\n",
serial_get_port( context->serial )
);
serial_free_driver( context->serial );
context->serial = NULL;
gtk_button_set_label(
context->control_connect,
"connect"
);
return true;
}
//Connect
if( context->serial != NULL )
{
serial_free_driver( context->serial );
context->serial = NULL;
}
//context->serial = serial_create_driver( "/dev/ttyUSB0", SP115200, false );
if( serial_get_status( context->serial ) != SERIAL_OK )
{
log_printf(
context->control_log,
"Cannot connect to serial port %s\n",
serial_get_port( context->serial )
);
gtk_button_set_label(
context->control_connect,
"Connect"
);
return true;
}
else
{
log_printf(
context->control_log,
"Connected to %s\n",
serial_get_port( context->serial )
);
gtk_button_set_label(
context->control_connect,
"Disconnect"
);
}
return true;
}
And of course, here’s the funtion(s) in charge of appending the text:
static void log_append_to_textview( GtkTextView * tv, char * msg );
void log_printf( GtkTextView * tv, const char * format, ... )
{
va_list arg;
va_start( arg, format );
//1000 for buffer size (+1 for the \0) and +12 for the time
static char buffer[1013] = {0};
buffer[0] = 0;
char * tgt = get_time( buffer );
vsnprintf( tgt, 1000, format, arg );
log_append_to_textview( tv, buffer );
}
void log_append_to_textview( GtkTextView * tv, char * msg )
{
GtkTextBuffer * buff =
gtk_text_view_get_buffer(tv);
GtkTextMark *mark =
gtk_text_buffer_get_insert( buff );
GtkTextIter end;
gtk_text_buffer_get_end_iter(
buff,
&end
);
gtk_text_buffer_move_mark( buff, mark, &end );
gtk_text_buffer_insert_at_cursor(
buff,
msg,
-1
);
gtk_text_view_scroll_to_mark(
tv,
mark,
0.0,
TRUE,
0.5,
1
);
}
The funny thing is, all of the other callbacks seem to work just fine. I do believe the warning is caused by this segment:
if( serial_get_status( context->serial ) != SERIAL_OK )
{
log_printf(
context->control_log,
"Cannot connect to serial port %s\n",
serial_get_port( context->serial )
);
gtk_button_set_label(
context->control_connect,
"Connect"
);
As it doesn’t occur when the other conditions are met. I check and it doesn’t seem to be a problem with the pointers for the widgets. I imagine the warning is not critical as it does not seem to make the application crash, but of course I don’t want to just ignore it for now and worry about it later. I appreciate any feedback you guys might provide, and sorry if I’m not providing enough info, I’m still a little new to Gtk.
I also didn’t wanted to post the whole code behind serial
since I feel like this was getting a little bit too long already, but you can also check the code on Github