优化滑动的函数
authorCaisking <Casiking@zhihuishixun.com>
Fri, 26 Dec 2025 13:18:28 +0000 (21:18 +0800)
committerCaisking <Casiking@zhihuishixun.com>
Fri, 26 Dec 2025 13:18:28 +0000 (21:18 +0800)
code/sdk/middleware/services/gui/uikit/ui/frameworks/dock/pointer_input_device.cpp

index 4994c4e..cc2d4fc 100644 (file)
@@ -118,6 +118,10 @@ void PointerInputDevice::DispatchPressEvent(UIViewGroup* rootView)
 
 bool PointerInputDevice::ProcessReleaseEvent()
 {
+    // 检查 touchableView_ 是否为空,防止空指针解引用
+    if (touchableView_ == nullptr) {
+        return false;
+    }
     UIView* parent = touchableView_->GetParent();
     // reissue press event.
     if (!pressSent_) {
@@ -336,6 +340,10 @@ void PointerInputDevice::DispatchDragEndEvent()
 
 void PointerInputDevice::DispatchLongPressEvent(uint32_t elapse)
 {
+    // 检查 touchableView_ 是否为空,防止空指针解引用
+    if (touchableView_ == nullptr) {
+        return;
+    }
     if (!longPressSent_ && (elapse > INDEV_LONG_PRESS_TIME)) {
         longPressSent_ = true;
         LongPressEvent evt(curPos_, pressTimeStamp_);
@@ -368,6 +376,11 @@ void PointerInputDevice::DispatchLongPressEvent(uint32_t elapse)
 
 void PointerInputDevice::DispatchCancelEvent()
 {
+    // 检查 touchableView_ 是否为空,防止空指针解引用
+    if (touchableView_ == nullptr) {
+        cancelSent_ = true;
+        return;
+    }
     CancelEvent evt(lastPos_);
     UIView* parent = touchableView_->GetParent();
     if (!touchableView_->OnCancelEvent(evt)) {