Skip to content

Conversation

@workbysaran
Copy link
Contributor

@workbysaran workbysaran commented Nov 21, 2025

Resolved / Related Issues
Fixed a crash (DivideByZeroException) that occurred when resizing the window with multiple panes split vertically.

Closes #17739

Steps used to test these changes

  1. Open Files with dual pane (vertical split)
  2. Resize the window to smaller sizes
  3. Resize window back to larger size and verify right pane restores with correct folder
  4. Test multiple resize cycles and layouts to ensure stability

@yaira2 yaira2 added the changes requested Changes are needed for this pull request label Nov 23, 2025
@yaira2
Copy link
Member

yaira2 commented Nov 23, 2025

Thank you for the PR. Can you please provide some details on why you went with this approach? Ideally the minimum size wouldn't have to change, and we would instead fix the underlying cause.

@workbysaran
Copy link
Contributor Author

@yaira2
The application was crashing with a System.DivideByZeroException in Microsoft's WinUI framework when the window was resized too small with multiple panes displayed vertically. The crash occurs in WinUI's internal layout engine(FrameworkElement.MeasureOverride) when the available window space becomes insufficient to handle the grid's minimum height and width constraints.

In fact, the same issue happens even when using a single pane but the crash threshold is much lower (nearly 0px) compared to the original default size set by the code (316×416). With dual panes, the crash occurs around 700-850px width. So setting MinWidth = 850 and MinHeight = 646 on the main window itself prevents users from resizing below the threshold before WinUI's layout engine runs, avoiding the crash condition entirely.

If you don't want to set the size explicitly, we need to spend more time on research to find out why the internal Microsoft component fails, find out if there is a way to handle the validation ourselves, and confirm whether it's a Microsoft bug and report it accordingly.

Furthermore, we can enhance my previous fix to set the minimum size dynamically based on whether multiple panes are enabled.

Please let me know how you’d like to proceed.

@workbysaran
Copy link
Contributor Author

With further investigation, the DivideByZeroException occurs because the restored pane has no navigation parameters, leaving it uninitialized. When WinUI's layout engine attempts to measure and arrange the empty pane, it encounters invalid state, which can lead to a division-by-zero error during its dimension calculations.

I fixed the issue by saving the navigation parameters and restoring them when the pane is shown again.

@yaira2 yaira2 changed the title Fix: Increased minimum window size to prevent crash when resizing wit… Fix: Fixed crash that would sometimes occur when resizing the window Dec 8, 2025
@yaira2
Copy link
Member

yaira2 commented Dec 8, 2025

@workbysaran I don't recall the original behavior (maybe @winston-de or @gave92 remembers) but the other option is to use 'home' when adding back the second pane. Does anyone have a preference?

@yaira2 yaira2 added ready to merge Pull requests that are approved and ready to merge and removed changes requested Changes are needed for this pull request labels Dec 8, 2025
Copy link
Member

@yaira2 yaira2 left a comment

Choose a reason for hiding this comment

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

LGTM

