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

Fixing grouping/ungrouping crash #3190

Closed
wants to merge 1 commit into from
Closed

Conversation

strk
Copy link
Contributor

@strk strk commented Jun 9, 2016

@strk strk added Requires Changes! Waiting on the submitter to make requested changes Bugfix labels Jun 9, 2016
@strk strk self-assigned this Jun 9, 2016
@strk strk added For Review and removed Requires Changes! Waiting on the submitter to make requested changes labels Jun 10, 2016
@strk
Copy link
Contributor Author

strk commented Jun 10, 2016

@nyalldawson this is ready for review, could you please take a look ?

The crash was basically due to unclear ownership of the "group" item, the code was deleting it on "ungroup" while it was still referenced by the UndoRedoCommand of the "group item move".

My patch drops the immediate deletion replacing it with an UndoRedoCommand that adds/remove the grouping, with "Remove" command taking ownership of the group.

@strk strk added the Requires Changes! Waiting on the submitter to make requested changes label Jun 10, 2016
@strk
Copy link
Contributor Author

strk commented Jun 10, 2016

Ok it's still not ready as on "delete group item" we're still removing the items contained in the group while we should not be doing that.

@strk
Copy link
Contributor Author

strk commented Jun 10, 2016

Also, "undo grouping" leaves the Scene with unselectable items

@strk
Copy link
Contributor Author

strk commented Jun 10, 2016

Note that the premature deletion of items still results in a crash on exit (double free, I suspect):

#0  0x0000000000000000 in ?? ()
#1  0x00007f7fa1dd0ac0 in QgsAddRemoveItemCommand::~QgsAddRemoveItemCommand (this=0x6768c70, __in_chrg=<optimized out>)
    at /usr/src/qgis/qgis-master/src/core/composer/qgsaddremoveitemcommand.cpp:33
#2  0x00007f7fa1dd0b80 in QgsAddRemoveItemCommand::~QgsAddRemoveItemCommand (this=0x6768c70, __in_chrg=<optimized out>)
    at /usr/src/qgis/qgis-master/src/core/composer/qgsaddremoveitemcommand.cpp:35
#3  0x00007f7fa059246e in QUndoCommand::~QUndoCommand() () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#4  0x00007f7fa1dd0ae2 in QgsAddRemoveItemCommand::~QgsAddRemoveItemCommand (this=0x6633e90, __in_chrg=<optimized out>)
    at /usr/src/qgis/qgis-master/src/core/composer/qgsaddremoveitemcommand.cpp:29
#5  0x00007f7fa1dd0b80 in QgsAddRemoveItemCommand::~QgsAddRemoveItemCommand (this=0x6633e90, __in_chrg=<optimized out>)
    at /usr/src/qgis/qgis-master/src/core/composer/qgsaddremoveitemcommand.cpp:35
#6  0x00007f7fa05926c6 in QUndoStack::clear() () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#7  0x00007f7fa0592817 in QUndoStack::~QUndoStack() () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#8  0x00007f7fa0592849 in QUndoStack::~QUndoStack() () from /usr/lib/x86_64-linux-gnu/libQtGui.so.4
#9  0x00007f7fa1f2fa18 in QgsComposition::~QgsComposition (this=0x63b8000, __in_chrg=<optimized out>)

@strk strk added the Requires Tests! Waiting on the submitter to add unit tests before eligible for merging label Jun 10, 2016
@strk
Copy link
Contributor Author

strk commented Jun 13, 2016

I've tested more and fixed more undo/redo issues. I'd add a few more tests (for position and undostack state) and then cleanup and merge.

@nyalldawson
Copy link
Collaborator

@strk great! will take a look first thing tomorrow

@strk
Copy link
Contributor Author

strk commented Jun 13, 2016

Hopefully for tomorrow I'll be finished with tests and tweaks.
For example, I think the mechanism to decide on having or not ownership of the item, from the AddRemoveItemCommand, is too weak if we also toggle the command state on undo/redo

@strk
Copy link
Contributor Author

strk commented Jun 13, 2016

More tests have been added. Travis still fails due to lack of SIP bindings update (due to the new QgsGroupUngroupItemsCommand class). No test was added to expose the possible memory leak (only theoretical so far)

