Skip to content

Commit c2352d3

Browse files
committed
Cleanup
1 parent 727365c commit c2352d3

4 files changed

Lines changed: 25 additions & 1 deletion

File tree

changelog.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# 1.2.4
2+
- Cleanup on close
3+
14
# 1.2.3
25
- Made a mistake oops, fixed
36

include/ModifyHandler.hpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ namespace alpha::utils {
2929
ObjectData* getObjectData(uint32_t id);
3030
void createObjectData(cocos2d::CCObject* object);
3131
void handleObject(cocos2d::CCObject* object);
32+
void cleanup();
3233

3334
template <class Base>
3435
inline bool containsBase(const cocos2d::CCObject* obj) {

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@
88
},
99
"id": "alphalaneous.alphas_geode_utils",
1010
"name": "Alpha's Geode Utils",
11-
"version": "v1.2.3",
11+
"version": "v1.2.4",
1212
"developer": "Alphalaneous",
1313
"description": "Miscellaneous utilities for Geode Modding",
1414
"api": {

src/ModifyHandler.cpp

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -47,12 +47,16 @@ ZStringView getObjectNameOptimized(const cocos2d::CCObject* obj) {
4747
#endif
4848
}
4949

50+
bool g_closing = false;
51+
5052
ModifyHandler* ModifyHandler::get() {
5153
static ModifyHandler handler;
5254
return &handler;
5355
}
5456

5557
uint32_t ModifyHandler::allocateObjectData(ObjectData* data) {
58+
if (g_closing) return 0;
59+
5660
if (!m_slots.empty()) {
5761
auto id = m_slots.front();
5862
m_slots.pop();
@@ -65,20 +69,25 @@ uint32_t ModifyHandler::allocateObjectData(ObjectData* data) {
6569
}
6670

6771
void ModifyHandler::releaseObjectData(uint32_t id) {
72+
if (g_closing) return;
73+
6874
if (id < m_arena.size() && m_arena[id]) {
6975
m_arena[id] = nullptr;
7076
m_slots.push(id);
7177
}
7278
}
7379

7480
ObjectData* ModifyHandler::getObjectData(uint32_t id) {
81+
if (g_closing) return nullptr;
82+
7583
if (id < m_arena.size()) {
7684
return m_arena[id];
7785
}
7886
return nullptr;
7987
}
8088

8189
void ModifyHandler::createObjectData(CCObject* object) {
90+
if (g_closing) return;
8291
if (object->m_nLuaID != 0) return;
8392

8493
ObjectData* data = new ObjectData();
@@ -87,6 +96,8 @@ void ModifyHandler::createObjectData(CCObject* object) {
8796
}
8897

8998
void ModifyHandler::handleObject(CCObject* object) {
99+
if (g_closing) return;
100+
90101
createObjectData(object);
91102
auto& objectsToModify = ObjectModify::get()->getObjectsToModify();
92103
auto it = objectsToModify.find(getObjectNameOptimized(object));
@@ -102,4 +113,13 @@ void ModifyHandler::handleObject(CCObject* object) {
102113
pair.method(static_cast<ModifyCCObject<CCObject>*>(object));
103114
}
104115
}
116+
}
117+
118+
void ModifyHandler::cleanup() {
119+
g_closing = true;
120+
m_arena.clear();
121+
}
122+
123+
$on_game(Exiting) {
124+
ModifyHandler::get()->cleanup();
105125
}

0 commit comments

Comments
 (0)