From: Emden R. Gansner Date: Tue, 10 Mar 2015 19:33:28 +0000 (-0400) Subject: Fix callback for writing an output file to avoid a crash or a new X-Git-Tag: TRAVIS_CI_BUILD_EXPERIMENTAL~119 X-Git-Url: https://granicus.if.org/sourcecode?a=commitdiff_plain;h=4d7bb2fe732c906413cfb7aaf5989265c8020900;p=graphviz Fix callback for writing an output file to avoid a crash or a new window popping up. --- diff --git a/lib/gvc/gvevent.c b/lib/gvc/gvevent.c index 89ffa5b89..a9c0ed33d 100644 --- a/lib/gvc/gvevent.c +++ b/lib/gvc/gvevent.c @@ -618,7 +618,28 @@ static void gvevent_layout (GVJ_t * job, const char *layout) static void gvevent_render (GVJ_t * job, const char *format, const char *filename) { +/* If gvc->jobs is set, a new job for doing the rendering won't be created. + * If gvc->active_jobs is set, this will be used in a call to gv_end_job. + * If we assume this function is called by an interactive front-end which + * actually wants to write a file, the above possibilities can cause problems, + * with either gvc->job being NULL or the creation of a new window. To avoid + * this, we null out these values for rendering the file, and restore them + * afterwards. John may have a better way around this. + */ + GVJ_t* save_jobs; + GVJ_t* save_active; + if (job->gvc->jobs && (job->gvc->job == NULL)) { + save_jobs = job->gvc->jobs; + save_active = job->gvc->active_jobs; + job->gvc->active_jobs = job->gvc->jobs = NULL; + } + else + save_jobs = NULL; gvRenderFilename(job->gvc, job->gvc->g, format, filename); + if (save_jobs) { + job->gvc->jobs = save_jobs; + job->gvc->active_jobs = save_active; + } }