IOHIDEventSystemClientScheduleWithRunLoop与EXC_BAD_ACCESS [英] IOHIDEventSystemClientScheduleWithRunLoop with EXC_BAD_ACCESS

查看:569
本文介绍了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_BAD_ACCESS的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