ufo
ufo copied to clipboard
glfw input callbacks
Hi,
ufo seems like a great project. I have been fiddling around with glsw(on OSX) and I can set callbacks with ffi.cast (for example glfwSetCharCallback), but on input I get a segfault:
[...]
glfw.glfwSetCharCallback(ffi.cast("GLFWcharfun", function(w,c,a) end))
while glfw.glfwGetKey( window, glfw.GLFW_KEY_ESCAPE ) ~= glfw.GLFW_PRESS do
gl.glClear( gl.GL_COLOR_BUFFER_BIT )
glfw.glfwSwapBuffers(window)
glfw.glfwPollEvents()
end
[...]
Am I missing something?
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread
0 luajit.dylib 0x00007fff04c4f16f 0x7fff04c4a000 + 20847
1 luajit.dylib 0x00007fff04c4f038 0x7fff04c4a000 + 20536
2 libunwind.dylib 0x00007fff8d3b591f _Unwind_RaiseException + 139
3 luajit.dylib 0x00007fff04c4f41a 0x7fff04c4a000 + 21530
4 luajit.dylib 0x00007fff04c4f5a3 0x7fff04c4a000 + 21923
5 luajit.dylib 0x00007fff04c503eb 0x7fff04c4a000 + 25579
6 luajit.dylib 0x00007fff04c54b63 0x7fff04c4a000 + 43875
7 luajit.dylib 0x00007fff04c5a1ed 0x7fff04c4a000 + 66029
8 luajit.dylib 0x00007fff04c4e799 0x7fff04c4a000 + 18329
9 glfw.dylib 0x000000000006634d _glfwInputChar + 109
10 glfw.dylib 0x000000000006d0ec -[GLFWContentView keyDown:] + 348
11 com.apple.AppKit 0x00007fff8ff5f7ac -[NSWindow sendEvent:] + 7430
12 com.apple.AppKit 0x00007fff8fef8a55 -[NSApplication sendEvent:] + 5593
13 glfw.dylib 0x000000000006d413 -[GLFWApplication sendEvent:] + 195
14 glfw.dylib 0x000000000006e8db _glfwPlatformPollEvents + 171
15 glfw.dylib 0x0000000000069839 glfwPollEvents + 57
16 ??? 0x00007fff3dcfffe4 0 + 140734230429668
Thanks. I'll take a look later on my Mac (10.8.2) On Nov 8, 2012 12:44 PM, "headchant" [email protected] wrote:
Hi,
ufo seems like a great project. I have been fiddling around with glsw(on OSX) and I can set callbacks with ffi.cast (for example glfwSetCharCallback, but on input I get a segfault:
[...] glfw.glfwSetCharCallback(ffi.cast("GLFWcharfun", function(w,c,a) end))
while glfw.glfwGetKey( window, glfw.GLFW_KEY_ESCAPE ) ~= glfw.GLFW_PRESS do gl.glClear( gl.GL_COLOR_BUFFER_BIT ) glfw.glfwSwapBuffers(window) glfw.glfwPollEvents() end [...]
Am I missing something?
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 luajit.dylib 0x00007fff04c4f16f 0x7fff04c4a000 + 20847 1 luajit.dylib 0x00007fff04c4f038 0x7fff04c4a000 + 20536 2 libunwind.dylib 0x00007fff8d3b591f _Unwind_RaiseException + 139 3 luajit.dylib 0x00007fff04c4f41a 0x7fff04c4a000 + 21530 4 luajit.dylib 0x00007fff04c4f5a3 0x7fff04c4a000 + 21923 5 luajit.dylib 0x00007fff04c503eb 0x7fff04c4a000 + 25579 6 luajit.dylib 0x00007fff04c54b63 0x7fff04c4a000 + 43875 7 luajit.dylib 0x00007fff04c5a1ed 0x7fff04c4a000 + 66029 8 luajit.dylib 0x00007fff04c4e799 0x7fff04c4a000 + 18329 9 glfw.dylib 0x000000000006634d _glfwInputChar + 109 10 glfw.dylib 0x000000000006d0ec -[GLFWContentView keyDown:] + 348 11 com.apple.AppKit 0x00007fff8ff5f7ac -[NSWindow sendEvent:] + 7430 12 com.apple.AppKit 0x00007fff8fef8a55 -[NSApplication sendEvent:] + 5593 13 glfw.dylib 0x000000000006d413 -[GLFWApplication sendEvent:] + 195 14 glfw.dylib 0x000000000006e8db _glfwPlatformPollEvents + 171 15 glfw.dylib 0x0000000000069839 glfwPollEvents + 57 16 ??? 0x00007fff3dcfffe4 0 + 140734230429668
— Reply to this email directly or view it on GitHubhttps://github.com/malkia/ufo/issues/9.
I just synced to the latest glfw (3.0) from depot: commit 410a4e29e133fe911c817fb1061df16420c4365a Author: Camilla Berglund [email protected] Date: Thu Sep 27 22:28:04 2012 +0200
Moved from gl3.h to glcorearb.h.
The GLFWcharfun takes two arguments, not three (w,c,a): malkia ~/p/glfw $ git grep GLFWcharfun include/GL/glfw3.h:typedef void (* GLFWcharfun)(GLFWwindow,int); include/GL/glfw3.h:GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun); src/input.c:GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun) src/internal.h: GLFWcharfun charCallback;
Then again not sure whether it matters.
I'll try your code, and update the latest glfw version in.
On Thu, Nov 8, 2012 at 4:42 PM, malkia [email protected] wrote:
Thanks. I'll take a look later on my Mac (10.8.2) On Nov 8, 2012 12:44 PM, "headchant" [email protected] wrote:
Hi,
ufo seems like a great project. I have been fiddling around with glsw(on OSX) and I can set callbacks with ffi.cast (for example glfwSetCharCallback, but on input I get a segfault:
[...] glfw.glfwSetCharCallback(ffi.cast("GLFWcharfun", function(w,c,a) end))
while glfw.glfwGetKey( window, glfw.GLFW_KEY_ESCAPE ) ~= glfw.GLFW_PRESS do gl.glClear( gl.GL_COLOR_BUFFER_BIT ) glfw.glfwSwapBuffers(window) glfw.glfwPollEvents() end [...]
Am I missing something?
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 luajit.dylib 0x00007fff04c4f16f 0x7fff04c4a000 + 20847 1 luajit.dylib 0x00007fff04c4f038 0x7fff04c4a000 + 20536 2 libunwind.dylib 0x00007fff8d3b591f _Unwind_RaiseException + 139 3 luajit.dylib 0x00007fff04c4f41a 0x7fff04c4a000 + 21530 4 luajit.dylib 0x00007fff04c4f5a3 0x7fff04c4a000 + 21923 5 luajit.dylib 0x00007fff04c503eb 0x7fff04c4a000 + 25579 6 luajit.dylib 0x00007fff04c54b63 0x7fff04c4a000 + 43875 7 luajit.dylib 0x00007fff04c5a1ed 0x7fff04c4a000 + 66029 8 luajit.dylib 0x00007fff04c4e799 0x7fff04c4a000 + 18329 9 glfw.dylib 0x000000000006634d _glfwInputChar + 109 10 glfw.dylib 0x000000000006d0ec -[GLFWContentView keyDown:] + 348 11 com.apple.AppKit 0x00007fff8ff5f7ac -[NSWindow sendEvent:] + 7430 12 com.apple.AppKit 0x00007fff8fef8a55 -[NSApplication sendEvent:] + 5593 13 glfw.dylib 0x000000000006d413 -[GLFWApplication sendEvent:] + 195 14 glfw.dylib 0x000000000006e8db _glfwPlatformPollEvents + 171 15 glfw.dylib 0x0000000000069839 glfwPollEvents + 57 16 ??? 0x00007fff3dcfffe4 0 + 140734230429668
— Reply to this email directly or view it on GitHubhttps://github.com/malkia/ufo/issues/9.
Dimiter "malkia" Stanev, ICQ: 21875894 [email protected] [email protected]
It works here, but while trying your test I ran somehow in something similar.
It turned out my window was NULL.
Test whether the code works without the callback, if it crashes, then make sure window is not NULL (nil)
I'll submit the latest glfw in.
Cheers!
On Thu, Nov 8, 2012 at 7:27 PM, malkia [email protected] wrote:
I just synced to the latest glfw (3.0) from depot: commit 410a4e29e133fe911c817fb1061df16420c4365a Author: Camilla Berglund [email protected] Date: Thu Sep 27 22:28:04 2012 +0200
Moved from gl3.h to glcorearb.h.
The GLFWcharfun takes two arguments, not three (w,c,a): malkia ~/p/glfw $ git grep GLFWcharfun include/GL/glfw3.h:typedef void (* GLFWcharfun)(GLFWwindow,int); include/GL/glfw3.h:GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun); src/input.c:GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun) src/internal.h: GLFWcharfun charCallback;
Then again not sure whether it matters.
I'll try your code, and update the latest glfw version in.
On Thu, Nov 8, 2012 at 4:42 PM, malkia [email protected] wrote:
Thanks. I'll take a look later on my Mac (10.8.2) On Nov 8, 2012 12:44 PM, "headchant" [email protected] wrote:
Hi,
ufo seems like a great project. I have been fiddling around with glsw(on OSX) and I can set callbacks with ffi.cast (for example glfwSetCharCallback, but on input I get a segfault:
[...] glfw.glfwSetCharCallback(ffi.cast("GLFWcharfun", function(w,c,a) end))
while glfw.glfwGetKey( window, glfw.GLFW_KEY_ESCAPE ) ~= glfw.GLFW_PRESS do gl.glClear( gl.GL_COLOR_BUFFER_BIT ) glfw.glfwSwapBuffers(window) glfw.glfwPollEvents() end [...]
Am I missing something?
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 luajit.dylib 0x00007fff04c4f16f 0x7fff04c4a000 + 20847 1 luajit.dylib 0x00007fff04c4f038 0x7fff04c4a000 + 20536 2 libunwind.dylib 0x00007fff8d3b591f _Unwind_RaiseException + 139 3 luajit.dylib 0x00007fff04c4f41a 0x7fff04c4a000 + 21530 4 luajit.dylib 0x00007fff04c4f5a3 0x7fff04c4a000 + 21923 5 luajit.dylib 0x00007fff04c503eb 0x7fff04c4a000 + 25579 6 luajit.dylib 0x00007fff04c54b63 0x7fff04c4a000 + 43875 7 luajit.dylib 0x00007fff04c5a1ed 0x7fff04c4a000 + 66029 8 luajit.dylib 0x00007fff04c4e799 0x7fff04c4a000 + 18329 9 glfw.dylib 0x000000000006634d _glfwInputChar + 109 10 glfw.dylib 0x000000000006d0ec -[GLFWContentView keyDown:] + 348 11 com.apple.AppKit 0x00007fff8ff5f7ac -[NSWindow sendEvent:] + 7430 12 com.apple.AppKit 0x00007fff8fef8a55 -[NSApplication sendEvent:] + 5593 13 glfw.dylib 0x000000000006d413 -[GLFWApplication sendEvent:] + 195 14 glfw.dylib 0x000000000006e8db _glfwPlatformPollEvents + 171 15 glfw.dylib 0x0000000000069839 glfwPollEvents + 57 16 ??? 0x00007fff3dcfffe4 0 + 140734230429668
— Reply to this email directly or view it on GitHubhttps://github.com/malkia/ufo/issues/9.
Dimiter "malkia" Stanev, ICQ: 21875894 [email protected] [email protected]
Dimiter "malkia" Stanev, ICQ: 21875894 [email protected] [email protected]
Please try it out now. I haven't submitted latest luajit, but it should work with whatever is in there.
commit 9dcdf85583503ad38428f44f0d96b7c5703b32ff Author: Dimiter "malkia" Stanev [email protected] Date: Thu Nov 8 19:53:36 2012 -0800
latest glfw osx, some minor fixes, testcase for headchant
This is only glfw, and I created one test case for you samples/glfw/headchant-test.lua - It works here - 64-bit osx 10.8.2 (mac book pro). I should test it on my wife's old 10.5 to see whether it's okay there too.
Cheers!
On Thu, Nov 8, 2012 at 7:50 PM, malkia [email protected] wrote:
It works here, but while trying your test I ran somehow in something similar.
It turned out my window was NULL.
Test whether the code works without the callback, if it crashes, then make sure window is not NULL (nil)
I'll submit the latest glfw in.
Cheers!
On Thu, Nov 8, 2012 at 7:27 PM, malkia [email protected] wrote:
I just synced to the latest glfw (3.0) from depot: commit 410a4e29e133fe911c817fb1061df16420c4365a Author: Camilla Berglund [email protected] Date: Thu Sep 27 22:28:04 2012 +0200
Moved from gl3.h to glcorearb.h.
The GLFWcharfun takes two arguments, not three (w,c,a): malkia ~/p/glfw $ git grep GLFWcharfun include/GL/glfw3.h:typedef void (* GLFWcharfun)(GLFWwindow,int); include/GL/glfw3.h:GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun); src/input.c:GLFWAPI void glfwSetCharCallback(GLFWcharfun cbfun) src/internal.h: GLFWcharfun charCallback;
Then again not sure whether it matters.
I'll try your code, and update the latest glfw version in.
On Thu, Nov 8, 2012 at 4:42 PM, malkia [email protected] wrote:
Thanks. I'll take a look later on my Mac (10.8.2) On Nov 8, 2012 12:44 PM, "headchant" [email protected] wrote:
Hi,
ufo seems like a great project. I have been fiddling around with glsw(on OSX) and I can set callbacks with ffi.cast (for example glfwSetCharCallback, but on input I get a segfault:
[...] glfw.glfwSetCharCallback(ffi.cast("GLFWcharfun", function(w,c,a) end))
while glfw.glfwGetKey( window, glfw.GLFW_KEY_ESCAPE ) ~= glfw.GLFW_PRESS do gl.glClear( gl.GL_COLOR_BUFFER_BIT ) glfw.glfwSwapBuffers(window) glfw.glfwPollEvents() end [...]
Am I missing something?
Thread 0 Crashed:: Dispatch queue: com.apple.main-thread 0 luajit.dylib 0x00007fff04c4f16f 0x7fff04c4a000 + 20847 1 luajit.dylib 0x00007fff04c4f038 0x7fff04c4a000 + 20536 2 libunwind.dylib 0x00007fff8d3b591f _Unwind_RaiseException + 139 3 luajit.dylib 0x00007fff04c4f41a 0x7fff04c4a000 + 21530 4 luajit.dylib 0x00007fff04c4f5a3 0x7fff04c4a000 + 21923 5 luajit.dylib 0x00007fff04c503eb 0x7fff04c4a000 + 25579 6 luajit.dylib 0x00007fff04c54b63 0x7fff04c4a000 + 43875 7 luajit.dylib 0x00007fff04c5a1ed 0x7fff04c4a000 + 66029 8 luajit.dylib 0x00007fff04c4e799 0x7fff04c4a000 + 18329 9 glfw.dylib 0x000000000006634d _glfwInputChar + 109 10 glfw.dylib 0x000000000006d0ec -[GLFWContentView keyDown:] + 348 11 com.apple.AppKit 0x00007fff8ff5f7ac -[NSWindow sendEvent:] + 7430 12 com.apple.AppKit 0x00007fff8fef8a55 -[NSApplication sendEvent:] + 5593 13 glfw.dylib 0x000000000006d413 -[GLFWApplication sendEvent:] + 195 14 glfw.dylib 0x000000000006e8db _glfwPlatformPollEvents + 171 15 glfw.dylib 0x0000000000069839 glfwPollEvents + 57 16 ??? 0x00007fff3dcfffe4 0 + 140734230429668
— Reply to this email directly or view it on GitHubhttps://github.com/malkia/ufo/issues/9.
Dimiter "malkia" Stanev, ICQ: 21875894 [email protected] [email protected]
Dimiter "malkia" Stanev, ICQ: 21875894 [email protected] [email protected]
Dimiter "malkia" Stanev, ICQ: 21875894 [email protected] [email protected]
I'm on 10.7.4. And it still segfaults. Should I try compiling glfw myself?
Yes, please try that
if ufo is say in here
~/ufo
then you should have latest glfw (3.0 from ther git repo) in
~/glfw
then go to
~/ufo/build/OSX and do ./glfw.sh
it would build it, and copy the files (it expects git repo in glfw dir)
Sent from my iPad
On Nov 9, 2012, at 8:20 AM, headchant [email protected] wrote:
I'm on 10.7.4. And it still segfaults. Should I try compiling glfw myself?
— Reply to this email directly or view it on GitHub.
Thanks for the help. Compilation worked(sources from https://github.com/elmindreda/glfw). But now the error is: ./luajit: line 53: 4969 Bus error: 10
It seems to already crash on glfwSetCharCallback:
0 glfw.dylib 0x00000000000668cb glfwSetCharCallback + 75 1 luajit.dylib 0x00007fff04c4e877 0x7fff04c4a000 + 18551 2 luajit.dylib 0x00007fff04c6939c 0x7fff04c4a000 + 127900 3 luajit.dylib 0x00007fff04c4c6f6 0x7fff04c4a000 + 9974 4 luajit.dylib 0x00007fff04c58374 lua_pcall + 100 5 luajit 0x0000000100001fe9 0x100000000 + 8169 6 luajit 0x0000000100001a30 0x100000000 + 6704 7 luajit.dylib 0x00007fff04c4c6f6 0x7fff04c4a000 + 9974 8 luajit.dylib 0x00007fff04c583bb lua_cpcall + 27 9 luajit 0x0000000100000faa main + 138 10 luajit 0x0000000100000ef4 start + 52
hmm.. make ure that the window handle is not NULL
Sent from my iPad
On Nov 9, 2012, at 9:32 AM, headchant [email protected] wrote:
Thanks for the help. Compilation worked(sources from https://github.com/elmindreda/glfw). But now the error is: ./luajit: line 53: 4969 Bus error: 10
It seems to already crash on glfwSetCharCallback:
0 glfw.dylib 0x00000000000668cb glfwSetCharCallback + 75 1 luajit.dylib 0x00007fff04c4e877 0x7fff04c4a000 + 18551 2 luajit.dylib 0x00007fff04c6939c 0x7fff04c4a000 + 127900 3 luajit.dylib 0x00007fff04c4c6f6 0x7fff04c4a000 + 9974 4 luajit.dylib 0x00007fff04c58374 lua_pcall + 100 5 luajit 0x0000000100001fe9 0x100000000 + 8169 6 luajit 0x0000000100001a30 0x100000000 + 6704 7 luajit.dylib 0x00007fff04c4c6f6 0x7fff04c4a000 + 9974 8 luajit.dylib 0x00007fff04c583bb lua_cpcall + 27 9 luajit 0x0000000100000faa main + 138 10 luajit 0x0000000100000ef4 start + 52
— Reply to this email directly or view it on GitHub.
The window handle is not nil (I tested it several times). Again, thank you for the help. I will test some stuff(upgrading to mountain lion) and see if it works there.
Hey dude,
Here is what happened - I haven't updated the ffi/glfw.lua properly. I recompiled to latest windows/osx glfw, and submitted to the ufo bin folder. Also updated the ffi/glfw.lua as I've said.
It looks like now the glfwSet*Callback functions require the window handle (e.g. they are per window, not global).
Check samples/glfw/headchant-test.lua for updated sample.
Cheers!
On Sun, Nov 11, 2012 at 3:47 AM, headchant [email protected] wrote:
The window handle is not nil (I tested it several times). Again, thank you for the help. I will test some stuff(upgrading to mountain lion) and see if it works there.
— Reply to this email directly or view it on GitHubhttps://github.com/malkia/ufo/issues/9#issuecomment-10265823.
Dimiter "malkia" Stanev, ICQ: 21875894 [email protected] [email protected]
Ok, sorry for the late response: On Lion I had the same error as before. Now I updated to mountain lion and I get: PANIC: unprotected error in call to Lua API (bad callback)
Is this happening at head.
I've just tested this on my machine (from both 32-bit and 64-bit)
malkia ~/p/ufo $ arch -i386 bin/OSX/luajit samples/glfw/headchant-test.lua GLFW Window cdata<struct GLFWwindow *>: 0x00a3c800 CocoaWindow cdata<void *>: 0x001dca30 NSGLContext cdata<void *>: 0x001de230 nil
malkia ~/p/ufo $ arch -x86_64 bin/OSX/luajit samples/glfw/headchant-test.lua GLFW Window cdata<struct GLFWwindow *>: 0x00164670 CocoaWindow cdata<void *>: 0x0017cac0 NSGLContext cdata<void *>: 0x0018be70 nil
On Sun, Nov 18, 2012 at 1:39 AM, headchant [email protected] wrote:
Ok, sorry for the late response: On Lion I had the same error as before. Now I updated to mountain lion and I get: PANIC: unprotected error in call to Lua API (bad callback)
— Reply to this email directly or view it on GitHubhttps://github.com/malkia/ufo/issues/9#issuecomment-10484216.
Dimiter "malkia" Stanev, ICQ: 21875894 [email protected] [email protected]
I get the same error here, with a freshly pulled ufo and luajit.
I get the "PANIC: unprotected error in call to Lua API (bad callback)" when pressing a key. Below is the most minimal example. If I comment out require "ffi.OpenGL", or if I use glfwWaitEvents() instead of glfwPollEvents(), then the keyboard callback works fine. Could it be either a threading issue or that GLFW is talking to a different OpenGL?
local gl = require "ffi.OpenGL" -- no PANIC if I comment this out
local glfw = require "ffi.glfw"
local ffi = require "ffi"
assert(glfw.glfwInit() ~= 0, "failed to initialize GLFW")
print(string.format("using %s", ffi.string(glfw.glfwGetVersionString())))
local window = glfw.glfwCreateWindow(640, 480, glfw.GLFW_WINDOWED, "test", nil)
assert(window ~= nil)
glfw.glfwSetKeyCallback(window, function(win, k, c) print("key", win, k, c) end)
while true do
glfw.glfwSwapBuffers(window)
glfw.glfwPollEvents()
--glfw.glfwWaitEvents() -- no PANIC if I use this instead of glfwPollEvents()
end
glfw.glfwTerminate()
The GLFW version string prints "using 3.0.0 dynamic" luajit -v prints LuaJIT 2.0.1 -- Copyright (C) 2005-2013 Mike Pall. http://luajit.org/ uname -a says: Darwin grrrwaaa.local 10.8.0 Darwin Kernel Version 10.8.0: Tue Jun 7 16:32:41 PDT 2011; root:xnu-1504.15.3~1/RELEASE_X86_64 x86_64 OSX version is 10.6.8.
I also get PANIC on keyboard hits with /samples/glfw/headchant-test.lua
Pulled latest GLFW and tried cd ~/ufo/build/OSX && ./glfw.sh, built successfully into bin/OSX/glfw.dylib. The API of GLFW 3.0 has changed (again), so I generated a new ffi/glfw.lua (and the arguments to glfwCreateWindow) to avoid a Bus Error crash (included below). But I'm still seeing the "PANIC: unprotected error in call to Lua API (bad callback)" when using PollEvents(), and no PANIC when using WaitEvents().
Perhaps GLFW 3.0 is not safe to use yet?
local ffi = require( "ffi" )
local libs = ffi_glfw_libs or {
OSX = { x86 = "bin/OSX/glfw.dylib", x64 = "bin/OSX/glfw.dylib" },
Windows = { x86 = "bin/Windows/x86/glfw.dll", x64 = "bin/Windows/x64/glfw.dll" },
Linux = { x86 = "bin/Linux/x86/libglfw.so", x64 = "bin/Linux/x64/libglfw.so",
arm = "bin/Linux/arm/libglfw.so" },
BSD = { x86 = "bin/glfw32.so", x64 = "bin/glfw64.so" },
POSIX = { x86 = "bin/glfw32.so", x64 = "bin/glfw64.so" },
Other = { x86 = "bin/glfw32.so", x64 = "bin/glfw64.so" },
}
local lib = ffi_glfw_lib or libs[ ffi.os ][ ffi.arch ]
local glfw = ffi.load( lib )
ffi.cdef[[
enum {
GLFW_VERSION_MAJOR = 3,
GLFW_VERSION_MINOR = 0,
GLFW_VERSION_REVISION = 0,
GLFW_RELEASE = 0,
GLFW_PRESS = 1,
GLFW_KEY_SPACE = 32,
GLFW_KEY_APOSTROPHE = 39,
GLFW_KEY_COMMA = 44,
GLFW_KEY_MINUS = 45,
GLFW_KEY_PERIOD = 46,
GLFW_KEY_SLASH = 47,
GLFW_KEY_0 = 48,
GLFW_KEY_1 = 49,
GLFW_KEY_2 = 50,
GLFW_KEY_3 = 51,
GLFW_KEY_4 = 52,
GLFW_KEY_5 = 53,
GLFW_KEY_6 = 54,
GLFW_KEY_7 = 55,
GLFW_KEY_8 = 56,
GLFW_KEY_9 = 57,
GLFW_KEY_SEMICOLON = 59,
GLFW_KEY_EQUAL = 61,
GLFW_KEY_A = 65,
GLFW_KEY_B = 66,
GLFW_KEY_C = 67,
GLFW_KEY_D = 68,
GLFW_KEY_E = 69,
GLFW_KEY_F = 70,
GLFW_KEY_G = 71,
GLFW_KEY_H = 72,
GLFW_KEY_I = 73,
GLFW_KEY_J = 74,
GLFW_KEY_K = 75,
GLFW_KEY_L = 76,
GLFW_KEY_M = 77,
GLFW_KEY_N = 78,
GLFW_KEY_O = 79,
GLFW_KEY_P = 80,
GLFW_KEY_Q = 81,
GLFW_KEY_R = 82,
GLFW_KEY_S = 83,
GLFW_KEY_T = 84,
GLFW_KEY_U = 85,
GLFW_KEY_V = 86,
GLFW_KEY_W = 87,
GLFW_KEY_X = 88,
GLFW_KEY_Y = 89,
GLFW_KEY_Z = 90,
GLFW_KEY_LEFT_BRACKET = 91,
GLFW_KEY_BACKSLASH = 92,
GLFW_KEY_RIGHT_BRACKET = 93,
GLFW_KEY_GRAVE_ACCENT = 96,
GLFW_KEY_WORLD_1 = 161,
GLFW_KEY_WORLD_2 = 162,
GLFW_KEY_ESCAPE = 256,
GLFW_KEY_ENTER = 257,
GLFW_KEY_TAB = 258,
GLFW_KEY_BACKSPACE = 259,
GLFW_KEY_INSERT = 260,
GLFW_KEY_DELETE = 261,
GLFW_KEY_RIGHT = 262,
GLFW_KEY_LEFT = 263,
GLFW_KEY_DOWN = 264,
GLFW_KEY_UP = 265,
GLFW_KEY_PAGE_UP = 266,
GLFW_KEY_PAGE_DOWN = 267,
GLFW_KEY_HOME = 268,
GLFW_KEY_END = 269,
GLFW_KEY_CAPS_LOCK = 280,
GLFW_KEY_SCROLL_LOCK = 281,
GLFW_KEY_NUM_LOCK = 282,
GLFW_KEY_PRINT_SCREEN = 283,
GLFW_KEY_PAUSE = 284,
GLFW_KEY_F1 = 290,
GLFW_KEY_F2 = 291,
GLFW_KEY_F3 = 292,
GLFW_KEY_F4 = 293,
GLFW_KEY_F5 = 294,
GLFW_KEY_F6 = 295,
GLFW_KEY_F7 = 296,
GLFW_KEY_F8 = 297,
GLFW_KEY_F9 = 298,
GLFW_KEY_F10 = 299,
GLFW_KEY_F11 = 300,
GLFW_KEY_F12 = 301,
GLFW_KEY_F13 = 302,
GLFW_KEY_F14 = 303,
GLFW_KEY_F15 = 304,
GLFW_KEY_F16 = 305,
GLFW_KEY_F17 = 306,
GLFW_KEY_F18 = 307,
GLFW_KEY_F19 = 308,
GLFW_KEY_F20 = 309,
GLFW_KEY_F21 = 310,
GLFW_KEY_F22 = 311,
GLFW_KEY_F23 = 312,
GLFW_KEY_F24 = 313,
GLFW_KEY_F25 = 314,
GLFW_KEY_KP_0 = 320,
GLFW_KEY_KP_1 = 321,
GLFW_KEY_KP_2 = 322,
GLFW_KEY_KP_3 = 323,
GLFW_KEY_KP_4 = 324,
GLFW_KEY_KP_5 = 325,
GLFW_KEY_KP_6 = 326,
GLFW_KEY_KP_7 = 327,
GLFW_KEY_KP_8 = 328,
GLFW_KEY_KP_9 = 329,
GLFW_KEY_KP_DECIMAL = 330,
GLFW_KEY_KP_DIVIDE = 331,
GLFW_KEY_KP_MULTIPLY = 332,
GLFW_KEY_KP_SUBTRACT = 333,
GLFW_KEY_KP_ADD = 334,
GLFW_KEY_KP_ENTER = 335,
GLFW_KEY_KP_EQUAL = 336,
GLFW_KEY_LEFT_SHIFT = 340,
GLFW_KEY_LEFT_CONTROL = 341,
GLFW_KEY_LEFT_ALT = 342,
GLFW_KEY_LEFT_SUPER = 343,
GLFW_KEY_RIGHT_SHIFT = 344,
GLFW_KEY_RIGHT_CONTROL = 345,
GLFW_KEY_RIGHT_ALT = 346,
GLFW_KEY_RIGHT_SUPER = 347,
GLFW_KEY_MENU = 348,
GLFW_KEY_LAST = GLFW_KEY_MENU,
GLFW_KEY_ESC = GLFW_KEY_ESCAPE,
GLFW_KEY_DEL = GLFW_KEY_DELETE,
GLFW_KEY_PAGEUP = GLFW_KEY_PAGE_UP,
GLFW_KEY_PAGEDOWN = GLFW_KEY_PAGE_DOWN,
GLFW_KEY_KP_NUM_LOCK = GLFW_KEY_NUM_LOCK,
GLFW_KEY_LCTRL = GLFW_KEY_LEFT_CONTROL,
GLFW_KEY_LSHIFT = GLFW_KEY_LEFT_SHIFT,
GLFW_KEY_LALT = GLFW_KEY_LEFT_ALT,
GLFW_KEY_LSUPER = GLFW_KEY_LEFT_SUPER,
GLFW_KEY_RCTRL = GLFW_KEY_RIGHT_CONTROL,
GLFW_KEY_RSHIFT = GLFW_KEY_RIGHT_SHIFT,
GLFW_KEY_RALT = GLFW_KEY_RIGHT_ALT,
GLFW_KEY_RSUPER = GLFW_KEY_RIGHT_SUPER,
GLFW_MOUSE_BUTTON_1 = 0,
GLFW_MOUSE_BUTTON_2 = 1,
GLFW_MOUSE_BUTTON_3 = 2,
GLFW_MOUSE_BUTTON_4 = 3,
GLFW_MOUSE_BUTTON_5 = 4,
GLFW_MOUSE_BUTTON_6 = 5,
GLFW_MOUSE_BUTTON_7 = 6,
GLFW_MOUSE_BUTTON_8 = 7,
GLFW_MOUSE_BUTTON_LAST = GLFW_MOUSE_BUTTON_8,
GLFW_MOUSE_BUTTON_LEFT = GLFW_MOUSE_BUTTON_1,
GLFW_MOUSE_BUTTON_RIGHT = GLFW_MOUSE_BUTTON_2,
GLFW_MOUSE_BUTTON_MIDDLE = GLFW_MOUSE_BUTTON_3,
GLFW_JOYSTICK_1 = 0,
GLFW_JOYSTICK_2 = 1,
GLFW_JOYSTICK_3 = 2,
GLFW_JOYSTICK_4 = 3,
GLFW_JOYSTICK_5 = 4,
GLFW_JOYSTICK_6 = 5,
GLFW_JOYSTICK_7 = 6,
GLFW_JOYSTICK_8 = 7,
GLFW_JOYSTICK_9 = 8,
GLFW_JOYSTICK_10 = 9,
GLFW_JOYSTICK_11 = 10,
GLFW_JOYSTICK_12 = 11,
GLFW_JOYSTICK_13 = 12,
GLFW_JOYSTICK_14 = 13,
GLFW_JOYSTICK_15 = 14,
GLFW_JOYSTICK_16 = 15,
GLFW_JOYSTICK_LAST = GLFW_JOYSTICK_16,
GLFW_WINDOWED = 0x00010001,
GLFW_FULLSCREEN = 0x00010002,
GLFW_ACTIVE = 0x00020001,
GLFW_ICONIFIED = 0x00020002,
GLFW_CLOSE_REQUESTED = 0x00020003,
GLFW_OPENGL_REVISION = 0x00020004,
GLFW_RED_BITS = 0x00021000,
GLFW_GREEN_BITS = 0x00021001,
GLFW_BLUE_BITS = 0x00021002,
GLFW_ALPHA_BITS = 0x00021003,
GLFW_DEPTH_BITS = 0x00021004,
GLFW_STENCIL_BITS = 0x00021005,
GLFW_REFRESH_RATE = 0x00021006,
GLFW_ACCUM_RED_BITS = 0x00021007,
GLFW_ACCUM_GREEN_BITS = 0x00021008,
GLFW_ACCUM_BLUE_BITS = 0x00021009,
GLFW_ACCUM_ALPHA_BITS = 0x0002100A,
GLFW_AUX_BUFFERS = 0x0002100B,
GLFW_STEREO = 0x0002100C,
GLFW_WINDOW_NO_RESIZE = 0x0002100D,
GLFW_FSAA_SAMPLES = 0x0002100E,
GLFW_CLIENT_API = 0x00022000,
GLFW_OPENGL_VERSION_MAJOR = 0x00022001,
GLFW_OPENGL_VERSION_MINOR = 0x00022002,
GLFW_OPENGL_FORWARD_COMPAT = 0x00022003,
GLFW_OPENGL_DEBUG_CONTEXT = 0x00022004,
GLFW_OPENGL_PROFILE = 0x00022005,
GLFW_OPENGL_ROBUSTNESS = 0x00022006,
GLFW_RESIZABLE = 0x00022007,
GLFW_VISIBLE = 0x00022008,
GLFW_POSITION_X = 0x00022009,
GLFW_POSITION_Y = 0x0002200A,
GLFW_OPENGL_API = 0x00000001,
GLFW_OPENGL_ES_API = 0x00000002,
GLFW_OPENGL_NO_ROBUSTNESS = 0x00000000,
GLFW_OPENGL_NO_RESET_NOTIFICATION = 0x00000001,
GLFW_OPENGL_LOSE_CONTEXT_ON_RESET = 0x00000002,
GLFW_OPENGL_NO_PROFILE = 0x00000000,
GLFW_OPENGL_CORE_PROFILE = 0x00000001,
GLFW_OPENGL_COMPAT_PROFILE = 0x00000002,
GLFW_CURSOR_MODE = 0x00030001,
GLFW_STICKY_KEYS = 0x00030002,
GLFW_STICKY_MOUSE_BUTTONS = 0x00030003,
GLFW_KEY_REPEAT = 0x00030004,
GLFW_CURSOR_NORMAL = 0x00040001,
GLFW_CURSOR_HIDDEN = 0x00040002,
GLFW_CURSOR_CAPTURED = 0x00040003,
GLFW_PRESENT = 0x00050001,
GLFW_AXES = 0x00050002,
GLFW_BUTTONS = 0x00050003,
GLFW_NO_ERROR = 0,
GLFW_NOT_INITIALIZED = 0x00070001,
GLFW_NO_CURRENT_CONTEXT = 0x00070002,
GLFW_INVALID_ENUM = 0x00070003,
GLFW_INVALID_VALUE = 0x00070004,
GLFW_OUT_OF_MEMORY = 0x00070005,
GLFW_OPENGL_UNAVAILABLE = 0x00070006,
GLFW_VERSION_UNAVAILABLE = 0x00070007,
GLFW_PLATFORM_ERROR = 0x00070008,
GLFW_WINDOW_NOT_ACTIVE = 0x00070009,
GLFW_FORMAT_UNAVAILABLE = 0x0007000A,
GLFW_GAMMA_RAMP_SIZE = 256,
};
typedef void (*GLFWglproc)(void);
typedef struct GLFWmonitor GLFWmonitor;
typedef struct GLFWwindow GLFWwindow;
typedef void (* GLFWerrorfun)(int,const char*);
typedef void (* GLFWwindowposfun)(GLFWwindow*,int,int);
typedef void (* GLFWwindowsizefun)(GLFWwindow*,int,int);
typedef int (* GLFWwindowclosefun)(GLFWwindow*);
typedef void (* GLFWwindowrefreshfun)(GLFWwindow*);
typedef void (* GLFWwindowfocusfun)(GLFWwindow*,int);
typedef void (* GLFWwindowiconifyfun)(GLFWwindow*,int);
typedef void (* GLFWmousebuttonfun)(GLFWwindow*,int,int);
typedef void (* GLFWcursorposfun)(GLFWwindow*,int,int);
typedef void (* GLFWcursorenterfun)(GLFWwindow*,int);
typedef void (* GLFWscrollfun)(GLFWwindow*,double,double);
typedef void (* GLFWkeyfun)(GLFWwindow*,int,int);
typedef void (* GLFWcharfun)(GLFWwindow*,unsigned int);
typedef void (* GLFWmonitorfun)(GLFWmonitor*,int);
typedef struct {
int width;
int height;
int redBits;
int blueBits;
int greenBits;
} GLFWvidmode;
typedef struct {
unsigned short red[256];
unsigned short green[256];
unsigned short blue[256];
} GLFWgammaramp;
int glfwInit(void);
void glfwTerminate(void);
void glfwGetVersion(int* major, int* minor, int* rev);
const char* glfwGetVersionString(void);
void glfwSetErrorCallback(GLFWerrorfun cbfun);
GLFWmonitor** glfwGetMonitors(int* count);
GLFWmonitor* glfwGetPrimaryMonitor(void);
void glfwGetMonitorPos(GLFWmonitor* monitor, int* xpos, int* ypos);
void glfwGetMonitorPhysicalSize(GLFWmonitor* monitor, int* width, int* height);
const char* glfwGetMonitorName(GLFWmonitor* monitor);
void glfwSetMonitorCallback(GLFWmonitorfun cbfun);
const GLFWvidmode* glfwGetVideoModes(GLFWmonitor* monitor, int* count);
GLFWvidmode glfwGetVideoMode(GLFWmonitor* monitor);
void glfwSetGamma(GLFWmonitor* monitor, float gamma);
void glfwGetGammaRamp(GLFWmonitor* monitor, GLFWgammaramp* ramp);
void glfwSetGammaRamp(GLFWmonitor* monitor, const GLFWgammaramp* ramp);
void glfwDefaultWindowHints(void);
void glfwWindowHint(int target, int hint);
GLFWwindow* glfwCreateWindow(int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share);
void glfwDestroyWindow(GLFWwindow* window);
int glfwWindowShouldClose(GLFWwindow* window);
void glfwSetWindowShouldClose(GLFWwindow* window, int value);
void glfwSetWindowTitle(GLFWwindow* window, const char* title);
void glfwGetWindowPos(GLFWwindow* window, int* xpos, int* ypos);
void glfwSetWindowPos(GLFWwindow* window, int xpos, int ypos);
void glfwGetWindowSize(GLFWwindow* window, int* width, int* height);
void glfwSetWindowSize(GLFWwindow* window, int width, int height);
void glfwIconifyWindow(GLFWwindow* window);
void glfwRestoreWindow(GLFWwindow* window);
void glfwShowWindow(GLFWwindow* window);
void glfwHideWindow(GLFWwindow* window);
GLFWmonitor* glfwGetWindowMonitor(GLFWwindow* window);
int glfwGetWindowParam(GLFWwindow* window, int param);
void glfwSetWindowUserPointer(GLFWwindow* window, void* pointer);
void* glfwGetWindowUserPointer(GLFWwindow* window);
void glfwSetWindowPosCallback(GLFWwindow* window, GLFWwindowposfun cbfun);
void glfwSetWindowSizeCallback(GLFWwindow* window, GLFWwindowsizefun cbfun);
void glfwSetWindowCloseCallback(GLFWwindow* window, GLFWwindowclosefun cbfun);
void glfwSetWindowRefreshCallback(GLFWwindow* window, GLFWwindowrefreshfun cbfun);
void glfwSetWindowFocusCallback(GLFWwindow* window, GLFWwindowfocusfun cbfun);
void glfwSetWindowIconifyCallback(GLFWwindow* window, GLFWwindowiconifyfun cbfun);
void glfwPollEvents(void);
void glfwWaitEvents(void);
int glfwGetInputMode(GLFWwindow* window, int mode);
void glfwSetInputMode(GLFWwindow* window, int mode, int value);
int glfwGetKey(GLFWwindow* window, int key);
int glfwGetMouseButton(GLFWwindow* window, int button);
void glfwGetCursorPos(GLFWwindow* window, int* xpos, int* ypos);
void glfwSetCursorPos(GLFWwindow* window, int xpos, int ypos);
void glfwSetKeyCallback(GLFWwindow* window, GLFWkeyfun cbfun);
void glfwSetCharCallback(GLFWwindow* window, GLFWcharfun cbfun);
void glfwSetMouseButtonCallback(GLFWwindow* window, GLFWmousebuttonfun cbfun);
void glfwSetCursorPosCallback(GLFWwindow* window, GLFWcursorposfun cbfun);
void glfwSetCursorEnterCallback(GLFWwindow* window, GLFWcursorenterfun cbfun);
void glfwSetScrollCallback(GLFWwindow* window, GLFWscrollfun cbfun);
int glfwGetJoystickParam(int joy, int param);
int glfwGetJoystickAxes(int joy, float* axes, int numaxes);
int glfwGetJoystickButtons(int joy, unsigned char* buttons, int numbuttons);
const char* glfwGetJoystickName(int joy);
void glfwSetClipboardString(GLFWwindow* window, const char* string);
const char* glfwGetClipboardString(GLFWwindow* window);
double glfwGetTime(void);
void glfwSetTime(double time);
void glfwMakeContextCurrent(GLFWwindow* window);
GLFWwindow* glfwGetCurrentContext(void);
void glfwSwapBuffers(GLFWwindow* window);
void glfwSwapInterval(int interval);
int glfwExtensionSupported(const char* extension);
GLFWglproc glfwGetProcAddress(const char* procname);
]]
return glfw
-- test code:
local glfw = require "ffi.glfw"
local ffi = require "ffi"
assert(glfw.glfwInit() ~= 0, "failed to initialize GLFW")
print(string.format("using %s", ffi.string(glfw.glfwGetVersionString())))
--int width, int height, const char* title, GLFWmonitor* monitor, GLFWwindow* share)
local window = glfw.glfwCreateWindow(640, 480, "test", nil, nil)
assert(window ~= nil)
glfw.glfwSetKeyCallback(window, function(win, k, c) print("key", win, k, c) end)
while true do
glfw.glfwSwapBuffers(window)
glfw.glfwPollEvents()
--glfw.glfwWaitEvents() -- no PANIC if I use this instead of glfwPollEvents()
end
glfw.glfwTerminate()
Having this issue with glfwSetFramebufferSizeCallback :( It seems, glfwPollEvents calls the callback, so LuaJIT doen't know about it. If you disable jit for glfwPollEvents, it works:
local cb = function (window, width, height)
print(width, height)
end
glfw.glfwSetFramebufferSizeCallback(window, ffi.cast('GLFWframebuffersizefun', cb))
local poll_events = function ()
glfw.glfwPollEvents()
end
jit.off(poll_events)
while glfw.glfwWindowShouldClose(window) ~= 1 do
...
poll_events()
...
end
BUT with -jv
i see this:
[TRACE --- main.lua:48 -- call to JIT-disabled function at main.lua:43]
[TRACE --- main.lua:48 -- call to JIT-disabled function at main.lua:43]
[TRACE --- main.lua:48 -- blacklisted at main.lua:43]
It seems like the whole loop gets blacklisted (not jit-compilled?). Am I right?
I forgot to mention main.lua:48 is a line where the loop begins and main.lua:43 is where poll_events begins
With -jdump
I see (line numbers changed a bit but you get the idea):
---- TRACE 1 start main.lua:49
---- TRACE 1 abort main.lua:44 -- call to JIT-disabled function
---- TRACE 1 start main.lua:49
---- TRACE 1 abort main.lua:44 -- call to JIT-disabled function
---- TRACE 1 start main.lua:49
---- TRACE 1 abort main.lua:44 -- blacklisted
---- TRACE 1 start main.lua:49
---- TRACE 1 abort main.lua:44 -- blacklisted
---- TRACE 1 start main.lua:49
Seems that whole loop is blacklisted but I don't know what it means exactly :) http://wiki.luajit.org/Optimizations#Penalties-and-Blacklisting -- nothing there :(
Don't know if this is the problem, but using print() will abort a trace, and it looks like you have a print() in the callback.
No, it's turning off jit
, not print
. It doesn't show in log and if I comment out print
, nothing changes. Reaction on print
btw looks like this:
[TRACE --- main.lua:49 -- NYI: FastFunc print at main.lua:90]