fix: fix destruct problem during initialization #548
Merged
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.
I developed a Qt GUI that acts as a plugin manager. In this application, when I rapidly load and unload a class implemented using qcefview, an exception is thrown inside the destroyCefBrowser() function.
By “rapidly,” I mean the following scenario: during the first initialization, the CEF library appears to asynchronously create a web context and its internal threads in the background. In other words, when a QCefView instance is created, this background initialization process has not yet fully completed. However, if I assume that the browser is already fully created and immediately call the destructor, ncw.qBrowserWidget ends up being nullptr.
I encountered this issue while testing edge cases in my system. If I activate the plugin and then deactivate it very quickly (for example, after about 0.2 seconds), the problem occurs. However, if I activate the plugin, wait for a certain amount of time (approximately 1.5 seconds), and then deactivate it, no issue occurs. Additionally, after the first successful initialization, even if I rapidly close and reopen the plugin, the problem no longer appears.
I should also mention that in my UI, it is not possible to remove or deactivate a plugin before it has been loaded. In other words, deactivation is only possible after the QCefView constructor has completed. Despite this, the issue still occurs, which suggests that although the constructor finishes, the internal CEF browser creation is still ongoing asynchronously.