File tree 1 file changed +17
-5
lines changed
1 file changed +17
-5
lines changed Original file line number Diff line number Diff line change @@ -156,11 +156,23 @@ impl BindingStorage {
156
156
"Godot engine not available; make sure you are not calling it from unit/doc tests" ,
157
157
) ;
158
158
159
- assert_eq ! (
160
- main_thread_id,
161
- std:: thread:: current( ) . id( ) ,
162
- "attempted to access binding from different thread than main thread; this is UB - use the \" experimental-threads\" feature."
163
- ) ;
159
+ if main_thread_id != std:: thread:: current ( ) . id ( ) {
160
+ // If a binding is accessed the first time, this will panic and start unwinding. It can then happen that during unwinding,
161
+ // another FFI call happens (e.g. Godot destructor), which would cause immediate abort, swallowing the error message.
162
+ // Thus check if a panic is already in progress.
163
+
164
+ if std:: thread:: panicking ( ) {
165
+ eprintln ! (
166
+ "ERROR: Attempted to access binding from different thread than main thread; this is UB.\n \
167
+ Cannot panic because panic unwind is already in progress. Please check surrounding messages to fix the bug."
168
+ ) ;
169
+ } else {
170
+ panic ! (
171
+ "attempted to access binding from different thread than main thread; \
172
+ this is UB - use the \" experimental-threads\" feature."
173
+ )
174
+ } ;
175
+ }
164
176
}
165
177
166
178
// SAFETY: This function can only be called when the binding is initialized and from the main thread, so we know that it's initialized.
You can’t perform that action at this time.
0 commit comments