{"action":"created","issue":{"url":"https://api.github.com/repos/glfw/glfw/issues/1225","repository_url":"https://api.github.com/repos/glfw/glfw","labels_url":"https://api.github.com/repos/glfw/glfw/issues/1225/labels{/name}","comments_url":"https://api.github.com/repos/glfw/glfw/issues/1225/comments","events_url":"https://api.github.com/repos/glfw/glfw/issues/1225/events","html_url":"https://github.com/glfw/glfw/issues/1225","id":301600950,"number":1225,"title":"glfwPlatformPollEvents can hang, assumes other code won't pull XEvents","user":{"login":"johnjosephorr","id":5215421,"avatar_url":"https://avatars3.githubusercontent.com/u/5215421?v=4","gravatar_id":"","url":"https://api.github.com/users/johnjosephorr","html_url":"https://github.com/johnjosephorr","followers_url":"https://api.github.com/users/johnjosephorr/followers","following_url":"https://api.github.com/users/johnjosephorr/following{/other_user}","gists_url":"https://api.github.com/users/johnjosephorr/gists{/gist_id}","starred_url":"https://api.github.com/users/johnjosephorr/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/johnjosephorr/subscriptions","organizations_url":"https://api.github.com/users/johnjosephorr/orgs","repos_url":"https://api.github.com/users/johnjosephorr/repos","events_url":"https://api.github.com/users/johnjosephorr/events{/privacy}","received_events_url":"https://api.github.com/users/johnjosephorr/received_events","type":"User","site_admin":false},"labels":[{"id":37361231,"url":"https://api.github.com/repos/glfw/glfw/labels/X11","name":"X11","color":"3b80ae","default":false},{"id":36425440,"url":"https://api.github.com/repos/glfw/glfw/labels/bug","name":"bug","color":"b60205","default":true}],"state":"open","locked":false,"assignee":null,"assignees":[],"milestone":null,"comments":1,"created_at":"2018-03-01T23:38:29Z","updated_at":"2018-03-23T12:46:50Z","closed_at":null,"author_association":"NONE","body":"from master/src/x11_window.c:\r\n\r\n```c++\r\nvoid _glfwPlatformPollEvents(void)\r\n{\r\n    _GLFWwindow* window;\r\n\r\n#if defined(__linux__)\r\n    _glfwDetectJoystickConnectionLinux();\r\n#endif\r\n    int count = XPending(_glfw.x11.display);\r\n    while (count--)\r\n    {\r\n        XEvent event;\r\n        XNextEvent(_glfw.x11.display, &event);\r\n        processEvent(&event);\r\n    }\r\n```\r\nThis code assumes that it will be the only code removing the \"count\" number of XEvent's from the queue (it assumes it can call XNextEvent \"count\" number of times and it will not block waiting for input).  If something else should pull an XEvent off the queue (or perhaps Xlib will cancel events or coalesce multiple events that are currently on the queue?) this code will call XNextEvent more times than it should to process the events that are currently on the queue and will block inside XNextEvent until something generates new events.\r\n\r\nOn a normal computer there is a person with a mouse and keyboard who will typically generate more events, but on a system driving a non-interactive display of some kind, there is no one at the keyboard or mouse, so this code can hang.\r\n\r\nIn my case, I modified this loop to check XPending before calling XNextEvent:\r\n\r\n```c++\r\n    while (count--)\r\n    {\r\n        if ( XPending(_glfw.x11.display) > 0 )\r\n        {\r\n            XEvent event;\r\n            XNextEvent(_glfw.x11.display, &event);\r\n            processEvent(&event);\r\n        }\r\n    }\r\n```\r\n\r\nI intentionally left the cap in here on \"count\" number of loops so it does not process more than the original set of events, which matches the original behavior.  \r\n\r\nIf it matters, I ran into this while using Cinder which uses glfw in Linux only.  \r\n"},"comment":{"url":"https://api.github.com/repos/glfw/glfw/issues/comments/375654094","html_url":"https://github.com/glfw/glfw/issues/1225#issuecomment-375654094","issue_url":"https://api.github.com/repos/glfw/glfw/issues/1225","id":375654094,"user":{"login":"tombsar","id":3090978,"avatar_url":"https://avatars3.githubusercontent.com/u/3090978?v=4","gravatar_id":"","url":"https://api.github.com/users/tombsar","html_url":"https://github.com/tombsar","followers_url":"https://api.github.com/users/tombsar/followers","following_url":"https://api.github.com/users/tombsar/following{/other_user}","gists_url":"https://api.github.com/users/tombsar/gists{/gist_id}","starred_url":"https://api.github.com/users/tombsar/starred{/owner}{/repo}","subscriptions_url":"https://api.github.com/users/tombsar/subscriptions","organizations_url":"https://api.github.com/users/tombsar/orgs","repos_url":"https://api.github.com/users/tombsar/repos","events_url":"https://api.github.com/users/tombsar/events{/privacy}","received_events_url":"https://api.github.com/users/tombsar/received_events","type":"User","site_admin":false},"created_at":"2018-03-23T12:46:50Z","updated_at":"2018-03-23T12:46:50Z","author_association":"CONTRIBUTOR","body":"@ILGSupreme Sorry, calling either `glfwDestroyWindow` or `glfwTerminate` from within a callback is explicitly disallowed in the current API. Please see http://www.glfw.org/docs/latest/intro_guide.html#reentrancy"}}
{"actor":{"display_login":"tombsar"}}