Skip to content

Commit d724fdb

Browse files
authored
add note about fields dtor
1 parent 856086f commit d724fdb

File tree

1 file changed

+21
-0
lines changed

1 file changed

+21
-0
lines changed

tutorials/modify.md

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -102,6 +102,27 @@ You still need to call the base destructor itself for calling the original.
102102
103103
**This pattern is the same for constructors.**
104104
105+
### Fields destructor
106+
107+
Modifying destructors the traditional way is highly unreliable and outright broken in some Geode versions. The more recommended and more reliable way is utilizing the Fields struct and adding your destructor logic there.
108+
109+
```cpp
110+
class $modify(CreatorLayer) {
111+
struct Fields {
112+
~Fields {
113+
log::info("CreatorLayer is destructed");
114+
}
115+
}
116+
117+
bool init() {
118+
CreatorLayer::init();
119+
m_fields.self();
120+
}
121+
};
122+
```
123+
124+
Do note that you need to initialize the Fields struct manually at some point during the class's lifespan for this to work. See the [Fields tutorial](/tutorials/fields.md) for more information.
125+
105126
## Using without macros
106127

107128
If you need to refrain from using the `$modify` macro (clang-format really cries when it sees the macro so), here is how you would do it:

0 commit comments

Comments
 (0)