mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Profile: properly initialize plot_info structures
The create_plot_info_new() function releases old plot data. This can only work if the plot_info structure was initialized previously. The ProfileWidget2 did that by a memset, but other parts of the code did not. Therefore, introduce a init_plot_info() function and call that when generating a plot_info struct. Constructors would make this so much easier - but since this is called from C, we can't use them. Fixes #2251 Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
0e55739f03
commit
25b30da244
7 changed files with 18 additions and 4 deletions
|
@ -1318,12 +1318,23 @@ static void debug_print_profiledata(struct plot_info *pi)
|
|||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Initialize a plot_info structure to all-zeroes
|
||||
*/
|
||||
void init_plot_info(struct plot_info *pi)
|
||||
{
|
||||
memset(pi, 0, sizeof(*pi));
|
||||
}
|
||||
|
||||
/*
|
||||
* Create a plot-info with smoothing and ranged min/max
|
||||
*
|
||||
* This also makes sure that we have extra empty events on both
|
||||
* sides, so that you can do end-points without having to worry
|
||||
* about it.
|
||||
*
|
||||
* The old data will be freed. Before the first call, the plot
|
||||
* info must be initialized with init_plot_info().
|
||||
*/
|
||||
void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, struct deco_state *planner_ds)
|
||||
{
|
||||
|
|
|
@ -80,6 +80,7 @@ struct ev_select {
|
|||
|
||||
extern void compare_samples(struct plot_data *e1, struct plot_data *e2, char *buf, int bufsize, int sum);
|
||||
extern struct plot_info *analyze_plot_info(struct plot_info *pi);
|
||||
extern void init_plot_info(struct plot_info *pi);
|
||||
extern void create_plot_info_new(struct dive *dive, struct divecomputer *dc, struct plot_info *pi, bool fast, struct deco_state *planner_ds);
|
||||
extern void calculate_deco_information(struct deco_state *ds, const struct deco_state *planner_de, const struct dive *dive, const struct divecomputer *dc, struct plot_info *pi, bool print_mode);
|
||||
extern struct plot_data *get_plot_details_new(struct plot_info *pi, int time, struct membuffer *);
|
||||
|
|
|
@ -199,6 +199,7 @@ static void save_profiles_buffer(struct membuffer *b, bool select_only)
|
|||
struct plot_info pi;
|
||||
struct deco_state *planner_deco_state = NULL;
|
||||
|
||||
init_plot_info(&pi);
|
||||
for_each_dive(i, dive) {
|
||||
if (select_only && !dive->selected)
|
||||
continue;
|
||||
|
@ -220,6 +221,7 @@ void save_subtitles_buffer(struct membuffer *b, struct dive *dive, int offset, i
|
|||
struct plot_info pi;
|
||||
struct deco_state *planner_deco_state = NULL;
|
||||
|
||||
init_plot_info(&pi);
|
||||
create_plot_info_new(dive, &dive->dc, &pi, false, planner_deco_state);
|
||||
|
||||
put_format(b, "[Script Info]\n");
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue