PDA

View Full Version : Trouble with TBGL_MouseGetLButton ?



dcromley
22-03-2016, 06:28
Hello again,

When I run this script and hit the left mouse button every second or so, it hangs up after 5 or so seconds. "Not responding". The "close" box turns red; I'm at 1.9.16.16, Windows 10. Thanks in advance, Dave


Uses "TBGL"

Global hWnd, hFont As DWord
Global s1 As String

s1 = "ESC to exit"
hWnd = TBGL_CreateWindowEx( _
s1, 1024, 742, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_UseVSync 1
hFont = TBGL_FontHandle("Courier New", 12)
TBGL_BuildFont hFont
TBGL_ShowWindow
TBGL_UseLighting %FALSE
TBGL_UseLightSource %GL_LIGHT0, %TRUE
TBGL_ResetKeyState()
Do While TBGL_IsWindow(hwnd)
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Stop
TBGL_ClearFrame
TBGL_Camera 1,1,5, 0,0,0
TBGL_Color 255,255,255
TBGL_UseLighting %FALSE
TBGL_PrintFont TBGL_MouseGetLButton, -1,1,0
TBGL_DrawFrame
Loop

Petr Schreiber
22-03-2016, 08:03
Hello, dear mister bug hunter!

This sure looks like an issue. I think it is related to the DO WHILE ... LOOP, because when you refactor the code to this equivalent, the problem is gone:


Uses "TBGL"

Global hWnd, hFont As DWord
Global s1 As String

s1 = "ESC to exit"
hWnd = TBGL_CreateWindowEx( _
s1, 1024, 742, 32, %TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)

TBGL_UseVSync 1

hFont = TBGL_FontHandle("Courier New", 12)
TBGL_BuildFont hFont
TBGL_ShowWindow

TBGL_UseLighting %FALSE
TBGL_UseLightSource %GL_LIGHT0, %TRUE

TBGL_ResetKeyState()

While TBGL_IsWindow(hwnd)
If TBGL_GetWindowKeyState(hWnd, %VK_ESCAPE) Then Stop
TBGL_ClearFrame
TBGL_Camera 1,1,5, 0,0,0
TBGL_Color 255,255,255
TBGL_UseLighting %FALSE
TBGL_PrintFont TBGL_MouseGetLButton, -1,1,0
TBGL_DrawFrame
Wend



Petr

ErosOlmi
22-03-2016, 08:10
Ciao

I think the problem is related to the fact that main loop does not give any time to process events.

There are two ways to solve:

Add a DoEvents inside the loop

Do While TBGL_IsWindow(hwnd)
...
DoEvents
Loop
Use WHILE/WEND instead of DO/LOOP. WHILE/WEND has an automatic DoEvents inside it:

While TBGL_IsWindow(hwnd)
...
Wend



I think the best is to use WHILE/WEND in all situations where a unknown loop (a loop where is not known how many cycles will be executed) is needed.
I will add into manual some indications about this behave.


PS: Petr, we posted quite the same time.

dcromley
22-03-2016, 18:12
Thanks again. You guys are Johnny-on-the-spot (http://www.merriam-webster.com/dictionary/Johnny%E2%80%93on%E2%80%93the%E2%80%93spot).