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

Frame extractor: fix ConcurrentModificationException when removing jobs #195

Merged
merged 1 commit into from
Jun 6, 2022
Merged
Changes from all commits
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
Original file line number Diff line number Diff line change
Expand Up @@ -81,14 +81,16 @@ class VideoFrameExtractor @JvmOverloads constructor(
* Cancels all started extract jobs. [FrameExtractListener.onCancelled] will be called for jobs that have been started.
*/
fun stopAll() {
activeJobMap.forEach { (requestId, job) ->
val iterator = activeJobMap.iterator()
while (iterator.hasNext()) {
val job = iterator.next().value
if (!job.future.isCancelled && !job.future.isDone) {
job.future.cancel(true)
}
if (!job.future.isStarted) {
// If the job hasn't started, it won't probably even start, but it will remain in the activeJobMap,
// we must remove it from there.
activeJobMap.remove(requestId)
iterator.remove()
}
}
}
Expand Down