C LIBCHAMPLAIN SegFault?

C LIBCHAMPLAIN SegFault?,c,segmentation-fault,maps,C,Segmentation Fault,Maps,我用C和libchamplain编写了一个程序,显示了一张地图。很好。现在我想将它集成到gtk应用程序中。但在跑步时,我会犯一个错误: #include <stdio.h> #include <gtk/gtk.h> #include <champlain/champlain.h> #include <champlain-gtk/champlain-gtk.h> #include <clutter-gtk/clutter-gtk.h> #

我用C和libchamplain编写了一个程序,显示了一张地图。很好。现在我想将它集成到gtk应用程序中。但在跑步时,我会犯一个错误:

#include <stdio.h>
#include <gtk/gtk.h>
#include <champlain/champlain.h>
#include <champlain-gtk/champlain-gtk.h>
#include <clutter-gtk/clutter-gtk.h>
#include <math.h>

#include "GPS_stub.h"

#define MARKER_SIZE 10
#define MAX_SIZ 4096

static gboolean draw_center(ClutterCanvas *canvas, cairo_t *cr, int width, int height){
  cairo_set_operator(cr, CAIRO_OPERATOR_CLEAR);
  cairo_paint(cr);
  cairo_set_operator(cr, CAIRO_OPERATOR_OVER);

  cairo_set_source_rgb(cr, 0, 0, 0);
  cairo_arc(cr, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, MARKER_SIZE / 2.0, 0, 2 * M_PI);
  cairo_close_path(cr);
  cairo_set_source_rgba(cr, 0.1, 0.1, 0.9, 1.0);
  cairo_fill(cr);

  return TRUE;
}

static ClutterActor *create_marker(void){
  ClutterActor *marker;
  ClutterActor *bg;
  ClutterContent *canvas;
  ClutterTransition *transition;

  marker = champlain_custom_marker_new();

  canvas = clutter_canvas_new();
  clutter_canvas_set_size(CLUTTER_CANVAS(canvas), MARKER_SIZE, MARKER_SIZE);
  g_signal_connect(canvas, "draw", G_CALLBACK(draw_center), NULL);

  bg = clutter_actor_new();
  clutter_actor_set_size(bg, MARKER_SIZE, MARKER_SIZE);
  clutter_actor_set_content(bg, canvas);
  clutter_content_invalidate(canvas);
  g_object_unref(canvas);

  clutter_actor_add_child(marker, bg);
  clutter_actor_set_pivot_point(bg, 0.5, 0.5);
  clutter_actor_set_position(bg, -MARKER_SIZE, -MARKER_SIZE);

  transition = clutter_property_transition_new("opacity");
  clutter_actor_set_easing_mode(bg, CLUTTER_EASE_OUT_SINE);
  clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), 1000);
  clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), -1);
  clutter_transition_set_from(transition, G_TYPE_UINT, 255);
  clutter_transition_set_to(transition, G_TYPE_UINT, 0);
  clutter_actor_add_transition(bg, "animate-opacity", transition);

  transition = clutter_property_transition_new("scale-x");
  clutter_actor_set_easing_mode(bg, CLUTTER_EASE_OUT_SINE);
  clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), 1000);
  clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), -1);
  clutter_transition_set_from(transition, G_TYPE_FLOAT, 0.5);
  clutter_transition_set_to(transition, G_TYPE_FLOAT, 1.0);
  clutter_actor_add_transition(bg, "animate-scale-x", transition);

  transition = clutter_property_transition_new("scale-y");
  clutter_actor_set_easing_mode(bg, CLUTTER_EASE_OUT_SINE);
  clutter_timeline_set_duration(CLUTTER_TIMELINE(transition), 1000);
  clutter_timeline_set_repeat_count(CLUTTER_TIMELINE(transition), -1);
  clutter_transition_set_from(transition, G_TYPE_FLOAT, 0.5);
  clutter_transition_set_to(transition, G_TYPE_FLOAT, 1.0);
  clutter_actor_add_transition(bg, "animate-scale-y", transition);

  return marker;
}

static gboolean gps_callback(ChamplainMarker *marker[MAX_SIZ]){
  return TRUE;
}

