Hi !
Featured games (91)
games approved by the League of Dukes
Games in Showcase (803)
Games in Android Showcase (237)
games submitted by our members
Games in WIP (867)
games currently in development
News: Read the Java Gaming Resources, or peek at the official Java tutorials
    Home     Help   Search   Login   Register   
Pages: [1]
  ignore  |  Print  
  Possible to manually "start X" instead of -XstartOnFirstThread?  (Read 3645 times)
0 Members and 1 Guest are viewing this topic.
Offline theagentd
« Posted 2016-08-22 22:37:37 »


I've made this fancy-schmancy GLFW event handling system with LWJGL 3 that dedicates a thread to input processing while respecting all the threading limitations of GLFW (trust me, that was hard). I'd fire up a new thread and dedicate it to GLFW commands so that rendering/updating doesn't affect the responsiveness of the window or input event recording precision. However, when running this code on Mac it's broken since I need to use the -XstartOnFirstThread VM command... which breaks everything since I want to "start X" (whatever that means) on different thread than the main thread: the dedicated GLFW thread. This leads to the extremely awkward position where I need to do everything backwards, and dedicate the main thread to GLFW and transfer control of the entire game to a new thread instead. This is intrusive as f**k, reduces readability and has already caused hard-to-find bugs for us.

Is there any way of manually doing the equivalent of -XstartOnFirstThread but on a thread of our choosing?

Offline HeroesGraveDev

JGO Kernel

Medals: 383
Projects: 11
Exp: 4 years

┬─┬ノ(ಠ_ಠノ)(╯°□°)╯︵ ┻━┻

« Reply #1 - Posted 2016-08-22 23:51:21 »

It's Apple (specifically, the Cocoa API developers/designers) being a special snowflake, and AFAIK there's nothing you can do about it.

Same problem occurs no matter what language you use. It's just that most (native) languages don't start on a new thread by default, so single-threaded applications aren't affected.

Offline Ecumene

JGO Kernel

Medals: 200
Projects: 4
Exp: 8 years

I did not hit her! I did not!

« Reply #2 - Posted 2016-08-23 00:07:35 »

Why not move the GLFW stuff to start on the main thread, and the game run on a separate thread? ( That may take a ludicrous amount of time, depending on the game )

Games published by our own members! Check 'em out!
Legends of Yore - The Casual Retro Roguelike
Offline theagentd
« Reply #3 - Posted 2016-08-23 01:22:58 »

Why not move the GLFW stuff to start on the main thread, and the game run on a separate thread? ( That may take a ludicrous amount of time, depending on the game )
That's exactly what I'm doing right now, but it's ugly. Forcing the user to move the entire game to a new thread and doing some seemingly arbitrary unintuitive calls is what I'm trying to avoid. The cleanest solution of this kind is to abstract the entire thing away and have the player give a "game interface" to an engine, which handles the thread hand-over. I don't want to force the user to do this shit, and I don't want to surprise them 6 months into development with having to do hacky shit like this to make it work on Apple.

I had a long chat session with Spasi over Skype, and got some more info on why this is required on Mac and how to work around it. The "cleanest" solution for the user is to create a small native C program which fires up a JVM using the Invocation API. It'd create a new thread for the application and call the application's main() method, then start the GLFW event handling loop on the main thread. The Java code then just needs to realize that the event handling thread will be created externally.

I'd prefer this solution in the long run since I'd rather require a hack for getting the engine to run on Mac than have the user manually work around limitations of Mac to get anything at all to run.

Offline nsigma
« Reply #4 - Posted 2016-08-23 09:23:01 »

Just to make this clearer, or to be a complete pedant  Grin

This has nothing to do with anything called "X".  -X just means this is a non-standard option for the JVM.

Praxis LIVE - hybrid visual IDE for (live) creative coding
Offline theagentd
« Reply #5 - Posted 2016-08-23 12:05:02 »

Yeah, I realized that from Spasi's explanation. It just forces the entire VM to start on the first thread of the process, which due to Mac's stupid limitations is the only thread that can do UI stuff. Usually it'd dedicate the first thread to AWT/Swing just for this purpose. It's just stupid.

Pages: [1]
  ignore  |  Print  

Riven (397 views)
2019-09-04 15:33:17

hadezbladez (5280 views)
2018-11-16 13:46:03

hadezbladez (2204 views)
2018-11-16 13:41:33

hadezbladez (5544 views)
2018-11-16 13:35:35

hadezbladez (1150 views)
2018-11-16 13:32:03

EgonOlsen (4584 views)
2018-06-10 19:43:48

EgonOlsen (5462 views)
2018-06-10 19:43:44

EgonOlsen (3119 views)
2018-06-10 19:43:20

DesertCoockie (4015 views)
2018-05-13 18:23:11

nelsongames (4708 views)
2018-04-24 18:15:36
A NON-ideal modular configuration for Eclipse with JavaFX
by philfrei
2019-12-19 19:35:12

Java Gaming Resources
by philfrei
2019-05-14 16:15:13

Deployment and Packaging
by philfrei
2019-05-08 15:15:36

Deployment and Packaging
by philfrei
2019-05-08 15:13:34

Deployment and Packaging
by philfrei
2019-02-17 20:25:53

Deployment and Packaging
by mudlee
2018-08-22 18:09:50

Java Gaming Resources
by gouessej
2018-08-22 08:19:41

Deployment and Packaging
by gouessej
2018-08-22 08:04:08 is not responsible for the content posted by its members, including references to external websites, and other references that may or may not have a relation with our primarily gaming and game production oriented community. inquiries and complaints can be sent via email to the info‑account of the company managing the website of java‑
Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines | Managed by Enhanced Four Valid XHTML 1.0! Valid CSS!