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

Null pointer on connecting nodes in certain examples #441

Closed
chateauferret opened this issue Sep 19, 2024 · 7 comments
Closed

Null pointer on connecting nodes in certain examples #441

chateauferret opened this issue Sep 19, 2024 · 7 comments

Comments

@chateauferret
Copy link

In some of the examples, e.g. the calculator, there is a crash because of a null ProxyWidget pointer in places like this in NodeGraphicsObject.cpp line 81:

void NodeGraphicsObject::updateQWidgetEmbedPos()
{
_proxyWidget->setPos(nodeScene()->nodeGeometry().widgetPosition(_nodeId));
}

I might try and fix that by simply testing the pointer for NULL before it is dereferenced, but thought it wise to consult you first.

@chateauferret
Copy link
Author

That's on Qt 6.7.2 in Microsoft Windows (and seen on two different computers btw).

@chateauferret
Copy link
Author

OK, so it seems to behave if I just make sure the ProxyWidget pointer isn't NULL before I try to dereference it. There are a few other places where I think this is a risk, because some of the other examples are crashing at similar but different places. So I'll go through and look for them then see if I can put down a pull request.

Root cause seems to be line 91, in the method embedQWidget where _graphModel.nodeData must be returning NULL.

Think we can fix this without too much bother then.

@chateauferret
Copy link
Author

Slightly better, let's suggest this embedQWidget - always assign a value to the pointer.

void NodeGraphicsObject::embedQWidget()
{
    AbstractNodeGeometry &geometry = nodeScene()->nodeGeometry();
    geometry.recomputeSize(_nodeId);
    _proxyWidget = new QGraphicsProxyWidget(this);
    if (auto w = _graphModel.nodeData(_nodeId, NodeRole::Widget).value<QWidget *>()) {
        _proxyWidget->setWidget(w);
        ....

chateauferret added a commit to chateauferret/calenhad_dataflow that referenced this issue Sep 19, 2024
Fixed NULL pointer exception on connecting nodes (paceholder#441)
chateauferret added a commit to chateauferret/calenhad_dataflow that referenced this issue Sep 19, 2024
@Daguerreo
Copy link

Slightly better, let's suggest this embedQWidget - always assign a value to the pointer.

void NodeGraphicsObject::embedQWidget()
{
    AbstractNodeGeometry &geometry = nodeScene()->nodeGeometry();
    geometry.recomputeSize(_nodeId);
    _proxyWidget = new QGraphicsProxyWidget(this);
    if (auto w = _graphModel.nodeData(_nodeId, NodeRole::Widget).value<QWidget *>()) {
        _proxyWidget->setWidget(w);
        ....

If embedQWidget() is called multiple time you continue to allocate a new QGraphicsProxyWidget. It should be included a guard at least to destroy the previous pointer.

@chateauferret
Copy link
Author

chateauferret commented Sep 27, 2024

void NodeGraphicsObject::embedQWidget()
{
    AbstractNodeGeometry &geometry = nodeScene()->nodeGeometry();
    geometry.recomputeSize(_nodeId);
    if (! _proxyWidget) {
        _proxyWidget = new QGraphicsProxyWidget(this);
    }
    if (auto w = _graphModel.nodeData(_nodeId, NodeRole::Widget).value<QWidget *>()) {
        _proxyWidget->setWidget(w);
        ....

chateauferret added a commit to chateauferret/calenhad_dataflow that referenced this issue Sep 27, 2024
When assigning new pointer for _proxyWidget (issue paceholder#441), only do so if the pointer is NULL. Otherwise we repeatedly create new and leave the existing hanging if the method is called multiple times.
@chateauferret
Copy link
Author

Slightly better, let's suggest this embedQWidget - always assign a value to the pointer.

void NodeGraphicsObject::embedQWidget()
{
    AbstractNodeGeometry &geometry = nodeScene()->nodeGeometry();
    geometry.recomputeSize(_nodeId);
    _proxyWidget = new QGraphicsProxyWidget(this);
    if (auto w = _graphModel.nodeData(_nodeId, NodeRole::Widget).value<QWidget *>()) {
        _proxyWidget->setWidget(w);
        ....

If embedQWidget() is called multiple time you continue to allocate a new QGraphicsProxyWidget. It should be included a guard at least to destroy the previous pointer.

Good point. Fixed.

@paceholder
Copy link
Owner

Thanks for addressing it. It's been recently added in 77f3ad1 .
I am not sure if we need to create a proxy wiged for no purpose if there is no user's widget to embed.
Maybe it is enough to check for nullptr in the problematic function NodeGraphicsObject::updateQWidgetEmbedPos()

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

No branches or pull requests

3 participants