Skip to content

Commit 9ffd6a6

Browse files
committed
Fixing crash when destructing Timeline/Clips/FrameMapper
1 parent 6335d6f commit 9ffd6a6

File tree

3 files changed

+5
-27
lines changed

3 files changed

+5
-27
lines changed

include/FrameMapper.h

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -213,6 +213,9 @@ namespace openshot
213213
/// Get the current reader
214214
ReaderBase* Reader();
215215

216+
/// Set the current reader
217+
void Reader(ReaderBase *new_reader) { reader = new_reader; }
218+
216219
/// Resample audio and map channels (if needed)
217220
void ResampleMappedAudio(std::shared_ptr<Frame> frame, int64_t original_frame_number);
218221

src/Timeline.cpp

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -80,6 +80,8 @@ Timeline::~Timeline() {
8080
for (frame_mapper_itr = allocated_frame_mappers.begin(); frame_mapper_itr != allocated_frame_mappers.end(); ++frame_mapper_itr) {
8181
// Get frame mapper object from the iterator
8282
FrameMapper *frame_mapper = (*frame_mapper_itr);
83+
frame_mapper->Reader(NULL);
84+
frame_mapper->Close();
8385
delete frame_mapper;
8486
}
8587
allocated_frame_mappers.clear();

tests/Timeline_Tests.cpp

Lines changed: 0 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -185,61 +185,48 @@ TEST(Timeline_Check_Two_Track_Video)
185185
TEST(Timeline_Clip_Order)
186186
{
187187
// Create a timeline
188-
cout << "A" << endl;
189188
Timeline t(640, 480, Fraction(30, 1), 44100, 2, LAYOUT_STEREO);
190-
cout << "B" << endl;
191189

192190
// Add some clips out of order
193191
stringstream path_top;
194192
path_top << TEST_MEDIA_PATH << "front3.png";
195193
Clip clip_top(path_top.str());
196194
clip_top.Layer(2);
197195
t.AddClip(&clip_top);
198-
cout << "C" << endl;
199196

200197
stringstream path_middle;
201198
path_middle << TEST_MEDIA_PATH << "front.png";
202199
Clip clip_middle(path_middle.str());
203200
clip_middle.Layer(0);
204201
t.AddClip(&clip_middle);
205-
cout << "D" << endl;
206202

207203
stringstream path_bottom;
208204
path_bottom << TEST_MEDIA_PATH << "back.png";
209205
Clip clip_bottom(path_bottom.str());
210206
clip_bottom.Layer(1);
211207
t.AddClip(&clip_bottom);
212-
cout << "E" << endl;
213208

214209
// Open Timeline
215210
t.Open();
216-
cout << "F" << endl;
217211

218212
// Loop through Clips and check order (they should have been sorted into the correct order)
219213
// Bottom layer to top layer, then by position.
220214
list<Clip*>::iterator clip_itr;
221215
list<Clip*> clips = t.Clips();
222-
cout << "G" << endl;
223216
int counter = 0;
224217
for (clip_itr=clips.begin(); clip_itr != clips.end(); ++clip_itr)
225218
{
226-
cout << "H" << endl;
227219
// Get clip object from the iterator
228220
Clip *clip = (*clip_itr);
229221

230-
cout << "I" << endl;
231-
232222
switch (counter) {
233223
case 0:
234-
cout << "J" << endl;
235224
CHECK_EQUAL(0, clip->Layer());
236225
break;
237226
case 1:
238-
cout << "K" << endl;
239227
CHECK_EQUAL(1, clip->Layer());
240228
break;
241229
case 2:
242-
cout << "L" << endl;
243230
CHECK_EQUAL(2, clip->Layer());
244231
break;
245232
}
@@ -248,8 +235,6 @@ TEST(Timeline_Clip_Order)
248235
counter++;
249236
}
250237

251-
cout << "M" << endl;
252-
253238
// Add another clip
254239
stringstream path_middle1;
255240
path_middle1 << TEST_MEDIA_PATH << "interlaced.png";
@@ -258,35 +243,27 @@ TEST(Timeline_Clip_Order)
258243
clip_middle1.Position(0.5);
259244
t.AddClip(&clip_middle1);
260245

261-
cout << "N" << endl;
262-
263246
// Loop through clips again, and re-check order
264247
counter = 0;
265248
clips = t.Clips();
266-
cout << "O" << endl;
267249
for (clip_itr=clips.begin(); clip_itr != clips.end(); ++clip_itr)
268250
{
269251
// Get clip object from the iterator
270252
Clip *clip = (*clip_itr);
271-
cout << "P" << endl;
272253

273254
switch (counter) {
274255
case 0:
275-
cout << "Q" << endl;
276256
CHECK_EQUAL(0, clip->Layer());
277257
break;
278258
case 1:
279-
cout << "R" << endl;
280259
CHECK_EQUAL(1, clip->Layer());
281260
CHECK_CLOSE(0.0, clip->Position(), 0.0001);
282261
break;
283262
case 2:
284-
cout << "S" << endl;
285263
CHECK_EQUAL(1, clip->Layer());
286264
CHECK_CLOSE(0.5, clip->Position(), 0.0001);
287265
break;
288266
case 3:
289-
cout << "T" << endl;
290267
CHECK_EQUAL(2, clip->Layer());
291268
break;
292269
}
@@ -295,12 +272,8 @@ TEST(Timeline_Clip_Order)
295272
counter++;
296273
}
297274

298-
cout << "U" << endl;
299-
300275
// Close reader
301276
t.Close();
302-
303-
cout << "V" << endl;
304277
}
305278

306279

0 commit comments

Comments
 (0)