Skip to content

Postpone error message display if not in GUI thread#753

Merged
dirkhh merged 1 commit intosubsurface:masterfrom
bstoeger:thread2
Oct 31, 2017
Merged

Postpone error message display if not in GUI thread#753
dirkhh merged 1 commit intosubsurface:masterfrom
bstoeger:thread2

Conversation

@bstoeger
Copy link
Copy Markdown
Collaborator

Calls to report_error() crashed if not called from GUI thread.
Fix this by postponing error message display if not in GUI thread.
Code that creates a thread which possibly calls report_error()
is responsible for calling MainWindow::showErrors() to flush
the accumulated messages.

Note that there is a race condition in report_error() and
get_error_string(). Nevertheless, hitting it should be rather
unlikely (two threads producing error messages at the same time)
and hopefully it can be fixed rather easily.

Signed-off-by: Berthold Stoeger bstoeger@mail.tuwien.ac.at

Describe the pull request:

  • Bug fix
  • Functional change
  • New feature
  • Documentation change
  • Language translation

Pull request long description:

Changes made:

Related issues:

Additional information:

Mentions:

Copy link
Copy Markdown
Member

@neolit123 neolit123 left a comment

Choose a reason for hiding this comment

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

thanks for this,
the patch looks good to me, but i haven't tested it.

a small coding style request bellow.

// If we're not in the GUI thread, let errors accumulate.
if (QThread::currentThread() != QCoreApplication::instance()->thread()) {
return;
}
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

can you please remove all braces { } if the if statement wraps a single line.
becomes:

if (QThread::currentThread() != QCoreApplication::instance()->thread())
    return;

applies to the rest of the patch too.

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

NOTE: i know that we have this in a lot of places, but the idea is to keep future if additions consistent.

Calls to report_error() crashed if not called from GUI thread.
Fix this by postponing error message display if not in GUI thread.
Code that creates a thread which possibly calls report_error()
is responsible for calling MainWindow::showErrors() to flush
the accumulated messages.

Note that there is a race condition in report_error() and
get_error_string(). Nevertheless, hitting it should be rather
unlikely (two threads producing error messages at the same time)
and hopefully it can be fixed rather easily.

Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
@bstoeger
Copy link
Copy Markdown
Collaborator Author

Done - still works with my (simple) test case.

@neolit123
Copy link
Copy Markdown
Member

thanks - LGTM.
waiting on @dirkhh for the final weight in.

@dirkhh
Copy link
Copy Markdown
Collaborator

dirkhh commented Oct 31, 2017

This is simple and hopefully deal with the biggest problem in my code.
Thanks

@dirkhh dirkhh merged commit 3acc28c into subsurface:master Oct 31, 2017
@bstoeger bstoeger deleted the thread2 branch November 1, 2017 07:51
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants