IOHIDEventSystemClientScheduleWithRunLoop与EXC

编程入门 行业动态 更新时间:2024-10-25 23:35:49
本文介绍了IOHIDEventSystemClientScheduleWithRunLoop与EXC_BAD_ACCESS的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试在我的应用程序中获取触摸事件。所以我使用IOHIDFamily回调来获取事件。我的代码是这样的:

I'm trying to get touch events in my application. So I used the IOHIDFamily callback to get the events. My code is like this:

void handle_event(void* target, void* refcon, IOHIDServiceRef service, IOHIDEventRef event) { printf("Received event of type %2d from service %p.\n", IOHIDEventGetType(event), service); } - (void)viewDidLoad { [super viewDidLoad]; void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault); IOHIDEventSystemClientScheduleWithRunLoop(system, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode); IOHIDEventSystemClientRegisterEventCallback(system, handle_event, NULL, NULL); CFRunLoopRun(); }

执行时出错:

IOHIDEventSystemClientScheduleWithRunLoop(system,CFRunLoopGetCurrent(),kCFRunLoopDefaultMode);

IOHIDEventSystemClientScheduleWithRunLoop(system, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

IOKit`IOHIDEventSystemClientScheduleWithRunLoop: ... 0x32f8fd14:cmp.w r10,#0 0x32f8fd18:strd r10,r11,[r4,#116]< --- EXC_BAD_ACCESS(代码= EXC_ARM_DA_ALIGN) 0x32f8fd1c:beq 0x32f8fdac; IOHIDEventSystemClientScheduleWithRunLoop + 168 0x32f8fd1e:ldr r1,[r4,#96] 0x32f8fd20:cbz r1,0x32f8fd2a; IOHIDEventSystemClientScheduleWithRunLoop + 38 0x32f8fd22:mov r0,r10 ...

IOKit`IOHIDEventSystemClientScheduleWithRunLoop: ... 0x32f8fd14: cmp.w r10, #0 0x32f8fd18: strd r10, r11, [r4, #116] <---EXC_BAD_ACCESS(code=EXC_ARM_DA_ALIGN) 0x32f8fd1c: beq 0x32f8fdac ; IOHIDEventSystemClientScheduleWithRunLoop + 168 0x32f8fd1e: ldr r1, [r4, #96] 0x32f8fd20: cbz r1, 0x32f8fd2a ; IOHIDEventSystemClientScheduleWithRunLoop + 38 0x32f8fd22: mov r0, r10 ...

我以错误的方式使用IOHIDFamily?

Did I use IOHIDFamily in the wrong way?

推荐答案

我发现代码中至少有几个问题:

There's at least a couple problems I see in the code posted:

首先,您正在致电

CFRunLoopRun();

$ b

在 viewDidLoad 方法中在main / UI线程上调用。我认为没有理由,所以只需删除该行。我通常希望看到那个调用,如果你有一个方法,你在后台线程上运行,你需要启动后台运行循环。或者,如果您直接在 main()中注册回调,请回答。

in the viewDidLoad method, which is going to be called on the main/UI thread. I see no reason for that, so just remove that line. I'd normally expect to see that call if you had a method that you were running on a background thread, and you needed to start a background run loop. Or, if you were registering for callbacks directly in main(), as in this answer.

然后,你有这个:

void *ioHIDEventSystem = IOHIDEventSystemClientCreate(kCFAllocatorDefault); IOHIDEventSystemClientScheduleWithRunLoop(system, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

我猜第二行应该是

IOHIDEventSystemClientScheduleWithRunLoop(ioHIDEventSystem, CFRunLoopGetCurrent(), kCFRunLoopDefaultMode);

我不知道系统是什么变量实际上是指,但它看起来不正确。

I don't know what the system variable actually refers to, but it doesn't look right.

参加看看最近的答案,因为它似乎正确使用 IOKit 。

Take a look at this recent answer, as it seems to use IOKit correctly.

更多推荐

IOHIDEventSystemClientScheduleWithRunLoop与EXC

本文发布于:2023-11-26 12:37:54,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1633944.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:IOHIDEventSystemClientScheduleWithRunLoop   EXC

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!