Fix an infinite recursion in Emoji panel/section.

HistoryWidget::resizeEvent() can start taking TabbedSelector from
TabbedPanel which will call QWidget::render() which can call again
HistoryWidget::resizeEvent() from sendPendingMoveAndResizeEvents().

Use a separate flag for _tabbedSection to prevent recursion there.
This commit is contained in:
John Preston 2017-05-01 11:29:02 +03:00
parent aedbd6dfe4
commit 33f59dd3ec
2 changed files with 9 additions and 4 deletions

View File

@ -3699,13 +3699,17 @@ void HistoryWidget::topBarClick() {
void HistoryWidget::updateTabbedSelectorSectionShown() {
auto tabbedSelectorSectionEnabled = AuthSession::Current().data().tabbedSelectorSectionEnabled();
auto shown = tabbedSelectorSectionEnabled && (width() >= minimalWidthForTabbedSelectorSection());
auto shownNow = (_tabbedSection != nullptr);
if (shown == shownNow) {
auto useTabbedSection = tabbedSelectorSectionEnabled && (width() >= minimalWidthForTabbedSelectorSection());
if (_tabbedSectionUsed == useTabbedSection) {
return;
}
_tabbedSectionUsed = useTabbedSection;
if (shown) {
// Use a separate bool flag instead of just (_tabbedSection != nullptr), because
// _tabbedPanel->takeSelector() calls QWidget::render(), which calls
// sendPendingMoveAndResizeEvents() for all widgets in the window, which can lead
// to a new HistoryWidget::resizeEvent() call and an infinite recursion here.
if (_tabbedSectionUsed) {
_tabbedSection.create(this, _controller, _tabbedPanel->takeSelector());
_tabbedSection->setCancelledCallback([this] { setInnerFocus(); });
_rightShadow.create(this, st::shadowFg);

View File

@ -790,6 +790,7 @@ private:
object_ptr<ChatHelpers::TabbedPanel> _tabbedPanel;
object_ptr<ChatHelpers::TabbedSection> _tabbedSection = { nullptr };
QPointer<ChatHelpers::TabbedSelector> _tabbedSelector;
bool _tabbedSectionUsed = false;
DragState _attachDrag = DragStateNone;
object_ptr<DragArea> _attachDragDocument, _attachDragPhoto;