typedef struct{
  double lat;
  double lng;
} GpsCallbackData;

static void load_map(GpsCallbackData *data){
  ClutterActor *actor, *stage;
  ChamplainMarkerLayer *layer;
  ClutterActor *marker[MAX_SIZ];

  stage = clutter_stage_new();
  clutter_actor_set_size(stage, 800, 600);
  g_signal_connect(stage, "destroy", G_CALLBACK(clutter_main_quit), NULL);

  actor = champlain_view_new();
  clutter_actor_set_size(CLUTTER_ACTOR(actor), 800, 600);
  clutter_actor_add_child(stage, actor);

  layer = champlain_marker_layer_new_full(CHAMPLAIN_SELECTION_SINGLE);
  clutter_actor_show(CLUTTER_ACTOR(layer));
  champlain_view_add_layer(CHAMPLAIN_VIEW(actor), CHAMPLAIN_LAYER(layer));

  for(int i = 0; i < MAX_SIZ/40; i++){
    marker[i] = create_marker();
    champlain_marker_layer_add_marker(layer, CHAMPLAIN_MARKER(marker[i]));
    champlain_location_set_location(CHAMPLAIN_LOCATION(marker[i]), data->lat+i/10, data->lng+i/10);
  }

  g_object_set(G_OBJECT(actor), "zoom-level", 2, "kinetic-mode", TRUE, NULL);
  champlain_view_center_on(CHAMPLAIN_VIEW(actor), 40, 0);

  g_timeout_add(1000, (GSourceFunc) gps_callback, CHAMPLAIN_MARKER(marker));

  clutter_actor_show(stage);
  clutter_main();
}

