Skip to content

Commit

Permalink
android platformer crash workaround
Browse files Browse the repository at this point in the history
  • Loading branch information
qimiko committed May 19, 2024
1 parent d6c5f72 commit 0fbd374
Show file tree
Hide file tree
Showing 2 changed files with 32 additions and 2 deletions.
26 changes: 24 additions & 2 deletions src/async.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,31 @@ bool AsyncUILayer::ccTouchBegan(cocos2d::CCTouch* touch, cocos2d::CCEvent* event

void AsyncUILayer::ccTouchMoved(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) {
if (!event) {
#ifdef GEODE_IS_ANDROID
if (this->m_inPlatformer) {
this->processUINodesTouch(
static_cast<GJUITouchEvent>(1), touch
);
}
return;
#else
return UILayer::ccTouchMoved(touch, event);
#endif
}

auto extendedInfo = static_cast<ExtendedCCEvent*>(event);
m_fields->m_lastTimestamp = extendedInfo->getTimestamp();

#ifdef GEODE_IS_ANDROID
if (this->m_inPlatformer) {
this->processUINodesTouch(
static_cast<GJUITouchEvent>(1), touch
);
}
#else
UILayer::ccTouchMoved(touch, event);
#endif

m_fields->m_lastTimestamp = 0ull;
}

Expand All @@ -55,14 +73,18 @@ void AsyncUILayer::ccTouchEnded(cocos2d::CCTouch* touch, cocos2d::CCEvent* event

#ifndef GEODE_IS_WINDOWS
void AsyncUILayer::ccTouchCancelled(cocos2d::CCTouch* touch, cocos2d::CCEvent* event) {
// this event can't actually be called on anything but android/ios,
// so should be safe to just rewrite them

if (!event) {
return UILayer::ccTouchCancelled(touch, event);
return this->ccTouchEnded(touch, event);
}

auto extendedInfo = static_cast<ExtendedCCEvent*>(event);
m_fields->m_lastTimestamp = extendedInfo->getTimestamp();

UILayer::ccTouchCancelled(touch, event);
this->ccTouchEnded(touch, event);

m_fields->m_lastTimestamp = 0ull;
}
#endif
Expand Down
8 changes: 8 additions & 0 deletions src/async.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,13 @@ struct AsyncUILayer : geode::Modify<AsyncUILayer, UILayer> {
void ccTouchCancelled(cocos2d::CCTouch*, cocos2d::CCEvent*);
#endif

#ifdef GEODE_IS_ANDROID
// to workaround some Android hook size problems, we reimplement these functions
static void onModify(auto& self) {
(void)self.setHookPriority("UILayer::ccTouchMoved", 5000);
(void)self.setHookPriority("UILayer::ccTouchCancelled", 5000);
}
#endif

std::uint64_t getLastTimestamp();
};

0 comments on commit 0fbd374

Please sign in to comment.