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

Fixes crash due to accessing selection after graph_scene is deleted #218 #230

Closed

Conversation

valleyofblackpanther
Copy link
Contributor

Summary

The MainWindow class is where I integrated the cleanup routine for the GraphScene. MainWindow has already a closeEvent method. This is where we call the shutdown method of each GraphScene instance before the application closes. However, the GraphScene instances are not directly managed by MainWindow but rather by the panels like GraphEditPanel, ProofPanel, and RulePanel which are derived from BasePanel. Each of these panels contains an instance of GraphScene.

Here's the cleanup implementation:

  1. Add a cleanup method in the BasePanel class.
  2. Call this cleanup method for each panel in the MainWindow's closeEvent.

Firslty, I added a shutdown method to the GraphScene class. Then, added a corresponding method in the BasePanel class that calls GraphScene.shutdown()
Next, I ensured each panel subclassing BasePanel class provides its own shutdown method.
Finally, I modified the closeEvent of the MainWindow class to shutdown on each panel before closing.

This method ensures that each GraphScene is properly cleaned up before the main window closes.

Copy link
Collaborator

@RazinShaikh RazinShaikh left a comment

Choose a reason for hiding this comment

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

Hi Kaushik, thank you for the PR. Could you please make the requested changes before we can merge this?

@@ -106,3 +106,7 @@ def _input_circuit(self) -> None:
cmd = UpdateGraph(self.graph_view, new_g)
self.undo_stack.push(cmd)
self.graph_scene.select_vertices(new_verts)

def shutdown(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need this method here in edit_panel if it is already implemented in base_panel?

@@ -421,6 +421,10 @@ def _refresh_rewrites_model(self) -> None:
# TODO: Right now this calls for every single vertex selected, even if we select many at the same time
self.graph_scene.selectionChanged.connect(model.update_on_selection)

def shutdown(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need this method here in proof_panel if it is already implemented in base_panel?

@@ -80,3 +80,7 @@ def get_rule(self) -> CustomRule:
self.graph_scene_right.g,
self.name_field.text(),
self.description_field.text())

def shutdown(self):
Copy link
Collaborator

Choose a reason for hiding this comment

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

Why do you need this method here in rule_panel if it is already implemented in base_panel?


#Clear all items from the scene to ensure no dangling references remain
self.clear()

Copy link
Collaborator

Choose a reason for hiding this comment

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

Do you mind cleaning up some extra empty lines in this function?

zxlive/dialogs.py Outdated Show resolved Hide resolved
@valleyofblackpanther
Copy link
Contributor Author

Hi, @RazinShaikh I have made the suggested changes, here is the commit.

@dlyongemallo
Copy link
Contributor

I wonder if it wouldn't be simpler and more future-proof to simply clear the node selection when the user asks to close the app?

@RazinShaikh
Copy link
Collaborator

@dlyongemallo that actually makes more sense

@@ -223,6 +223,12 @@ def active_panel(self) -> Optional[BasePanel]:


def closeEvent(self, e: QCloseEvent) -> None:
#Call shutdown on all tabs before closing
Copy link
Contributor

Choose a reason for hiding this comment

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

I think you may be overthinking this. I think all that is needed to fix the issue is to add a single line in close_tab (just above line 329 self.tab_widget.removeTab(i)), like:
widget.graph_scene.clearSelection()

Please try to see if that works.

@dlyongemallo
Copy link
Contributor

Hi Kaushik, thank you for the PR. Could you please make the requested changes before we can merge this?

Thanks for the PR, Kaushik. Can you make the suggested change and add a test to confirm it works? I think that should suffice.

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.

3 participants