简体   繁体   English

SDL2调整大小事件转到错误的线程?

[英]SDL2 resize event goes to wrong thread?

I use SDL2 from Python 3.5 and I have 2 threads, each drawing to their own OpenGl window. 我使用来自Python 3.5的SDL2,我有2个线程,每个线程都绘制到自己的OpenGl窗口。

Drawing goes fine, and all mouse and keyboard events arrive in the right thread. 绘图正常,所有鼠标和键盘事件到达正确的线程。 Only when I resize one of the window's, the resize event goes to the wrong window. 仅当我调整一个窗口的大小时,resize事件才会转到错误的窗口。

Here's part of my code: 这是我的代码的一部分:

def pollEvent (self):
    event = s2.SDL_Event ()
    if s2.SDL_PollEvent (ct.byref (event)):
        if event.type == s2.SDL_QUIT:
            self.running = False
        elif event.type == s2.SDL_WINDOWEVENT:
            if event.window.event == s2.SDL_WINDOWEVENT_RESIZED:
                print (111, self.name, 222)
                self.event = resizeEvent
                self.width = event.window.data1
                self.height = event.window.data2
                self.reshape ()
            elif event.window.event == s2.SDL_WINDOWEVENT_CLOSE:
                self.running = False
            self.renderDisplayList ()
        elif event.type == s2.SDL_MOUSEBUTTONDOWN:
            print (222, self.name, 333)

The SDL_MOUSEBUTTONDOWN goes to the right window, printing the right name, but the SDL_WINDOWEVENT_RESIZED goes to the wrong one, printing the wrong name. SDL_MOUSEBUTTONDOWN转到右侧窗口,打印正确的名称,但是SDL_WINDOWEVENT_RESIZED转到错误的名称,打印错误的名称。

Anyone any idea what could cause this? 任何人都知道是什么原因造成的吗? Each SDL window is only approached from its own thread. 每个SDL窗口仅从其自己的线程访问。

SDL makes only one event queue. SDL仅使一个事件队列。 Event queue is mostly thread-safe, but it would be logically hard to use it in multiple threads. 事件队列大多是线程安全的,但是从逻辑上讲很难在多个线程中使用它。 It is probably better to read events in only one thread and send notifications to other threads through some other things. 最好只在一个线程中读取事件,然后通过其他方式将通知发送给其他线程。

As for window events, they contain windowID field. 至于窗口事件,它们包含windowID字段。 You can get ID of a window with SDL_GetWindowID call. 您可以通过SDL_GetWindowID调用获取窗口的ID。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM