Fix waitFor not being implemented in lwjgl3 - #1048
Conversation
|
Not sure why the compare is not working correctly, only a couple lines changed... |
|
Probably you checked the file in with a different line ending. You may want to fix it as it's harder to see what actually changed. |
|
Ah, I did not think about that. I'll fix it right now |
|
FYI: https://github.blog/2018-05-01-ignore-white-space-in-code-review/ Note though that this still means we don't want "unclean" commits, as git tools might not ignore whitespaces and it's not clear which line ending/white space is the correct one. Actually we should have linters/auto formatters as bots which comment on the PRs :) |
|
Or I sort of remember that it's possible to set line ending style on the repo or something... but that may make a whole bunch of source change because I don't believe it's consistent right now. |
| } | ||
|
|
||
| // NOTE: this is required for Mac OS X! | ||
| mainThread = Thread.currentThread(); |
There was a problem hiding this comment.
I know what they are doing here and your method might break OSX support. Do some research on the hub please:
For OpenGL to work on Mac OS X it has to be started on the MainThread (which is the Thread the Application is started with, hence Thread.currentThread(). Your change destroys this. So it changes semantics.
WaitFor() might be useless because if you're already on the MainThread, you don't have to wait for it.
But it's an inconsistent behavior as lwjgl2 probably returns from the Application#start() call.
So a proper solution would be to document this or provide AppSettings to enable "forking", unless on OS X.
Or always use the CurrentThread, which to me is expectable if you hand control over to a framework.
There was a problem hiding this comment.
Would it be better to check if we are on OS X, then ignore the wiatFor. Also, does this mean that jme-lwjgl does not work on OS X?
There was a problem hiding this comment.
Yes, this is probably better, but I don't like it cause we'd have an OS dependant behavior then. I need to triple check that with lwjgl3, but as pointed out in #1193, VR has the same problem.
lwjgl2 however is capable of working on Mac OS X, which is related to the way it creates the window, I guess. Which is why we need to double check things and re-check the above assumption. I guess I need to try that on mac.
02cb54d to
4c86de0
Compare
|
OK I have line endings fixed. |
|
I would also like to note, that with LWJGL3, the headless context does return from start, which makes inconsistent behavior within the library itself. |
|
OK, I just made a new commit. If waitFor is false, we run it on the main thread, otherwise, create a new thread. How about this solution? |
|
I do not have an apple computer, perhaps someone can test this? |
|
Just for documentation purpose, it was issue #433 that has the os x workaround info in it. I have tested this proposed fix on my apps in windows, and I think it is ready but still needs tested in OS X. Any thoughts? Thanks, |
|
Perhaps someone at the Forum would be willing to help us. |
|
What exactly needs to be tested here? Is there some sort of test case to run? |
|
Just needs to be tested in a working application. Behavior should not change on OS X and that needs to be confirmed. |
|
Sorry for not reacting on this so long, I've just re-encountered this without the PR:
I think your PR addresses the first point, but not the second one? [Which would at least be one improvement] Edit: Forgot to say: the current behavior is required on Mac OS X regardless of the waitFor, since start() may NOT return, since we have to run on that thread. Edit2: Here's a read up on why things are like they are: LWJGL/lwjgl3#311 Edit3: It is a problem. Most GLFW functions are required to be called from the main thread, which also has to be the first thread on macOS (see -XstartOnFirstThread). The javadoc of each function mentions if it's callable from any thread or only from main. This is neither an LWJGL nor a GLFW limitation; it's the only way to write a usable cross-platform windowing system. Your application may work on Windows, but will certainly fail on macOS. Note that this applies to GLFW functions only; OpenGL contexts can be made current in other threads and those threads can be used for rendering. So a separate rendering thread is possible, but then all calls like resizing the window will fail as the main thread aka. first thread has already exited... Edit 4: https://www.glfw.org/docs/latest/group__input.html#ga1caf18159767e761185e49a3be019f8d |
|
Okay, so after Review in #1248, I think this PR cannot work like this, it needs a more complicated approach, which I didn't manage to do. The thing is: the GLFW docs say you must not access these functions (most of initInThread) from outside the main thread. They say it's because some platforms require that. I don't know if that will lead to exceptions or work on all those other platforms (i.e. not working on mac os soley), but it's discouraged by the docs. I think we have to accept that behavior, because everything else gives additional problems, starting with context restarts and a proper app shutdown. For now I'd recommend discussing on #1248 about our options. |
|
@MeFisto94 thank you for looking into this. I am not sure why the documentation is so unclear on LWJGL's side on this, but I have been using a different thread for quite some time now in my applications be using this approached: Thread t = new Thread() {
@Override
public void run() {
jme.start();
}
};
t.start();This was taken right from a working application. I have only tested it in windows though. Using JME3 LWJGL3. Perhaps this only works in Windows...? |
Because it's a limitation of glfw and their Docs state this clearly.
And Linux, but it seems to just crash on Mac OS. So while it's forbidden you can get away with that on most platforms. |
|
I'm confused about the status of this PR. Does it need code changes? Testing? Or just integration? |
|
From what I've gathered, there isn't a good way to maintain the previous functionality with lwjgl3 on all platforms. Creating a new thread will crash on OSX. So this isn't really a simple fix, because we can't match the lwjgl2 functionality. |
|
What Jeddic says, we're violating the docs/contract when creating a new thread. I tried a different way but failed. It's a problem: Currently one cannot use start(false) and thus the thread calling into app.start() is locked forever, which is bad for Editors/SDKs. With this PR, that would work on Windows and Linux but crash the JVM on Mac OS X. I don't know if some (if Mac OS waitFor == true) would work, but we might need to find a solution to the glfw problems anyway |
|
That is what this PR does. It keeps Mac os on main thread, and forks for everything else. EDIT: @MeFisto94 I did not look at the username to realize I was replying to you. I know you know what this PR is. Sorry about that. |
So this seems like a big bug to me. I noticed that for some reason for the lwjgl 3 display context, the wait for was being ignored. There was a comment about a OSX fix, but with no information to go with it.
It seems to me that it is important for the waitFor to work, as it broke one of my applications that I was swapping from lwjgl2 to lwjgl3.
Does anyone know about this, or can provide insight into this?
This PR adds support for the waitFor in the same way that it was implemented in lwjgl2.
Also, if someone can confirm that this still works for them, that would be great.
PS: I hope I opened this PR correctly. If not I'm sorry in advance, every project has their preferred way of doing things.
Thank you,
Trevor Flynn