Skip to content

Prevent napari crash when checking orientation on large datasets#272

Open
Prathiba-G wants to merge 3 commits into
brainglobe:mainfrom
Prathiba-G:fix-check-orientation-large-datasets
Open

Prevent napari crash when checking orientation on large datasets#272
Prathiba-G wants to merge 3 commits into
brainglobe:mainfrom
Prathiba-G:fix-check-orientation-large-datasets

Conversation

@Prathiba-G

Copy link
Copy Markdown

What does this PR do?

Adds a safeguard to prevent napari from crashing when the "Check orientation" feature is used on large datasets.

Changes made

  • Added dataset size check before rendering
  • Introduced Qt warning dialog for large datasets
  • Allows user to cancel operation safely

Why is this needed?

Large datasets can exceed memory limits when rendered in 3D, causing napari to crash.

Testing

  • Small datasets work as expected
  • Large datasets trigger warning dialog and do not crash

Prathiba-G and others added 3 commits March 31, 2026 18:39
Prevents napari crashes when rendering projections of 3D volumes >500M voxels or >2GB memory.
Shows Qt warning dialog; cancels if user selects No.

Closes #issue-number (if applicable)

@alessandrofelder alessandrofelder left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

We appreciate you contributing @Prathiba-G and apologies for taking so long to get back to you.

I can see your thinking here, and the implementation is reasonable.
I made some suggestions for improvements.

num_voxels = np.prod(data.shape)
bytes_per_voxel = data.dtype.itemsize
estimated_gb = num_voxels * bytes_per_voxel / 1e9
if num_voxels > 500_000_000 or estimated_gb > 2.0:

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

What was your thinking behind these numbers? Maybe we need just the estimated_gb? Either way, we should have a comment explaining the reasoning to developers reading this code.

msg = QMessageBox()
msg.setIcon(QMessageBox.Warning)
msg.setText(
"This dataset is very large and may cause napari to crash when rendered in 3D."

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

The error message should contain info about the estimated size of the dataset, to make it less vague.

bytes_per_voxel = data.dtype.itemsize
estimated_gb = num_voxels * bytes_per_voxel / 1e9
if num_voxels > 500_000_000 or estimated_gb > 2.0:
msg = QMessageBox()

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

could this use display_warning from https://github.com/neuroinformatics-unit/qt-niu/blob/main/qt_niu/dialog.py for maintainability and consistent look-and-feel?

We would need to add qt-niu as a dependency.

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.

2 participants