Skip to content

Commit

Permalink
segfault debug
Browse files Browse the repository at this point in the history
  • Loading branch information
accellarando committed Dec 2, 2023
1 parent 289c356 commit 18ace5b
Show file tree
Hide file tree
Showing 6 changed files with 64 additions and 23 deletions.
Binary file modified software/TagGang
Binary file not shown.
53 changes: 46 additions & 7 deletions software/drawable_canvas.c
Original file line number Diff line number Diff line change
Expand Up @@ -65,11 +65,17 @@ static void advance_stage(){
clear_surface();

// Prepare for moving to next stage
if (surface)
if (surface){
cairo_surface_destroy (surface);
surface = NULL;
}
/* gtk_widget_destroy(widget); */
gtk_widget_destroy(frame);
gtk_widget_destroy(drawing_area);
if(frame)
gtk_widget_destroy(frame);
if(drawing_area){
gtk_widget_destroy(drawing_area);
drawing_area = NULL;
}


// Change window title to next stage.
Expand All @@ -86,10 +92,17 @@ int last_hand_x = -1;
int last_hand_y = -1;
int time_last_updated = 0;
int max_pix_per_sec = 75;
#define NUM_SAMPLES 8
int x_samples[NUM_SAMPLES];
int y_samples[NUM_SAMPLES];
int sample_i = 0;
int sample_ready = 0;
static gboolean draw_cb (GtkWidget *widget,
cairo_t *cr,
gpointer data)
{
if(surface == NULL || drawing_area == NULL)
return;
cairo_set_source_surface (cr, surface, 0, 0);
cairo_paint (cr);

Expand Down Expand Up @@ -126,6 +139,7 @@ static gboolean draw_cb (GtkWidget *widget,
// Do some noise filtering first:
int now_x = WINDOW_WIDTH - right_hand->screen_x;
int now_y = right_hand->screen_y;
/* THRESHOLD STRATEGY
int dx = last_hand_x == -1 ? 0 : now_x - last_hand_x;
int dy = last_hand_y == -1 ? 0 : now_y - last_hand_y;
int dt = time(NULL) - time_last_updated;
Expand All @@ -138,20 +152,45 @@ static gboolean draw_cb (GtkWidget *widget,
//ignore this point
return;
}
*/
/* AVERAGE STRATEGY */
x_samples[sample_i] = now_x;
y_samples[sample_i++] = now_y;
int avg_x = 0;
int avg_y = 0;
if(sample_i >= NUM_SAMPLES){
for(int i=0; i<sample_i; i++){
avg_x += x_samples[i];
avg_y += y_samples[i];
}
avg_x /= NUM_SAMPLES;
avg_y /= NUM_SAMPLES;
sample_i = 0;
sample_ready = 1;
}


/*
last_hand_x = now_x;
last_hand_y = now_y;
time_last_updated = time(NULL);
*/

cairo_set_source_rgb(cr, 1, 0, 0);
cairo_arc(cr, now_x, now_y, 10, 0, 2 * G_PI);
cairo_arc(cr, last_hand_x, last_hand_y, 10, 0, 2 * G_PI);
cairo_fill(cr);

if(pen_down){
draw_brush(widget, now_x, now_y);
if(sample_ready){
if(pen_down){
draw_brush(widget, avg_x, avg_y);
}
last_hand_x = avg_x;
last_hand_y = avg_y;
sample_ready = 0;
}
}
//skeltrack_joint_list_free(joints_list); //this segfaults sometimes???? idk.
//if(joints_list != NULL)
//skeltrack_joint_list_free(joints_list); //this segfaults sometimes???? idk.
}
return FALSE;
}
Expand Down
Binary file modified software/drawing.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion software/include/main.h
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@
#define THRESHOLD_BEGIN 500
#define THRESHOLD_END 1500

#define JOY_POLL_PERIOD 50 // ms to poll joystick for data
#define JOY_POLL_PERIOD 100 // ms to poll joystick for data

// Shared variables
extern GtkWidget *window;
Expand Down
9 changes: 6 additions & 3 deletions software/main.c
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ GtkWidget *window;
// these are declared in the header file as extern but idk if we actually want to share them?
GFreenectDevice *kinect = NULL;
SkeltrackSkeleton *skeleton = NULL;
gfloat smoothing_factor = 0.5;
gfloat smoothing_factor = 0.0;

void scale_point_cloud(GtkApplication *app,
gpointer data){
Expand Down Expand Up @@ -192,7 +192,8 @@ static void on_depth_frame (GFreenectDevice *dev, gpointer data){
// draw relevant joints and process them. this sends a new
// draw signal hopefully
if(drawing_area != NULL){
gtk_widget_queue_draw_area(drawing_area, 0, 0, WINDOW_WIDTH, WINDOW_HEIGHT);
if(GTK_IS_WIDGET(drawing_area))
gtk_widget_queue_draw(drawing_area);
}
}

Expand Down Expand Up @@ -232,12 +233,14 @@ static void on_new_kinect(GObject *obj,

//gfreenect_device_set_tilt_angle(kinect, 0, NULL, NULL, NULL);
gfreenect_device_start_depth_stream(kinect,
GFREENECT_DEPTH_FORMAT_MM,
GFREENECT_DEPTH_FORMAT_REGISTERED,
NULL);
/*
gfreenect_device_start_video_stream(kinect,
GFREENECT_RESOLUTION_MEDIUM,
GFREENECT_VIDEO_FORMAT_RGB,
NULL);
*/
}

/**
Expand Down
23 changes: 11 additions & 12 deletions software/selector_v1.c
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
#include <selector.h>
#include <stdio.h>

//static GtkWidget *drawing_area;
static GtkWidget *selector_area;
static GtkWidget *image_display_area; // GtkImage widget for displaying the loaded image
static GtkWidget *vbox;
static double box_x = 0;
Expand All @@ -37,27 +37,27 @@ static void save_coordinates(double x, double y);
void activate_selector( GObject* self,
GParamSpec* pspec,
gpointer user_data){
// printf("Selector should be active now.\n");

// Create a vertical box to hold the drawing area and image display area
vbox = gtk_box_new(GTK_ORIENTATION_VERTICAL, 0);
gtk_container_add(GTK_CONTAINER(window), vbox);

// Create drawing area
drawing_area = gtk_drawing_area_new();
gtk_widget_set_size_request(drawing_area, WINDOW_WIDTH / 2, WINDOW_HEIGHT);
gtk_box_pack_start(GTK_BOX(vbox), drawing_area, TRUE, TRUE, 0);
selector_area = gtk_drawing_area_new();
gtk_widget_set_size_request(selector_area, WINDOW_WIDTH / 2, WINDOW_HEIGHT);
gtk_box_pack_start(GTK_BOX(vbox), selector_area, TRUE, TRUE, 0);

// Create image display area
image_display_area = gtk_image_new();
gtk_widget_set_size_request(image_display_area, WINDOW_WIDTH / 2, WINDOW_HEIGHT);
gtk_box_pack_start(GTK_BOX(vbox), image_display_area, TRUE, TRUE, 0);

printf("Selector should be active now.\n");
// Load and set the image
load_and_set_image();

// Connect signals to callback functions
g_signal_connect(G_OBJECT(drawing_area), "draw", G_CALLBACK(on_draw), NULL);
g_signal_connect(G_OBJECT(selector_area), "draw", G_CALLBACK(on_draw), NULL);
g_signal_connect(window, "key-press-event", G_CALLBACK(on_key_press), NULL);

gtk_widget_set_events(window, GDK_KEY_PRESS_MASK);
Expand Down Expand Up @@ -102,7 +102,7 @@ static void move_box(double dx, double dy) {
if (box_y + GRID_SIZE > WINDOW_HEIGHT)
box_y = WINDOW_HEIGHT - GRID_SIZE;

gtk_widget_queue_draw(drawing_area); // Redraw the drawing area
gtk_widget_queue_draw(selector_area); // Redraw the drawing area

// Update the image display area with the loaded image
/* if (image_pixbuf != NULL) { */
Expand Down Expand Up @@ -158,7 +158,7 @@ static void save_coordinates(double x, double y) {
static void finish_selector_stage() {
// Clean up widgets
gtk_widget_destroy(vbox);
gtk_widget_destroy(drawing_area);
gtk_widget_destroy(selector_area);
gtk_widget_destroy(image_display_area);

// Disconnect signal handler for keypress
Expand Down Expand Up @@ -198,7 +198,7 @@ static void on_key_press(GtkWidget *widget, GdkEventKey *event, gpointer user_da

display_image = !display_image; // Toggle the display_image flag

gtk_widget_queue_draw(drawing_area);
gtk_widget_queue_draw(selector_area);
break;
default:
break;
Expand All @@ -217,15 +217,14 @@ static void load_and_set_image() {
}
GError *error = NULL;
image_pixbuf = gdk_pixbuf_new_from_file(image_file_path, &error);
preview_pixbuf = gdk_pixbuf_new_from_file(image_file_path, &error);

//preview_pixbuf = gdk_pixbuf_new_from_file(image_file_path, &error);
if (error != NULL) {
g_printerr("Error loading %s: %s\n", image_file_path, error->message);
g_error_free(error);
}

// Set the image in the image_display_area
gtk_image_set_from_pixbuf(GTK_IMAGE(image_display_area), preview_pixbuf);
//gtk_image_set_from_pixbuf(GTK_IMAGE(image_display_area), preview_pixbuf);

// Set shrunken image in the image_pixbuf buffer
gtk_image_set_from_pixbuf(GTK_IMAGE(image_display_area), image_pixbuf);
Expand Down

0 comments on commit 18ace5b

Please sign in to comment.