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

MainWindow: Fix crash for quick image changes #95

Merged
merged 1 commit into from
Jun 27, 2017
Merged

Conversation

palinek
Copy link
Contributor

@palinek palinek commented Jun 26, 2017

fixes #94

// to nullptr). This simple check should be enough.
if (sender() == loadJob_)
{
image_ = loadJob_->image();
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That should help but it's still not really safe, the other thread could definitely change loadJob_ to nullptr between the if and this line. And this thread could also set it to nullptr between the nullptr check and the cancel in the other thread.

Even if you were also using sender() on this line I believe the other accesses to loadJob_ (== and = nullptr) would still technically be undefined behaviour. We need to either make sure we don't need to access it concurrently or just lock it with a mutex when we do.

@palinek
Copy link
Contributor Author

palinek commented Jun 26, 2017

the other thread could definitely change loadJob_ to nullptr between the if and this line.

Nope, the "job" thread doesn't change the loadJob_ member anyhow. It is purely handled in the MainWindow and the main thread. Also the LoadJob objects are created in the main thread.

The race solved here was as follows: the "job" thread is running and user wants to load a new picture, so the the MainWindow cancels the running job and creates a new one. But in the meanwhile the old load "job" is finished (before it could have been cancelled) and emitted the finished() signal (so the onImageLoaded() is queued to event processing loop into the main thread). Ten onImageLoaded() is executed and loadJob_ is set to nullptr. When the new load "job" is finished and the onImageLoaded() executed.... the loadJob_ is nullptr and the crash happens.

@npmiller
Copy link
Contributor

Oh I see that makes sense, because of the behaviour I was under the impression that onImageLoaded() ended up running in the job thread somehow. But I see how it could happen with the behaviour you describe. I can't test it right now but if that's actually what's going on then your fix is good.

+1

@agaida
Copy link
Member

agaida commented Jun 27, 2017

GTM

@agaida agaida merged commit 7bea6c0 into master Jun 27, 2017
@agaida agaida deleted the load_cancel branch June 27, 2017 17:38
@agaida agaida added this to Done in Pull Requests Mar 28, 2018
@agaida agaida added this to Archive in PRs Nov 5, 2018
@agaida agaida added this to Old Archive in Pull Requests Mar 24, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
PRs
  
Changelog
Pull Requests
  
Old Archive (fucked up)
Development

Successfully merging this pull request may close these issues.

Crash when loading consecutive images quickly
3 participants