-
Notifications
You must be signed in to change notification settings - Fork 23
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix to _desktopwidth, _desktopheight, _screenicon #60
Conversation
Fixes the issue as brought up on the forums here: https://qb64phoenix.com/forum/showthread.php?tid=408 Also added a small set of logic so we don't end up inside an endless loop if the screen is hidden (via _SCREENHIDE), or if it doesn't exist for whatever reason.
while (!window_exists) { | ||
Sleep(100); | ||
} | ||
//while (!window_exists) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Don't leave commented code in the file :) If someone wants to see what was there before they can check the git
history.
|
||
int32 waited_enough = 20; | ||
|
||
while (!window_handle&&waited_enough>0) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think you're right that glutGet()
for these parameters doesn't require an open window. We should see if we can add some test cases for that, but either way I'd rather we just drop the check instead of add a timeout.
internal/c/libqb.cpp
Outdated
} | ||
# endif | ||
if (waited_enough == 0) | ||
return; // if the screen isn't created and doesn't have a handle after two seconds, then just return and don't try to minimize the window. | ||
glutIconifyWindow(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think the actual underlying problem is that we're trying to call glutIconifyWindow()
from outside the main thread using GLUT. Google indicates that FreeGLUT itself is not thread safe, and a quick look at the source code seems to back that up. So with that being the case, we cannot call glutIconifyWindow()
here anyway, it doesn't matter if the window is setup or not. It might work, but it could easily have problems if the thread doing the GLUT work happens to be doing the wrong thing at the time.
The proper way to solve this problem would be to set some kind of flag or otherwise notify the thread GLUT is being used on to call glutIconifyWindow()
itself. That has the added benefit that notifying the other thread does not require us to wait for the GLUT thread to do the work, so the busy waiting problem being addressed here also goes away. Notifying the thread can also be done regardless of the current state of GLUT itself and whether a window has already been opened or not.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I created #66 for this.
Having windows call GetSystemMetrics without relying on glutGet, gets rid of the seg fault that can occur at program start up. screenicon was restored to it's previous state so that larger issues with it can be addressed at a future date.
return glutGet(GLUT_SCREEN_WIDTH); | ||
#else | ||
# ifdef QB64_WINDOWS | ||
#ifdef QB64_WINDOWS | ||
return GetSystemMetrics(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's a small thing, but there are constants you're intended to use for GetSystemMetrics()
rather than hard-coded values. You should try swapping 0
for SM_CXSCREEN
and 1
for SM_CYSCREEN
, it makes it much easier to know what's going on. Hopefully those constants are already available in this file via the #include
s, if they can't be found then I'm fine leaving it as-is :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'd like you to give the SM_CXSCREEN
and SM_CYSCREEN
thing a try if you don't mind, but otherwise looks good to me :)
Fixes the issue as brought up on the forums here: https://qb64phoenix.com/forum/showthread.php?tid=408
Also added a small set of logic so we don't end up inside an endless loop if the screen is hidden (via _SCREENHIDE), or if it doesn't exist for whatever reason.