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

Crash on add a previously removed dock widget #212

Closed
IkkiNit opened this issue Jun 29, 2020 · 7 comments
Closed

Crash on add a previously removed dock widget #212

IkkiNit opened this issue Jun 29, 2020 · 7 comments
Assignees

Comments

@IkkiNit
Copy link

IkkiNit commented Jun 29, 2020

When we remove a dock widget:
dockManager1->removeDockWidget(dockWidget);
and then add it to another manager:
dockManager2->addDockWidget(ads::RightDockWidgetArea, dockWidget);
A crash appends.

After searching for the problem, it seems in
CDockAreaWidget* CDockContainerWidget::addDockWidget(DockWidgetArea area, CDockWidget* Dockwidget, CDockAreaWidget* DockAreaWidget) at this line
CDockAreaWidget* OldDockArea = Dockwidget->dockAreaWidget(); -> OldDockArea is still valid.

There is still a link to an old area from the dock widget but this area has been delete previously during the remove from the first dock manager.

@githubuser0xFFFF
Copy link
Owner

Fixed this in branch issue212. Please checkout the branch and test.

@IkkiNit
Copy link
Author

IkkiNit commented Jun 30, 2020

Hello !
It seems the fix is not enough but is better.
Now the crash I have is when the dock widget is removed from the manager with this line dockManager1->removeDockWidget(dockWidget);
Just after that the dock widget always gives the pointer to the old manager when I ask ads::CDockManager* manager = dockWidget->dockManager();
I think it should be reset as well as the area.
Thank you !

@githubuser0xFFFF
Copy link
Owner

Done. Please test.

@IkkiNit
Copy link
Author

IkkiNit commented Jun 30, 2020

Sorry again but I have still a crash, this time it's on void CDockAreaWidget::insertDockWidget(int index, CDockWidget* DockWidget, bool Activate)

I don't what is the problem exactly, I have this callstack:

qtadvanceddocking.dll!ads::CDockAreaWidget::insertDockWidget(int index, ads::CDockWidget * DockWidget, bool Activate) Line 429 C++
qtadvanceddocking.dll!ads::DockContainerWidgetPrivate::addDockWidgetToContainer(ads::DockWidgetArea area, ads::CDockWidget * Dockwidget) Line 1039 C++
qtadvanceddocking.dll!ads::CDockContainerWidget::addDockWidget(ads::DockWidgetArea area, ads::CDockWidget * Dockwidget, ads::CDockAreaWidget * DockAreaWidget) Line 1251 C++

I just test it in the sample example with this:

MainWindow::MainWindow(QWidget *parent) :
    QMainWindow(parent),
    ui(new Ui::MainWindow)
{
    ui->setupUi(this);

    // Create the dock manager. Because the parent parameter is a QMainWindow
    // the dock manager registers itself as the central widget.
	m_DockManager1 = new ads::CDockManager(this);

	// Create example content label - this can be any application specific
	// widget
	QLabel* l = new QLabel();
	l->setWordWrap(true);
	l->setAlignment(Qt::AlignTop | Qt::AlignLeft);
	l->setText("Lorem ipsum dolor sit amet, consectetuer adipiscing elit. ");

	// Create a dock widget with the title Label 1 and set the created label
	// as the dock widget content
	ads::CDockWidget* DockWidget = new ads::CDockWidget("Label 1");
	DockWidget->setWidget(l);

	// Add the toggleViewAction of the dock widget to the menu to give
	// the user the possibility to show the dock widget if it has been closed
	ui->menuView->addAction(DockWidget->toggleViewAction());

	// Add the dock widget to the top dock widget area
	m_DockManager1->addDockWidget(ads::TopDockWidgetArea, DockWidget);


	auto funcRemoveFirstManager = [=]()
	{
		m_DockManager1->removeDockWidget(DockWidget);

		delete m_DockManager1;
		m_DockManager1 = nullptr;
	};
	QTimer::singleShot(3000, funcRemoveFirstManager);

	auto funcAddSecondManager = [=]()
	{
		m_DockManager2 = new ads::CDockManager(this);

		m_DockManager2->addDockWidget(ads::TopDockWidgetArea, DockWidget);
	};
	QTimer::singleShot(5000, funcAddSecondManager);
}

@githubuser0xFFFF
Copy link
Owner

Fixed. Please test.

@IkkiNit
Copy link
Author

IkkiNit commented Jun 30, 2020

Ok that's good to me ;)

Thank you a lot !

@githubuser0xFFFF
Copy link
Owner

Merged into master.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants