Skip to content

Commit

Permalink
projectorganizer: Make sure project is open before trying to expand t…
Browse files Browse the repository at this point in the history
…he tree

Since expand_on_idle() is called as an idle function, it can happen it's
executed after project is closed. Before trying to expand paths it now
first checks if the idle call corresponds to the project for which
the idle call was created.

Should fix crash reported in geany#549.
  • Loading branch information
techee committed Apr 5, 2017
1 parent 4f1352f commit adf01d6
Showing 1 changed file with 20 additions and 9 deletions.
29 changes: 20 additions & 9 deletions projectorganizer/src/prjorg-sidebar.c
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,13 @@ typedef enum
MATCH_PATTERN
} MatchType;

typedef struct
{
GeanyProject *project;
GPtrArray *expanded_paths;
} ExpandData;


static GdkColor s_external_color;
static GtkWidget *s_toolbar = NULL;
static gboolean s_pending_reload = FALSE;
Expand Down Expand Up @@ -1210,22 +1217,24 @@ static gboolean expand_path(gchar *utf8_expanded_path, gboolean select)
}


static gboolean expand_on_idle(gpointer ptr)
static gboolean expand_on_idle(ExpandData *expand_data)
{
GeanyDocument *doc = document_get_current();

if (ptr)
if (prj_org && geany_data->app->project == expand_data->project &&
expand_data->expanded_paths)
{
GPtrArray *expanded_paths = ptr;
gchar *item;
guint i;

foreach_ptr_array(item, i, expanded_paths)
foreach_ptr_array(item, i, expand_data->expanded_paths)
expand_path(item, FALSE);
g_ptr_array_free(expanded_paths, TRUE);
g_ptr_array_free(expand_data->expanded_paths, TRUE);
}

if (!s_follow_editor || !doc || !doc->file_name || !geany_data->app->project || !prj_org)
g_free(expand_data);

if (!s_follow_editor || !doc || !doc->file_name)
return FALSE;

expand_path(doc->file_name, TRUE);
Expand Down Expand Up @@ -1281,11 +1290,13 @@ static GPtrArray *get_expanded_paths(void)

void prjorg_sidebar_update(gboolean reload)
{
GPtrArray *expanded_paths = NULL;
ExpandData *expand_data = g_new0(ExpandData, 1);

expand_data->project = geany_data->app->project;

if (reload)
{
expanded_paths = get_expanded_paths();
expand_data->expanded_paths = get_expanded_paths();

load_project();
/* we get color information only after the sidebar is realized -
Expand All @@ -1295,7 +1306,7 @@ void prjorg_sidebar_update(gboolean reload)
}

/* perform on idle - avoids unnecessary jumps on project load */
plugin_idle_add(geany_plugin, (GSourceFunc)expand_on_idle, expanded_paths);
plugin_idle_add(geany_plugin, (GSourceFunc)expand_on_idle, expand_data);
}


Expand Down

0 comments on commit adf01d6

Please sign in to comment.