@strk strk added Requires Tests! Waiting on the submitter to add unit tests before eligible for merging and removed Requires Tests! Waiting on the submitter to add unit tests before eligible for merging labels Jun 13, 2016
@strk
Copy link
Contributor Author

strk commented Jun 13, 2016

Tests for sent signals are also missing (itemAdded/itemRemoved being sent on "undo"/"redo" operations and more) -- @nyalldawson if you want to help there, I won't be on the code before ~10 hours from now

/** Signals removal of an item (the group) */
void itemRemoved( QgsComposerItem* item );

private:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

no need to include private members in sip - they aren't accessible anyway

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

how about signals, are them needed in SIP ?

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, signals should be included

@nyalldawson
Copy link
Collaborator

@strk looks good to me. Honestly the whole ownership of items in composer is a mess, and desperately in need of reworking. In future I'd like to change it so items are always deleted when removed from the scene, and only the xml representation of the composition/items is stored by undo/redo commands.
But this looks like a good approach given the current architecture.

@strk
Copy link
Contributor Author

strk commented Jun 14, 2016

Do you have any hint about testing signals dispatch ? As I'm not sure "itemAdded"/"itemRemoved" are sent correclty on undo/redo, and hadn't seen the current testcase checking for them.

@strk
Copy link
Contributor Author

strk commented Jun 14, 2016

I'll play with QSignalSpy some before merging this.

@nyalldawson
Copy link
Collaborator

Given that it's a c++ test you can use QSignalSpy. See TestQgsAtlasComposition::test_signals() for similar code you could copy.

@strk
Copy link
Contributor Author

strk commented Jun 14, 2016

Ok QSignalSpy testing gave its first fruits already.
It looks like QgsComposer::addItem(QgsComposerPolygon_) on itself does NOT send a composerPolygonAdded(QgsComposerPolygon_) -- should it ?

@strk
Copy link
Contributor Author

strk commented Jun 14, 2016

Also, should grouping/ungrouping send its own signals ?

@strk
Copy link
Contributor Author

strk commented Jun 14, 2016

Another thing cough bu the test: QgsComposition::ungroupItems( group ) -- emits an ItemRemoved signal for each member of the group. Seems to be WRONG to me, as there's eventually a single item removed, assuming the group is considered an item.

Likewise, there is no emission on grouping, which is inconsistent with the emissions on ungrouping.

@strk strk removed Requires Changes! Waiting on the submitter to make requested changes Requires Tests! Waiting on the submitter to add unit tests before eligible for merging labels Jun 14, 2016
@strk
Copy link
Contributor Author

strk commented Jun 14, 2016

There, I think the code is good to ready for merging now.
I can further reduce/squash the commits if you think it's worth it.

If Travis is happy, I'd merge. Or feel free to merge it yourself Nyall, if you have more sun than I will in the next 10 hours :)

@strk
Copy link
Contributor Author

strk commented Jun 16, 2016

squash-rebased for final check

@strk strk added Requires Changes! Waiting on the submitter to make requested changes and removed For Review labels Jun 16, 2016
@strk strk added For Review and removed Requires Changes! Waiting on the submitter to make requested changes labels Jun 16, 2016
@strk
Copy link
Contributor Author

strk commented Jun 17, 2016

Gah, travis fails for unrelated issues: PyQgsWFSProviderGUI

Fixes qgis#11371 (crash on ungrouping after moving the group) and more
undo/redo related issues.

Enable pending test for the crash (now passing) and add many more
undo/redo related ones (including signals testing).

Includes a new QgsGroupUngroupItemsCommand class
and its SIP bindings.
@strk
Copy link
Contributor Author

strk commented Jun 17, 2016

Rebase-pushed as a211c98

@strk strk closed this Jun 17, 2016
@nyalldawson
Copy link
Collaborator

Nice work @strk!

@strk
Copy link
Contributor Author

strk commented Jun 17, 2016

@nyalldawson how do you feel about backporting this to 2.14 ? See #3209

@strk strk deleted the composer-group-undo branch June 17, 2016 14:53
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

Successfully merging this pull request may close these issues.

None yet

2 participants