[ui] Drag&Drop: Use a pool of threads for asynchronous intrinsics computations #1896
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Description
This PR fixes an issue that occurred when dragging and dropping images from a folder into Meshroom's Image Gallery.
When dropping new images, the intrinsics were rebuilt asynchronously in a thread that was not attached to anything. The update of the intrinsics, performed in the main thead following a signal emitted in the detached thread, would block when there were already some existing intrinsics (and thus already some existing images in the gallery) because the garbage collector would destroy the thread in which the new intrinsics had been computed while the update was ongoing. It seems the issue did not appear when there was not any image in the gallery because the update of the intrinsics did not need to remove the previously existing ones before adding the new ones.
This pull request adds a pool of threads (currently, the pool contains a single thread as the intrinsics computation is the only operation that needs to be performed asynchronously) to the Reconstruction object and uses it to perform the intrinsics computations asynchronously. As a consequence, the update of the intrinsics does not remain blocked and images can be dragged and dropped in the Image Gallery safely.
Additionally, importing images through the "Import Images" menu action is now performed asynchronously as well. It used to be synchronous, and as such, not subject to the update issue, but as it was both a blocking and costly operations, it would freeze the application entirely until it was completed. "Import Images" now uses the same workflow as dragging and dropping images.
Features list
Implementation remarks