-
Notifications
You must be signed in to change notification settings - Fork 490
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
Fix QtDesigner crash in debug mode #847
Conversation
+1 I would prefer it if we could get rid of all asserts. |
52a5907
to
c342461
Compare
@jcfr What do you think about the new CTK_VALIDATE macro that only logs a warning but does not terminate the application on failure? (I've forced push updated code that uses this macro) |
a9e327b
to
d77e1cd
Compare
Done. Renamed macro to CTK_SOFT_ASSERT. |
One last nitpick, i suggest to use the For reference, see https://stackoverflow.com/questions/923822/whats-the-use-of-do-while0-when-we-define-a-macro |
I have never understood why people assume it's okay to ignore these conditions in release mode. I prefer either exceptions or the vtkErrorMacro followed by graceful cleanup approach for anything that really "shouldn't happen". When people use asserts they allow release mode code to silently ignore that the program has gotten into a bad state. If you are going to allow a user to go into a bad state then at least leave a log message. |
Fully agree. Do you think we should log in release mode builds, too? |
it depends ... if we decide "yes", then in the case of this PR, the check in
It basically started to be asserted with the transition to Qt5, it is something we should be fixed/investigated and having the debug version reporting a message is valuable. I looked into it not long ago but got side tracked. |
For our typical use cases I think it's best if debug and release builds behave identically to the extent we can. That makes it easier to replicate user issues and compare log files. |
I fully agree. The "assert" macro and its optimization in release mode doesn't make much sense unless it is in super time-critical loop which UI code probably isn't ;) |
d77e1cd
to
d9dee3a
Compare
Thanks for all the feedbacks. It is good that we all agree on this. I've updated the macro to log warning regardless of build mode and it uses do{}while(0) idiom. |
Libs/Core/ctkUtils.h
Outdated
/// in two key aspectsit only logs a warning (instead of | ||
/// terminating the application) and the message is logged | ||
/// in both release and debug mode builds (instead of ignoring | ||
/// the condition in release mode). |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[...]
/// in two key aspects: (1) it only logs a warning (instead of
/// terminating the application) and (2) the message is logged
/// in both release and debug mode builds (instead of ignoring
/// the condition in release mode).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks, fixed.
Debug-mode Qt Designer crashed when tried to instantiate a ctkMatrixWidget because of an assert failure. It may be useful to know that some operations fail, but making the Qt Designer crash is a too strong way of notifying developers (especially when developers only use CTK and not intend to fix its potential internal errors). Fixed by adding a new CTK_SOFT_ASSERT macro that just logs a warning instead of terminating the application (and does it both in debug and release mode, to make application behavior consistent). It should be possible to use this macro instead of Q_ASSSERT where crashing the application in unexpected situations in debug mode should be avoided.
d9dee3a
to
704d175
Compare
Debug-mode Qt Designer crashed when tried to instantiate a ctkMatrixWidget because of an assert failure.
It may be useful to know that some operations fail, but making the Qt Designer crash is a too strong way of notifying developers (especially when developers only use CTK and not intend to fix its potential internal errors).
Fixed by converting assert to a debug log.
See user problem report here: https://discourse.slicer.org/t/designer-will-not-load-with-slicer-widgets/5496/4