plugins-workspace icon indicating copy to clipboard operation
plugins-workspace copied to clipboard

`tauri-window-save-state` causes runtime panic when using `tauri-nspanel`

Open Hacksore opened this issue 1 year ago • 9 comments

So I setup this repro but tl;dr if you leave the window save state plugin enabled this repro will crash when you go to access the NSPanel.

https://github.com/Hacksore/tauri-window-save-state-bug

I've removed everything to be super straight to the issue so follow the readme and you can reproduce.

Unsure of what the issue is but here is the short stacktrace and you can find the full one in the repro.

Finished `dev` profile [unoptimized + debuginfo] target(s) in 9.16s
thread 'main' panicked at /Users/hacksore/.cargo/registry/src/index.crates.io-6f17d22bba15001f/cocoa-0.24.1/src/appkit.rs:1183:9:
Uncaught exception <NSException: 0x6000016f6940>
note: run with `RUST_BACKTRACE=1` environment variable to display a backtrace
libc++abi: terminating due to uncaught foreign exception

This happens in dev and release modes so not sure what's going on. cc @ahkohd (creator of the tauri-nspanel).

related issues: https://github.com/overlayeddev/overlayed/issues/152 https://github.com/Hacksore/tauri-window-save-state-bug/issues/1

Hacksore avatar Jul 14 '24 19:07 Hacksore

Since the NSWindow has been converted to NSPanel, you can no longer call the window.is_maximised or maximise the window anymore.

You can't maximise a panel.

https://github.com/tauri-apps/plugins-workspace/blob/a3fe84296a9a51fed960ab99ee7cebebb7df5390/plugins/window-state/src/lib.rs#L236

this line calls maximise on the window(panel), hence why it crashed.

ahkohd avatar Jul 14 '24 23:07 ahkohd

https://github.com/tauri-apps/plugins-workspace/blob/a3fe84296a9a51fed960ab99ee7cebebb7df5390/plugins/window-state/src/lib.rs#L235

this line needs to be refactored.

such that self.is_maximized is only called if and only if the state flag includes MAXIMIZED

ahkohd avatar Jul 14 '24 23:07 ahkohd

one more thing,

@Hacksore when calling saveWindowState, you will have to exclude MAXIMIZED image

ahkohd avatar Jul 14 '24 23:07 ahkohd

Here is the patch PR: https://github.com/tauri-apps/plugins-workspace/pull/1547

ahkohd avatar Jul 15 '24 00:07 ahkohd

@ahkohd I just pushed this which unblocks the app from crashing immediately on startup. https://github.com/Hacksore/tauri-window-save-state-bug/commit/79ca7f4e2d4fb01af2feb98f0215f296e4e9f634

However, hitting the in app close button will still cause a panic. I thought only selecting flags POSITION and SIZE would work? https://github.com/Hacksore/tauri-window-save-state-bug/blob/79ca7f4e2d4fb01af2feb98f0215f296e4e9f634/src/App.tsx#L12-L13

Hacksore avatar Jul 15 '24 13:07 Hacksore

https://github.com/tauri-apps/plugins-workspace/blob/a3fe84296a9a51fed960ab99ee7cebebb7df5390/plugins/window-state/src/lib.rs#L235

this line needs to be refactored.

such that self.is_maximized is only called if and only if the state flag includes MAXIMIZED

@Hacksore please read this comment.

In the window state plugin, as it is currently, if you set size or maximized flag, window.is_maximised() is called, and this will crash the panel.

This PR (https://github.com/tauri-apps/plugins-workspace/pull/1547) updates the implementation to call window.is_maximised only if maximized is set in the state flags.

ahkohd avatar Jul 15 '24 19:07 ahkohd

Yep, we are blocked here until they can review/merge your open PR.

In the meantime I just forked the repo and made the same you did. https://github.com/overlayeddev/overlayed/commit/f3359fdcf24d5d73b1f4f66f988b4c9b7d0c09e9

Hacksore avatar Jul 15 '24 19:07 Hacksore

https://github.com/tauri-apps/plugins-workspace/blob/a3fe84296a9a51fed960ab99ee7cebebb7df5390/plugins/window-state/src/lib.rs#L235

this line needs to be refactored. such that self.is_maximized is only called if and only if the state flag includes MAXIMIZED

@Hacksore please read this comment.

In the window state plugin, as it is currently, if you set size or maximized flag, window.is_maximised() is called, and this will crash the panel.

This PR (#1547) updates the implementation to call window.is_maximised only if maximized is set in the state flags.

I need to open same PR for the v2 plugin as well.

ahkohd avatar Jul 15 '24 19:07 ahkohd

@ahkohd I saw you closed that PR, was there issues getting it merged upstream?

Hacksore avatar Sep 08 '24 02:09 Hacksore

Seems there were some challenges getting this patched in https://github.com/tauri-apps/plugins-workspace/pull/1568 and instead fixing in tao.

I don't have that PR/issue for it but if it can be linked here that would be great.

Hacksore avatar Aug 14 '25 12:08 Hacksore