Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix crash in added views #292

Merged
merged 6 commits into from
Apr 5, 2020
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
moved AddedViews removal to new fun releaseAddedViewsAfterSnapshot to…
… make sure these are not added to a parent no matter what happened in the process of creating a ghost view snapshot
mzorz committed Apr 4, 2020
commit 601463b430314d1238c42e2bb1bd874ea58f94f6
Original file line number Diff line number Diff line change
@@ -119,6 +119,14 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
saveProgressListener?.onFrameSaveCompleted(frameIndex)
} catch (ex: Exception) {
saveProgressListener?.onFrameSaveFailed(frameIndex, ex.message)
} finally {
// if anything happened, just make sure the added views were removed from the offscreen
// photoEditor layout, otherwise it won't be possible to re-add them when we show the
// error screen and the user taps on the errored frames (crash will happen)
// Also, it's okay if this gets called more than once (for instance, when no exceptions
// are thrown) given it internally does check whether the parent contains the view before
// attempting to remove it
releaseAddedViewsAfterSnapshot(frame)
}
}
}
@@ -133,17 +141,23 @@ class FrameSaveManager(private val photoEditor: PhotoEditor) : CoroutineScope {
): File {
// prepare the ghostview with its background image and the AddedViews on top of it
preparePhotoEditorViewForSnapshot(frame, ghostPhotoEditorView)

val file = withContext(Dispatchers.IO) {
return@withContext photoEditor.saveImageFromPhotoEditorViewAsLoopFrameFile(frameIndex, ghostPhotoEditorView)
}

releaseAddedViewsAfterSnapshot(frame)

return file
}

private suspend fun releaseAddedViewsAfterSnapshot(frame: StoryFrameItem) {
withContext(Dispatchers.Main) {
// don't forget to remove these views from ghost offscreen view before exiting
for (oneView in frame.addedViews) {
removeViewFromParent(oneView.view)
}
}
return file
}

private suspend fun saveVideoFrame(