Skip to content

Commit 3fc6bda

Browse files
authored
Merge pull request #2045 from verilog-to-routing/vpr_graphics_crash_fix
VPR Graphics Crash Fixed
2 parents 56fc983 + 266b636 commit 3fc6bda

File tree

4 files changed

+19
-27
lines changed

4 files changed

+19
-27
lines changed

vpr/src/draw/buttons.cpp

Lines changed: 7 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -36,37 +36,21 @@ void button_for_net_alpha() {
3636
gtk_grid_insert_column((GtkGrid*)grid, 0);
3737

3838
//text entry for apha value
39-
GtkWidget* entry = gtk_entry_new();
40-
std::string initialValue = std::to_string(get_net_alpha());
41-
gtk_entry_set_text((GtkEntry*)entry, initialValue.c_str());
42-
gtk_entry_set_input_purpose((GtkEntry*)entry, GTK_INPUT_PURPOSE_NUMBER);
43-
gtk_widget_set_name(entry, "alphaValue");
44-
gtk_entry_set_activates_default((GtkEntry*)entry, TRUE);
39+
GtkWidget* alpha_widget = gtk_spin_button_new_with_range(0, 100, 1);
40+
GtkWidget* alpha_label = gtk_label_new("Set Net Transparency:");
41+
gtk_widget_set_name(alpha_widget, "netAlpha");
4542

46-
//label
47-
GtkWidget* alpha_label = gtk_label_new("Set net transparency [0., 1.]");
48-
49-
//button
50-
GtkWidget* button = gtk_button_new_with_label("set");
51-
52-
//attach to the grid
53-
gtk_grid_attach((GtkGrid*)grid, entry, 0, 0, box_width, box_height);
54-
gtk_grid_attach((GtkGrid*)grid, button, 1, 0, box_width, box_height);
5543
gtk_grid_attach((GtkGrid*)main_window_grid, alpha_label, label_left_start_col, button_row++, box_width, box_height);
56-
gtk_grid_attach((GtkGrid*)main_window_grid, grid, box_left_start_col, button_row++, box_width, box_height);
44+
gtk_grid_attach((GtkGrid*)main_window_grid, alpha_widget, box_left_start_col, button_row++, box_width, box_height);
5745

5846
//show newly added contents
5947
gtk_widget_show_all((GtkWidget*)main_window);
6048

6149
//connect signals
62-
g_signal_connect_swapped(GTK_BUTTON(button),
63-
"clicked",
50+
g_signal_connect_swapped((GtkSpinButton*)alpha_widget,
51+
"value_changed",
6452
G_CALLBACK(set_net_alpha_value),
65-
entry);
66-
g_signal_connect_swapped(GTK_ENTRY(entry),
67-
"activate",
68-
G_CALLBACK(set_net_alpha_value_with_enter),
69-
entry);
53+
alpha_widget);
7054
}
7155

7256
void button_for_toggle_nets() {

vpr/src/draw/draw.cpp

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4406,10 +4406,16 @@ static void highlight_blocks(double x, double y) {
44064406
application.update_message(msg);
44074407
application.refresh_drawing();
44084408
}
4409-
void set_net_alpha_value(GtkWidget* widget, gint /*response_id*/, gpointer /*data*/) {
4410-
std::string fa(gtk_entry_get_text((GtkEntry*)widget));
4409+
void set_net_alpha_value(GtkWidget* /*widget*/, gint /*response_id*/, gpointer /*data*/) {
4410+
std::string button_name = "netAlpha";
4411+
auto net_alpha = find_button(button_name.c_str());
44114412
t_draw_state* draw_state = get_draw_state_vars();
4412-
draw_state->net_alpha = std::stof(fa);
4413+
4414+
//set draw_state->net_alpha to its corresponding value in the ui
4415+
int new_value = gtk_spin_button_get_value_as_int((GtkSpinButton*)net_alpha) / 100;
4416+
draw_state->net_alpha = new_value;
4417+
4418+
//redraw
44134419
application.refresh_drawing();
44144420
}
44154421

vpr/src/draw/draw_debug.cpp

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -752,7 +752,8 @@ bool valid_expression(std::string exp) {
752752
}
753753

754754
//if expression started or ended with a bool operand or vector has and even number of operators (since in a valid expression number of operators are always odd)
755-
if (ops[0] == BOOL_OP || ops[ops.size() - 1] == BOOL_OP || ops.size() % 2 == 0)
755+
//checks if ops is empty first so trying to access ops[0] doesn't produce a seg fault
756+
if (ops.size() == 0 || ops[0] == BOOL_OP || ops[ops.size() - 1] == BOOL_OP || ops.size() % 2 == 0)
756757
return false;
757758

758759
//checks pattern (should be 0 1 0 1 0 ...) since in a valid expression comperator operators and bool operators are used in that pattern (e.g move_num == 3 || from_block == 11)
@@ -762,6 +763,7 @@ bool valid_expression(std::string exp) {
762763
else if (j % 2 != 0 && ops[j] == COMP_OP)
763764
return false;
764765
}
766+
765767
return true;
766768
}
767769

vpr/src/power/power_utils.h

Whitespace-only changes.

0 commit comments

Comments
 (0)