Skip to content

Avoid crashing when clicking reload#2283

Merged
klayoutmatthias merged 1 commit intoKLayout:masterfrom
abdelq:crash-on-reload
Apr 6, 2026
Merged

Avoid crashing when clicking reload#2283
klayoutmatthias merged 1 commit intoKLayout:masterfrom
abdelq:crash-on-reload

Conversation

@abdelq
Copy link
Copy Markdown
Contributor

@abdelq abdelq commented Feb 24, 2026

For context, this was happening to me on macOS with files being written to a temporary directory and no longer existing there. I would attempt to reload with the notification and KLayout would crash instead of giving an error message.

@klayoutmatthias
Copy link
Copy Markdown
Collaborator

Hi @abdelq,

thanks for the PR, but I think it's not the right place to catch exceptions. "reload layout" is part of the script API and it should really throw an exception in case of an error.

I tried to reproduce the problem on Linux, and there is no crash as the exception is caught higher up in the call stack - namely in lay::GuiApplication::do_notify:

image

So there is a no systematic issue. When you see a crash on MacOS it's likely because there may be an ABI incompatibility between the Qt shared objects and the application code and that prevents throwing exceptions over Qt library boundaries. I had such cases, when the Qt library is built with a different compiler than the application.

This is a general issue and will cause problems in many other places.

If the is absolutely no other solution, you can basically put the BEGIN_PROTECTED ... END_PROTECTED bracket into lay::LayoutViewNotificationWidget::action_triggered (once is enough), but I think this will only solve one problem out of many.

Matthias

@abdelq abdelq marked this pull request as draft February 27, 2026 22:39
@abdelq abdelq force-pushed the crash-on-reload branch from e3e9db4 to 177d167 Compare April 5, 2026 22:55
@abdelq abdelq force-pushed the crash-on-reload branch from 177d167 to ec4485a Compare April 5, 2026 22:57
@abdelq
Copy link
Copy Markdown
Contributor Author

abdelq commented Apr 5, 2026

Hello Matthias,

I should've uploaded the crash log in the original description: klayout_crash.log

I had such cases, when the Qt library is built with a different compiler than the application.

I have an unusual setup, in that, I'm using a Nix-packaged version of KLayout on macOS.
In principle, both the application and the library were compiled with the same standard environment (same Clang, etc.). I've done a quick look with otool and Nix-related commands and it seems to be the case.

It's more likely that it's a case of exceptions escaping a Qt-managed callback on macOS.

I haven't touched Qt code in a long time, but I've looked at the docs and they do claim that: "Throwing an exception from a slot invoked by Qt's signal-slot connection mechanism is considered undefined behaviour"

I've changed the approach to use END_PROTECTED_W instead and added another similar block in MacroEditorNotificationWidget::action_triggered as it's likely to lead to the same issue.

I wish I could dig deeper, but the macOS machine is a work one.

@abdelq abdelq marked this pull request as ready for review April 5, 2026 23:20
@klayoutmatthias
Copy link
Copy Markdown
Collaborator

The reason why signal/slot exceptions are undefined is that Qt offers to move signals between threads or delay execution. Both cases don't handle exceptions, that's why. Single-threaded direct signal/slot calls just get routed over C++ code generated by MOC and unless they have changed that significantly in Qt 6.11, I can't see why that should lead to lost exceptions.

The change you propose is okay and I will merge it, but I still think the reason sits deeper. So I'd expect that you see more crashes in other cases not related to signals and slots.

Matthias

@klayoutmatthias klayoutmatthias merged commit b1e49f6 into KLayout:master Apr 6, 2026
20 checks passed
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