@yaira2 yaira2 requested a review from 0x5bfa December 10, 2025 00:37
@yaira2 yaira2 merged commit 6cca0bb into files-community:main Dec 10, 2025
6 checks passed
yaira2 added a commit to Anoop-2024si96509/Files that referenced this pull request Jan 6, 2026
commit 13385cb
Author: Anoop-2024si96509 <2024si96509@wilp.bits-pilani.ac.in>
Date:   Tue Jan 6 00:36:45 2026 +0530

    Fix: Fixed an issue where file types displayed differently for hidden items (files-community#18018)

commit 124e1fc
Author: Saravanan G <workbysaran@gmail.com>
Date:   Mon Jan 5 21:29:05 2026 +0530

    Fix: Fixed an issue where search didn't work for tags with spaces in their name (files-community#18020)

commit c1484c2
Author: Steve <hez2010@outlook.com>
Date:   Mon Jan 5 00:54:06 2026 +0900

    Code Quality: Cleanup warnings (files-community#18011)

    Signed-off-by: Steve <hez2010@outlook.com>
    Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
    Co-authored-by: Copilot <198982749+Copilot@users.noreply.github.com>

commit 528be10
Author: Saravanan G <workbysaran@gmail.com>
Date:   Thu Jan 1 01:49:38 2026 +0530

    Fix: Prevent "Failed to enqueue the operation" exception during shutdown (files-community#18006)

commit babc715
Author: 0x5BFA <62196528+0x5bfa@users.noreply.github.com>
Date:   Mon Dec 29 07:27:11 2025 +0900

    Code Quality: Suppress exceptions that can occur in SidebarView drag/drop event handlers (files-community#17996)

commit 01ddde9
Author: Yair <39923744+yaira2@users.noreply.github.com>
Date:   Thu Dec 25 16:38:12 2025 -0500

    Build: v4.0.24

commit 3ad75f1
Author: Yair <39923744+yaira2@users.noreply.github.com>
Date:   Thu Dec 25 16:37:34 2025 -0500

    Code Quality: Updated translations (files-community#17997)

commit e21ef88
Author: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
Date:   Tue Dec 23 19:46:54 2025 -0500

    Fix: Added null checks for ShellViewModel in navigation helpers (files-community#17963)

    Signed-off-by: Yair <39923744+yaira2@users.noreply.github.com>
    Co-authored-by: seer-by-sentry[bot] <157164994+seer-by-sentry[bot]@users.noreply.github.com>
    Co-authored-by: Yair <39923744+yaira2@users.noreply.github.com>
    Co-authored-by: hishitetsu <66369541+hishitetsu@users.noreply.github.com>

commit 25bdcd1
Author: Yair <39923744+yaira2@users.noreply.github.com>
Date:   Mon Dec 22 18:32:10 2025 -0500

    Build: v4.0.23

commit 6721e58
Author: Yair <39923744+yaira2@users.noreply.github.com>
Date:   Mon Dec 22 18:27:25 2025 -0500

    Code Quality: Updated translations (files-community#17986)

commit 0c21660
Author: Yair <39923744+yaira2@users.noreply.github.com>
Date:   Mon Dec 22 17:47:00 2025 -0500

    Feature: Added text wrapping to Status Center (files-community#17985)

commit 9afe596
Author: 0x5BFA <62196528+0x5bfa@users.noreply.github.com>
Date:   Tue Dec 23 01:43:23 2025 +0900

    Code Quality: Removed ISidebarViewModel (files-community#17972)

commit 347c35d
Author: 0x5BFA <62196528+0x5bfa@users.noreply.github.com>
Date:   Sun Dec 21 08:40:37 2025 +0900

    GitHub: Removed the extra link space between the download badges (files-community#17975)

commit bb05ce1
Author: Saravanan G <workbysaran@gmail.com>
Date:   Fri Dec 19 20:53:32 2025 +0530

    Feature: Added Copy functionality to sidebar and home page widgets (files-community#17969)

commit 472347c
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Thu Dec 18 10:45:37 2025 -0500

    Bump Microsoft.WindowsAppSDK from 1.8.250907003 to 1.8.251106002 (files-community#17974)

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit 81aa50c
Author: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>
Date:   Thu Dec 18 10:45:27 2025 -0500

    Bump Microsoft.Windows.SDK.BuildTools from 10.0.26100.4948 to 10.0.26100.7175 (files-community#17973)

    Signed-off-by: dependabot[bot] <support@github.com>
    Co-authored-by: dependabot[bot] <49699333+dependabot[bot]@users.noreply.github.com>

commit e49e479
Author: 0x5BFA <62196528+0x5bfa@users.noreply.github.com>
Date:   Thu Dec 18 02:55:24 2025 +0900

    Feature: Added theme shadow to Omnibar flyout (files-community#17971)

commit 1d66171
Author: Marlen Halvorsen <marlenhalvorsen@gmail.com>
Date:   Wed Dec 17 00:53:29 2025 +0100

    Feature: Added default name when creating new files (files-community#17942)

    Co-authored-by: Yair <39923744+yaira2@users.noreply.github.com>

commit 014d34d
Author: Saravanan G <workbysaran@gmail.com>
Date:   Tue Dec 16 21:01:41 2025 +0530

    Code Quality: Additional logs to troubleshoot crashes (files-community#17955)

commit f56c965
Author: Yair <39923744+yaira2@users.noreply.github.com>
Date:   Mon Dec 15 12:18:46 2025 -0500

    Code Quality: Change provider detection order in PreviewPopupService

    Moved PowerToysPeekProvider availability check after QuickLookProvider and SeerProProvider in GetProviderAsync. This alters the priority in which preview providers are selected.

commit 929c304
Author: Yair <39923744+yaira2@users.noreply.github.com>
Date:   Sun Dec 14 10:19:27 2025 -0500

    Build: v4.0.22

    Signed-off-by: Yair <39923744+yaira2@users.noreply.github.com>

commit 7def439
Author: Yair <39923744+yaira2@users.noreply.github.com>
Date:   Wed Dec 10 18:19:38 2025 -0500

    Feature: Added support for PowerToys Peek (files-community#17954)

commit 6cca0bb
Author: Saravanan G <workbysaran@gmail.com>
Date:   Wed Dec 10 21:17:46 2025 +0530

    Fix: Fixed crash that would sometimes occur when resizing the window (files-community#17893)

commit e7eaf16
Author: Barton Milnor Mallory <erhebend@protonmail.com>
Date:   Tue Dec 9 18:24:54 2025 -0600

    Code Quality: Fixed typos in code comments (files-community#17945)

commit ddeb2ff
Author: Saravanan G <workbysaran@gmail.com>
Date:   Thu Dec 4 00:53:07 2025 +0530

    Fix: Fixed crash when switching git branches during merge conflict (files-community#17894)

    Signed-off-by: Saravanan G <workbysaran@gmail.com>
    Co-authored-by: Yair <39923744+yaira2@users.noreply.github.com>

commit 4abd5f2
Author: Kalmix <87293493+kalmix@users.noreply.github.com>
Date:   Wed Dec 3 11:34:58 2025 -0400

    Fix: Fixed PNG-based .ico files rendering with black backgrounds (files-community#17924)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

ready to merge Pull requests that are approved and ready to merge

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Resizing window in Dual Pane mode causes crash

2 participants