-
Notifications
You must be signed in to change notification settings - Fork 681
fix (WeaselUI): Crash when the Weasel Panel creation is re-entried. #1839
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
base: master
Are you sure you want to change the base?
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||||||||||||||||||||||
|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -83,23 +83,19 @@ VOID CALLBACK UIImpl::OnTimer(_In_ HWND hwnd, | |||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| bool UI::Create(HWND parent) { | ||||||||||||||||||||||||||||||
| if (pimpl_) { | ||||||||||||||||||||||||||||||
| pimpl_->panel.Create( | ||||||||||||||||||||||||||||||
| parent, 0, 0, WS_POPUP, | ||||||||||||||||||||||||||||||
| WS_EX_TOOLWINDOW | WS_EX_TOPMOST | WS_EX_NOACTIVATE | WS_EX_TRANSPARENT, | ||||||||||||||||||||||||||||||
| 0U, 0); | ||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||
| if (!pimpl_) { | ||||||||||||||||||||||||||||||
| pimpl_ = new UIImpl(*this); | ||||||||||||||||||||||||||||||
| if (!pimpl_) | ||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||
| } | ||||||||||||||||||||||||||||||
|
|
||||||||||||||||||||||||||||||
| pimpl_ = new UIImpl(*this); | ||||||||||||||||||||||||||||||
| if (!pimpl_) | ||||||||||||||||||||||||||||||
| return false; | ||||||||||||||||||||||||||||||
| if (pimpl_->panel.IsWindow()) | ||||||||||||||||||||||||||||||
| return true; | ||||||||||||||||||||||||||||||
|
Comment on lines
+92
to
+93
|
||||||||||||||||||||||||||||||
| if (pimpl_->panel.IsWindow()) | |
| return true; | |
| if (pimpl_->panel.IsWindow()) { | |
| HWND current_parent = ::GetParent(pimpl_->panel.m_hWnd); | |
| if (current_parent != parent) { | |
| ::SetLastError(0); | |
| LONG_PTR previous_parent = ::SetWindowLongPtr( | |
| pimpl_->panel.m_hWnd, GWLP_HWNDPARENT, | |
| reinterpret_cast<LONG_PTR>(parent)); | |
| if (previous_parent == 0 && ::GetLastError() != 0) | |
| return false; | |
| } | |
| return true; | |
| } |
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.
new UIImpl(*this)will typically throwstd::bad_allocon failure (or terminate if exceptions are disabled), so the subsequentif (!pimpl_) return false;is ineffective/misleading unless you intentionally usestd::nothrow. Consider either switching tonew (std::nothrow) UIImpl(*this)and keeping the null-check, or removing the null-check and handling allocation failure via exception policy for this project.