@@ -39,6 +39,7 @@ void dt_grouping_add_to_group(const dt_imgid_t group_id,
39
39
dt_grouping_remove_from_group (image_id );
40
40
41
41
dt_image_t * img = dt_image_cache_get (darktable .image_cache , image_id , 'w' );
42
+ if (!img ) return ;
42
43
img -> group_id = group_id ;
43
44
dt_image_cache_write_release_info (darktable .image_cache , img ,
44
45
DT_IMAGE_CACHE_SAFE , "dt_grouping_add_to_group" );
@@ -65,7 +66,7 @@ dt_imgid_t dt_grouping_remove_from_group(const dt_imgid_t image_id)
65
66
GList * imgs = NULL ;
66
67
67
68
const dt_image_t * img = dt_image_cache_get (darktable .image_cache , image_id , 'r' );
68
- const int img_group_id = img -> group_id ;
69
+ const dt_imgid_t img_group_id = img ? img -> group_id : NO_IMGID ;
69
70
dt_image_cache_read_release (darktable .image_cache , img );
70
71
if (img_group_id == image_id )
71
72
{
@@ -84,10 +85,13 @@ dt_imgid_t dt_grouping_remove_from_group(const dt_imgid_t image_id)
84
85
if (!dt_is_valid_imgid (new_group_id ))
85
86
new_group_id = other_id ;
86
87
dt_image_t * other_img = dt_image_cache_get (darktable .image_cache , other_id , 'w' );
87
- other_img -> group_id = new_group_id ;
88
- dt_image_cache_write_release_info (darktable .image_cache , other_img ,
88
+ if (other_img )
89
+ {
90
+ other_img -> group_id = new_group_id ;
91
+ dt_image_cache_write_release_info (darktable .image_cache , other_img ,
89
92
DT_IMAGE_CACHE_SAFE , "dt_grouping_add_to_group" );
90
- imgs = g_list_prepend (imgs , GINT_TO_POINTER (other_id ));
93
+ imgs = g_list_prepend (imgs , GINT_TO_POINTER (other_id ));
94
+ }
91
95
}
92
96
sqlite3_finalize (stmt );
93
97
if (dt_is_valid_imgid (new_group_id ))
@@ -122,13 +126,15 @@ dt_imgid_t dt_grouping_remove_from_group(const dt_imgid_t image_id)
122
126
{
123
127
// change the group_id for this image.
124
128
dt_image_t * wimg = dt_image_cache_get (darktable .image_cache , image_id , 'w' );
125
- new_group_id = wimg -> group_id ;
126
- wimg -> group_id = image_id ;
127
- dt_image_cache_write_release_info (darktable .image_cache , wimg ,
129
+ if (wimg )
130
+ {
131
+ new_group_id = wimg -> group_id ;
132
+ wimg -> group_id = image_id ;
133
+ dt_image_cache_write_release_info (darktable .image_cache , wimg ,
128
134
DT_IMAGE_CACHE_SAFE , "dt_grouping_add_to_group" );
129
- imgs = g_list_prepend (imgs , GINT_TO_POINTER (image_id ));
130
- // refresh also the group leader which may be alone now
131
- imgs = g_list_prepend (imgs , GINT_TO_POINTER (img_group_id ));
135
+ imgs = g_list_prepend (imgs , GINT_TO_POINTER (image_id ));
136
+ // refresh also the group leader which may be alone now
137
+ imgs = g_list_prepend (imgs , GINT_TO_POINTER (img_group_id ));
132
138
#ifdef USE_LUA
133
139
dt_lua_async_call_alien (dt_lua_event_trigger_wrapper ,
134
140
0 , NULL , NULL ,
@@ -138,6 +144,7 @@ dt_imgid_t dt_grouping_remove_from_group(const dt_imgid_t image_id)
138
144
LUA_ASYNC_TYPENAME , "dt_lua_image_t" , GINT_TO_POINTER (img_group_id ),
139
145
LUA_ASYNC_DONE );
140
146
#endif
147
+ }
141
148
}
142
149
DT_CONTROL_SIGNAL_RAISE (DT_SIGNAL_IMAGE_INFO_CHANGED , imgs );
143
150
@@ -150,8 +157,10 @@ dt_imgid_t dt_grouping_change_representative(const dt_imgid_t image_id)
150
157
sqlite3_stmt * stmt ;
151
158
152
159
dt_image_t * img = dt_image_cache_get (darktable .image_cache , image_id , 'r' );
153
- const dt_imgid_t group_id = img -> group_id ;
160
+ const dt_imgid_t group_id = img ? img -> group_id : NO_IMGID ;
154
161
dt_image_cache_read_release (darktable .image_cache , img );
162
+ if (!dt_is_valid_imgid (group_id ))
163
+ return group_id ;
155
164
156
165
GList * imgs = NULL ;
157
166
DT_DEBUG_SQLITE3_PREPARE_V2 (dt_database_get (darktable .db ), "SELECT id FROM main.images WHERE group_id = ?1" , -1 ,
@@ -161,11 +170,14 @@ dt_imgid_t dt_grouping_change_representative(const dt_imgid_t image_id)
161
170
{
162
171
const dt_imgid_t other_id = sqlite3_column_int (stmt , 0 );
163
172
dt_image_t * other_img = dt_image_cache_get (darktable .image_cache , other_id , 'w' );
164
- other_img -> group_id = image_id ;
165
- dt_image_cache_write_release_info (darktable .image_cache , other_img ,
173
+ if (other_img )
174
+ {
175
+ other_img -> group_id = image_id ;
176
+ dt_image_cache_write_release_info (darktable .image_cache , other_img ,
166
177
DT_IMAGE_CACHE_SAFE ,
167
178
"dt_grouping_change_representative" );
168
- imgs = g_list_prepend (imgs , GINT_TO_POINTER (other_id ));
179
+ imgs = g_list_prepend (imgs , GINT_TO_POINTER (other_id ));
180
+ }
169
181
}
170
182
sqlite3_finalize (stmt );
171
183
DT_CONTROL_SIGNAL_RAISE (DT_SIGNAL_IMAGE_INFO_CHANGED , imgs );
0 commit comments