Skip to content

Commit 0f672e9

Browse files
committed
Add common errors
1 parent d97f028 commit 0f672e9

File tree

5 files changed

+65
-27
lines changed

5 files changed

+65
-27
lines changed

astro.config.mjs

+1-1
Original file line numberDiff line numberDiff line change
@@ -34,7 +34,7 @@ export default defineConfig({
3434
},
3535
{
3636
label: "Common Errors",
37-
items: ["errors/errors"],
37+
autogenerate: { directory: 'errors' },
3838
},
3939
],
4040
}),
+27
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,27 @@
1+
---
2+
title: Gd<T>::bind_mut() failed, already bound
3+
description: Gd<T>::bind_mut() failed, already bound
4+
---
5+
6+
## Reason
7+
This error typically occurs when you attempt to get a mutable borrow (`bind_mut()`) of a Godot object that is already borrowed (either immutably or mutably). A common scenario is calling `self.to_gd().bind_mut()`.
8+
9+
## Solutions
10+
11+
Choose one of the following solutions:
12+
13+
1. **(Recommended)** Avoid `self.to_gd().bind_mut()`. Instead, use `self.base_mut().some_base_method()` to call methods on the base class mutably.
14+
15+
2. **Change Function Signature:** If you are passing the object to another function, consider passing a mutable reference to your _struct type_ (`&mut MyClass`) instead of `Gd<MyClass>`, if feasible. This allows direct field access in the receiving function without needing `bind_mut`.
16+
17+
3. **Use `base_mut()` Guard Carefully:**
18+
19+
```rust
20+
fn custom_method(&mut self) { 
21+
let gd = self.to_gd(); 
22+
// guard
23+
let _guard = self.base_mut(); 
24+
// now it's safe to call bind
25+
gd.bind()
26+
}
27+
```
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,17 @@
1+
---
2+
title: Cannot find attribute `signal` in this scope
3+
description: Cannot find attribute `signal` in this scope
4+
---
5+
6+
## Solutions:
7+
8+
1. Declare the `signal` in the class impl block.
9+
2. Add `#[godot_api]` on the impl block that contains the signal.
10+
11+
```rust
12+
#[godot_api]
13+
impl MyClass {
14+
#[signal]
15+
fn custom_signal();
16+
}
17+
```

src/content/docs/errors/errors.md

-26
This file was deleted.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
---
2+
title: The trait bound `...ToGodot` is not satisfied
3+
description: The trait bound `YourClass:godot::prelude::ToGodot` is not satisfied.
4+
---
5+
6+
## Error
7+
8+
The trait bound `YourClass:godot::prelude::ToGodot` is not satisfied.
9+
10+
## Reason
11+
12+
you need to define how to pass it around in godot(e.g. `function with #[func]`).
13+
Otherwise godot have no idea how to reference your Class in functions that talk about it.
14+
15+
## Solutions
16+
17+
Choose one of the following solutions:
18+
19+
1. (Recommend) Change `YourClass` to `Gd<YourClass>`.
20+
2. Implementing `GodotConvert`, `ToGodot`, and `FromGodot` to use some other type as an intermediate.

0 commit comments

Comments
 (0)