为什么我的 DirectInput8 堆栈溢出?

发布于 2024-11-01 02:09:49 字数 445 浏览 3 评论 0原文

整个程序太复杂,无法在此显示。基本上,只需关注我最近 git 提交中的绿色亮点即可。我对 DirectInput 很陌生,所以我预计我犯了一些错误。我非常仔细地研究了 MSDN 文档,所以我保证我不会只是把它扔到那里并在上面标记“FIX IT FOR ME”。 :)

基本上,我认为我已经将问题范围缩小到了 Engine::getEvent 周围的代码区域(第 238 行+)。我不明白这些功能是如何工作的,并且我弄乱了某些部分以获得不同的结果。我的目标是直接读取键盘事件并将这些原始数字输出到屏幕(稍后我将处理这些数字的含义)。这里的问题与KEYBOARD_BUFFER_SIZE有关。如果我把它变小,程序似乎运行良好,但它不输出任何事件。如果我把它调大,它会运行得更好一些,但它开始变慢,然后冻结(OpenGL 窗口只有一个旋转的颜色立方体)。如何正确捕获键盘事件?

我检查了代码中所有较高设置步骤的返回值。他们都返回 DI_OK 就好了。

The overall program is too complex to display here. Basically, just pay attention to the green highlights in my recent git commit. I am very new to DirectInput, so I expect I've made several errors. I have very carefully studied the MSDN documentation, so I promise I'm not just throwing this out there and stamping FIX IT FOR ME on it. :)

Basically, I think I have narrowed down my problem to the area of code around Engine::getEvent (line 238+). I do not understand how these functions work, and I've messed with certain pieces to achieve different results. My goal here is to simply read in keyboard events directly and output those raw numbers to the screen (I will deal with the numbers' meaning later). The problem here relates to KEYBOARD_BUFFER_SIZE. If I make it small, the program seems to run fine, but it outputs no events. If I make it big, it runs a bit better, but it starts to slow down and then freeze (the OpenGL window just has a rotating color cube). How do I properly capture keyboard events?

I checked the return values on all the setup steps higher in the code. They all return DI_OK just fine.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

错爱 2024-11-08 02:09:49

你的代码似乎没问题(根据这个教程,我过去使用过< /a>)。使用多个基于堆栈的数组是有问题的,但不应该是太大的问题(除非您开始运行大量并发 getEvent 调用)。

但是,最好的选择是停止使用 DirectInput< /a> 并开始使用 Windows 原始输入。最好尽早(即现在)进行此切换,而不是稍后意识到您确实需要使用 DI 以外的其他东西来获得您想要的结果。

Your code seems to be okay (according to this tutorial, which I have used in the past). The use of several stack-based arrays is questionable, but shouldn't be too much of an issue (unless you start having lots of concurrent getEvent calls running).

However, your best bet would be to stop using DirectInput and start using Windows Raw Input. It's best to make this switch early (ie, now) rather than realise later on that you really need to use something other than DI to get the results you want.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文