Skip to content

Commit 26cf084

Browse files
committed
Bug fix, late modify
1 parent 8e6d88f commit 26cf084

File tree

4 files changed

+56
-8
lines changed

4 files changed

+56
-8
lines changed

changelog.md

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 2.0.1
2+
- Fix a crash when a texture name was too short
3+
- Update UI at end of frame rather than start
4+
15
## 2.0.0
26
**NOTICE! Modifying nodes by ID is removed. You must now modify them by their class name instead.**
37
- Code cleanup

mod.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
"mac": "2.2074",
77
"ios": "2.2074"
88
},
9-
"version": "v2.0.0",
9+
"version": "v2.0.1",
1010
"id": "alphalaneous.happy_textures",
1111
"name": "Happy Textures :3",
1212
"developer": "Alphalaneous",

src/NodeModding.hpp

Lines changed: 49 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -2,26 +2,71 @@
22

33
#include <Geode/Geode.hpp>
44
#include <Geode/modify/CCObject.hpp>
5+
#include <Geode/modify/CCPoolManager.hpp>
56
#include "UIModding.hpp"
67
#include "nodes/CCNode.hpp"
78
#include "Utils.hpp"
89
#include "Macros.hpp"
910

1011
using namespace geode::prelude;
1112

13+
class LateQueue {
14+
protected:
15+
static LateQueue* instance;
16+
public:
17+
std::vector<std::function<void(void)>> m_mainThreadQueue;
18+
mutable std::mutex m_mainThreadMutex;
19+
20+
void queue(ScheduledFunction&& func) {
21+
std::lock_guard<std::mutex> lock(m_mainThreadMutex);
22+
m_mainThreadQueue.push_back(std::forward<ScheduledFunction>(func));
23+
}
24+
25+
void executeQueue() {
26+
m_mainThreadMutex.lock();
27+
auto queue = m_mainThreadQueue;
28+
m_mainThreadQueue.clear();
29+
m_mainThreadMutex.unlock();
30+
31+
for (auto const& func : queue) {
32+
func();
33+
}
34+
}
35+
36+
static LateQueue* get() {
37+
if (!instance) {
38+
instance = new LateQueue();
39+
};
40+
return instance;
41+
}
42+
};
43+
LateQueue* LateQueue::instance = nullptr;
44+
1245
class $modify(CCObject) {
1346

1447
CCObject* autorelease() {
1548
auto modding = UIModding::get();
16-
if (modding->doModify) {
17-
if (MyCCNode* node = static_cast<MyCCNode*>(typeinfo_cast<CCNode*>(this))) {
49+
if (!modding->doModify) return CCObject::autorelease();
50+
51+
if (MyCCNode* node = static_cast<MyCCNode*>(typeinfo_cast<CCNode*>(this))) {
52+
if (modding->finishedLoad && !node->isModified()) {
1853
const std::string& className = Utils::getNodeName(node);
19-
if (modding->finishedLoad && !node->isModified()) {
54+
node->retain();
55+
LateQueue::get()->queue([modding, node, className] {
2056
modding->doUICheckForType(className, node);
2157
node->setModified();
22-
}
58+
node->release();
59+
});
2360
}
2461
}
62+
2563
return CCObject::autorelease();
2664
}
2765
};
66+
67+
class $modify(CCPoolManager) {
68+
void pop() {
69+
LateQueue::get()->executeQueue();
70+
CCPoolManager::pop();
71+
}
72+
};

src/Utils.hpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -174,15 +174,14 @@ namespace Utils {
174174

175175
size_t prefixEnd = dotPos;
176176

177-
if (str.compare(prefixEnd - 4, 4, "-uhd") == 0) {
177+
if (prefixEnd >= 4 && str.compare(prefixEnd - 4, 4, "-uhd") == 0) {
178178
prefixEnd -= 4;
179-
} else if (str.compare(prefixEnd - 3, 3, "-hd") == 0) {
179+
} else if (prefixEnd >= 3 && str.compare(prefixEnd - 3, 3, "-hd") == 0) {
180180
prefixEnd -= 3;
181181
}
182182

183183
if (prefixEnd < dotPos) {
184184
str.erase(prefixEnd, dotPos - prefixEnd);
185-
dotPos = prefixEnd;
186185
}
187186
}
188187

0 commit comments

Comments
 (0)