int main(int argc, char *argv[]){
  GtkWidget *window, *button;

  GpsCallbackData *gps;

  double lat, lng;

  gtk_clutter_init(&argc, &argv);
  hs_init(&argc, &argv);

  getGPS("166.82.21.200", &lat, &lng);
  printf("GPS: %f %f\n", lat, lng);

  gps->lat = lat;
  gps->lng = lng;

  window = gtk_window_new(GTK_WINDOW_TOPLEVEL);
  g_signal_connect(window, "destroy", G_CALLBACK(gtk_main_quit), NULL);
  gtk_container_set_border_width(GTK_CONTAINER(window), 10);

  button = gtk_button_new_with_label("Load Map");
  g_signal_connect(button, "clicked", G_CALLBACK(load_map), &gps);

  gtk_container_add(GTK_CONTAINER(window), button);
  gtk_widget_show(window);
  gtk_main();

  hs_exit();

  return 0;
}
#包括
#包括
#包括
#包括
#包括
#包括
#包括“GPS_stub.h”
#定义尺寸为10的标记
#定义最大尺寸4096
静态gboolean绘图中心(凌乱的画布*画布、cairo\u t*cr、整型宽度、整型高度){
cairo_设置_运算符(cr、cairo_运算符_清除);
开罗漆(cr);
cairo_集_算子(cr,cairo_算子_OVER);
cairo\u set\u source\u rgb(cr,0,0,0);
cairo_弧(cr、MARKER_大小/2.0、MARKER_大小/2.0、MARKER_大小/2.0、0、2*M_PI);
开罗路(cr);
cairo_set_source_rgba(cr,0.1,0.1,0.9,1.0);
开罗填料(cr);
返回TRUE;
}
静态ClutterActor*创建标记(无效){
杂波器*标记;
杂波演员*bg;
杂乱的内容*画布;
杂乱过渡*过渡;
marker=champlain_custom_marker_new();
canvas=croot_canvas_new();
杂乱画布设置大小(杂乱画布(画布)、标记大小、标记大小);
g_信号连接(画布,“绘制”,g_回调(绘制中心),空);
bg=杂波_actor_new();
杂波大小(背景、标记大小、标记大小);
杂乱无章的演员集内容(背景、画布);
杂乱内容无效(画布);
g_object_unref(画布);
杂波、演员、添加、子(标记、背景);
杂波、演员、集合、支点(背景、0.5、0.5);
杂波位置(背景,-标记大小,-标记大小);
过渡=杂波特性过渡新(“不透明度”);
杂波演员设置缓解模式(背景,杂波缓解正弦);
混乱时间线设置持续时间(混乱时间线(过渡),1000);
杂波时间线设置重复计数(杂波时间线(转换),-1);
杂波转换设置源(转换,G类型单元,255);
杂波转换设置为(转换,G类型单元,0);
杂波演员添加过渡(背景,“动画不透明度”,过渡);
过渡=杂波特性过渡新(“缩放x”);
杂波演员设置缓解模式(背景,杂波缓解正弦);
混乱时间线设置持续时间(混乱时间线(过渡),1000);
杂波时间线设置重复计数(杂波时间线(转换),-1);
杂波(transition)(transition,G)类型(FLOAT),0.5);;
杂波_转换_设置_至(转换,G_类型_浮动,1.0);
混乱、演员、添加、过渡(背景,“动画缩放x”,过渡);
过渡=杂波特性过渡新(“缩放y”);
杂波演员设置缓解模式(背景,杂波缓解正弦);
混乱时间线设置持续时间(混乱时间线(过渡),1000);
杂波时间线设置重复计数(杂波时间线(转换),-1);
杂波(transition)(transition,G)类型(FLOAT),0.5);;
杂波_转换_设置_至(转换,G_类型_浮动,1.0);
混乱、演员、添加、过渡(背景,“动画缩放y”,过渡);
返回标记;
}
静态gboolean gps_回调(ChamplainMarker*标记器[MAX_SIZ]){
返回TRUE;
}
类型定义结构{
双lat;
双液化天然气;
}GpsCallbackData;
静态无效荷载图(GpsCallbackData*数据){
杂耍演员*演员,*舞台;
ChamplainMarkerLayer*层;
杂波器*标记器[最大尺寸];
stage=杂波_stage_new();
杂乱的演员集大小(舞台,800600);
g_信号连接(阶段,“销毁”,g_回调(杂波主信号退出),空);
actor=champlain_view_new();
杂波演员集大小(杂波演员,800600);
混乱、演员、添加、孩子(舞台、演员);
图层=champlain\u标记器\u图层\u新建\u完整(champlain\u选择\u单一);
杂波演员表演(杂波演员(层));
champlain_视图添加层(champlain_视图(演员)、champlain_层(层));
对于(int i=0;i纬度+i/10,数据->液化天然气+i/10);
}
g_对象集(g_对象(演员),“缩放级别”,2,“运动模式”,真,空);
尚普兰观点中心(尚普兰观点(演员),40,0);
g_timeout_add(1000,(GSourceFunc)gps_回调,CHAMPLAIN_标记(标记));
杂耍演员表演(舞台);
杂波_main();
}
int main(int argc,char*argv[]){
GtkWidget*窗口,*按钮;
GpsCallbackData*gps;
双lat,液化天然气;
gtk_杂波_初始(&argc,&argv);
hs_init(&argc,&argv);
getGPS(“166.82.21.200”、&lat和lng);
printf(“全球定位系统:%f%f\n”,纬度,液化天然气);
gps->lat=lat;
gps->lng=lng;
窗口=gtk_窗口_新建(gtk_窗口_顶层);
g_信号连接(窗口,“销毁”,g_回调(gtk_主退出),空);
gtk_容器_设置_边框_宽度(gtk_容器(窗口),10);
按钮=gtk_按钮_新建_,带有标签(“负载图”);
g_信号连接(按钮“点击”、g_回调(加载地图)和gps);
gtk_容器添加(gtk_容器(窗口),按钮);
gtk_widget_show(窗口);
gtk_main();
hs_退出();
返回0;
}
正如您在
main
中看到的,它打印出坐标。这个很好用。但在印刷之后,我又犯了一个错误


为什么?

我在ARM Linux上遇到了同样的问题

 stage = clutter_stage_new();
 clutter_actor_set_size(stage, 800, 600);
当我删除或阻止“杂波演员集”时,没有seg故障错误

演员没问题,但舞台就是问题。
但是在X86 Ubuntu桌面上,它没问题。

调试器说什么?我从来没有使用过调试器。我不知道怎么做;(