Fix linked list corruption, move code to C.

The picture list is a single linked list where the pictures have a node to
their next element. When adding the same picture to two dives, things got
way way wrong and crashes were appearing.

This will replicate the information (filename, latitude and longitude) for
each dive that has the picture, BUT it still tries to save as much as
possible on the actual pixmap.

Signed-off-by: Tomaz Canabrava <tomaz.canabrava@intel.com>
Signed-off-by: Dirk Hohndel <dirk@hohndel.org>
This commit is contained in:
Tomaz Canabrava 2014-06-03 14:51:47 -03:00 committed by Dirk Hohndel
parent 58f2613dae
commit f53b5c4d3f
3 changed files with 13 additions and 8 deletions

11
dive.c
View file

@ -2269,6 +2269,17 @@ struct picture *alloc_picture()
return pic;
}
void dive_create_picture(struct dive *d, char *filename, int shift_time)
{
struct picture *p = alloc_picture();
if (p->timestamp)
p->timestamp += shift_time;
p->filename = filename;
picture_load_exif_data(p);
dive_add_picture(d, p);
dive_set_geodata_from_picture(d, p);
}
void dive_add_picture(struct dive *d, struct picture *picture)
{
if (d->picture_list == NULL) {

1
dive.h
View file

@ -297,6 +297,7 @@ struct picture {
extern struct picture *alloc_picture();
extern void dive_create_picture(struct dive *d, char *filename, int shift_time);
extern void dive_add_picture(struct dive *d, struct picture *pic);
extern void dive_remove_picture(struct dive *d, struct picture *pic);
extern unsigned int dive_get_picture_count(struct dive *d);

View file

@ -775,19 +775,12 @@ void DiveListView::loadImages()
updateLastImageTimeOffset(shiftDialog.amount());
Q_FOREACH(const QString& fileName, fileNames) {
picture *p = alloc_picture();
p->filename = qstrdup(fileName.toUtf8().data());
picture_load_exif_data(p);
if (p->timestamp)
p->timestamp += shiftDialog.amount(); // TODO: this should be cached and passed to the C-function
int j = 0;
struct dive *dive;
for_each_dive (j, dive) {
if (!dive->selected)
continue;
dive_add_picture(dive, p);
dive_set_geodata_from_picture(dive, p);
dive_create_picture(dive, qstrdup(fileName.toUtf8().data()), shiftDialog.amount());
}
}