View Full Version : "Exit While" works, but "Exit Do" hangs up in TBGL loops
dcromley
10-03-2016, 19:14
I want to advance to the next figure when I hit TAB. In this script, Loop1 using "Exit While" works, but Loop2 using "Exit Do" hangs up. (Windows 10 - Thinair 1.9.16.11)
So run this script and hit TAB 3 times. It should show figures 1, 2, 3, and 4, but it hangs up after figure 3.
Uses "TBGL"
Global hWnd As DWord, n, fignum As Long
Sub TBMain()
Local s1 As String = "ESC to quit; TAB to advance"
hWnd = TBGL_CreateWindowEx(s1, 640, 480, 32,
%TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_UseVSync 1
Dim hFont As DWord = TBGL_FontHandle("Courier New", 12)
TBGL_BuildFont( hFont )
TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 5, 15, 1)
TBGL_ResetKeyState()
fignum = 1
Loop1() ' shows fig 1 -- hitting TAB advances to the fig 2
Loop1() ' shows fig 2 -- hitting TAB advances to the fig 3
Loop2() ' shows fig 3 -- hitting TAB hangs up the program
Loop2() ' never gets to here
End Sub
Sub Loop1() ' uses "While .. Wend" -- "Exit While" is OK
While TBGL_IsWindow(hWnd)
TBGL_ClearFrame
TBGL_Camera(1, 1, 5, 0, 0, 0)
TBGL_UseLighting(%FALSE)
n += 1
TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
TBGL_UseLighting(%TRUE)
If fignum = 1 Then
TBGL_Box(1, 1.4, 2) ' figure 1
Else
TBGL_Box(2, 1.4, 1) ' figure 2
End If
TBGL_DrawFrame
If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit While
If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
Wend
fignum += 1
End Sub
Sub Loop2() ' uses "Do While .. Loop" -- "Exit Do" hangs up
Do While TBGL_IsWindow(hWnd)
TBGL_ClearFrame
TBGL_Camera(1, 1, 5, 0, 0, 0)
TBGL_UseLighting(%FALSE)
n += 1
TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
TBGL_UseLighting(%TRUE)
If fignum = 3 Then
TBGL_Box(1, 1.4, 2) ' figure 3
Else
TBGL_Box(2, 1.4, 1) ' figure 4
End If
TBGL_DrawFrame
If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit Do
If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
Loop
fignum += 1
MsgBox 0, "!!" ' never gets here
End Sub
ErosOlmi
10-03-2016, 19:40
Can you please install thinBasic 1.9.16.16 and see if problem is still there?
Especially in version 1.9.16.11 there were some serious bugs: http://www.thinbasic.com/community/showthread.php?12600
Let me know.
Eros
Petr Schreiber
10-03-2016, 19:52
Hi,
tried it with thinBASIC 1.9.16.16 and no problems observed.
Petr
dcromley
11-03-2016, 00:29
Yes, the latest thinBasic works. As usual, thank you for your speedy response.
dcromley
11-03-2016, 00:47
I find that running the script and getting to figure 3, that the "close icon" (the "X") doesn't work. Do you find that?
Hi dcromley
yes the 'X' hangs on the 3rd run BUT: (my opinion only):
there is a possibility that using :
While TBGL_IsWindow(hWnd), or
Do While TBGL_IsWindow(hWnd)
instead of usual loops several times are dangerous, this like riding a helicopter to visit your neighbor 20 meters away. this is just a guess and not a scientific proof , depends on knowing that TBGL_IsWindow(hWnd) is a big thing and not a usual loop.
instead i will use a less important loop:
While TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) = %FALSE
and seems it runs okay with your program:
Uses "TBGL"
Global hWnd As DWord, n, fignum As Long
Sub TBMain()
Local s1 As String = "ESC to quit; TAB to advance"
hWnd = TBGL_CreateWindowEx(s1, 640, 480, 32,
%TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_UseVSync 1
Dim hFont As DWord = TBGL_FontHandle("Courier New", 12)
TBGL_BuildFont( hFont )
TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 5, 15, 1)
TBGL_ResetKeyState()
fignum = 1
Loop1() ' shows fig 1 -- hitting TAB advances to the fig 2
Loop1() ' shows fig 2 -- hitting TAB advances to the fig 3
Loop2() ' shows fig 3 -- hitting TAB hangs up the program
Loop2() ' never gets to here
End Sub
Sub Loop1() ' uses "While .. Wend" -- "Exit While" is OK
While TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) = %FALSE
'While TBGL_IsWindow(hWnd)
TBGL_ClearFrame
TBGL_Camera(1, 1, 5, 0, 0, 0)
TBGL_UseLighting(%FALSE)
n += 1
TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
TBGL_UseLighting(%TRUE)
If fignum = 1 Then
TBGL_Box(1, 1.4, 2) ' figure 1
Else
TBGL_Box(2, 1.4, 1) ' figure 2
End If
TBGL_DrawFrame
'If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit While
If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
Wend
fignum += 1
End Sub
Sub Loop2() ' uses "Do While .. Loop" -- "Exit Do" hangs up
'While TBGL_IsWindow(hWnd) 'Do While TBGL_IsWindow(hWnd)
While TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) = %FALSE
TBGL_ClearFrame
TBGL_Camera(1, 1, 5, 0, 0, 0)
TBGL_UseLighting(%FALSE)
n += 1
TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
TBGL_UseLighting(%TRUE)
If fignum = 3 Then
TBGL_Box(1, 1.4, 2) ' figure 3
Else
TBGL_Box(2, 1.4, 1) ' figure 4
End If
TBGL_DrawFrame
'If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit Do
If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
Wend 'Loop
fignum += 1
MsgBox 0, "!!" ' never gets here
End Sub
dcromley
11-03-2016, 19:08
Primo,
Thanks for your thoughtful post. This script is your last post with Loop1 removed. The only reason I had 2 loops was to demonstrate the difference between "While .. Wend" and "Do While .. Loop". This script is smaller.
BUT: when I run your (or this) script and hit the "Close" icon, I get the dangling "Background Process" titled "thinBasic Programming Language" running, and I have to end it using Task Manager. Do you have this issue?
This issue (a [inadvertent] dangling process left without any window(s)) has been brought up in other threads.
Uses "TBGL"
Global hWnd As DWord, n, fignum As Long
Sub TBMain()
Local s1 As String = "ESC to quit; TAB to advance"
hWnd = TBGL_CreateWindowEx(s1, 640, 480, 32,
%TBGL_WS_WINDOWED Or %TBGL_WS_CLOSEBOX)
TBGL_ShowWindow
TBGL_UseVSync 1
Dim hFont As DWord = TBGL_FontHandle("Courier New", 12)
TBGL_BuildFont( hFont )
TBGL_UseLightSource(%GL_LIGHT0, %TRUE)
TBGL_SetLightParameter(%GL_LIGHT0, %TBGL_LIGHT_POSITION, 15, 5, 15, 1)
TBGL_ResetKeyState()
fignum = 3
Loop2() ' shows fig 3
Loop2() ' shows fig 4
End Sub
Sub Loop2()
'While TBGL_IsWindow(hWnd) 'Do While TBGL_IsWindow(hWnd)
While TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) = %FALSE
TBGL_ClearFrame
TBGL_Camera(1, 1, 5, 0, 0, 0)
TBGL_UseLighting(%FALSE)
n += 1
TBGL_PrintFont("Figure " & fignum & " - " & n, -1, 1, 0)
TBGL_UseLighting(%TRUE)
If fignum = 3 Then
TBGL_Box(1, 1.4, 2) ' figure 3
Else
TBGL_Box(2, 1.4, 1) ' figure 4
End If
TBGL_DrawFrame
'If TBGL_GetWindowKeyOnce(hWnd, %VK_TAB) Then Exit Do
If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Then Stop
Wend 'Loop
fignum += 1
End Sub
dcromley,
this will make it exit without thinbasic.exe stay in memory, so change line 36 like this:
If TBGL_GetWindowKeyOnce(hWnd, %VK_ESCAPE) Or Not TBGL_IsWindow(hWnd) Then Stop
this is tested in windows xp/32
what is the name of the toy in your Avatar ? is it a gyroscope ? i have uploaded its image to images.google.com but it show only the avatar in thinbasic
Petr Schreiber
11-03-2016, 23:31
Hi friends,
the TBGL_IsWindow is actually just a wrapper for https://msdn.microsoft.com/en-us/library/windows/desktop/ms633528%28v=vs.85%29.aspx from Win32.
It is not as helicopterish, as it might look, and it is safe to use.
Petr
dcromley
12-03-2016, 04:32
Thanks guys.
My avatar comes from a TBGL program I wrote 4+ years ago.
The link to the thread is GimbalRock (http://www.thinbasic.com/community/showthread.php?11486-GimbalRock-demo-of-rotations-via-gimbals)
and the link to the zip package is GimbalRockZip (http://www.thinbasic.com/community/attachment.php?attachmentid=7661&d=1322325668)