EmergentOrganization / cell-rpg

:black_square_button: connect to a universe where cellular automata have run rampant
http://emergentorganization.github.io/bridge/
Other
12 stars 1 forks source link

Gdx.graphics.setDisplayMode sometimes causes hang #93

Closed 7yl4r closed 8 years ago

7yl4r commented 8 years ago

Occasionally I will start the desktop launcher and find that the app has become non-responsive before the screen re-sizes from the starting size of 100x100. I have to force-close the application when this happens. I don't see any pattern; this seems to occur randomly, about 1/5 times I run the application.

Based on the debug statements I've added it seems that the hangup is on Gdx.graphics.setDisplayMode. Why? I have no idea. A quick google search didn't reveal any hints.

Can someone confirm this is not just local to my machine?

BrianErikson commented 8 years ago

I've never had that happen myself. Has this been happening for a while, or after a specific commit possibly?

7yl4r commented 8 years ago

It's fairly recent. I would guess that it started in de047e8afcc9123103d283e67ffcfa235c717063. Since then I've added some print statement in DesktopLauncher to help debug, but haven't been able to figure it out.

7yl4r commented 8 years ago

image

This is what it looks like. Note how the debug statements indicate that everything seems fine up until the call to setDisplayMode

BrianErikson commented 8 years ago

I could possibly see a conflict with using Gdx.Preferences in the DesktopLauncher -- maybe Gdx launches asynchronously and sometimes things initialize in different orders, thus causing the hang? Maybe sticking a timed delay in there will alleviate the issue?

7yl4r commented 8 years ago

I think you're right. There's something asynch, and so we've got a race condition. Adding a delay will likely fix it.

7yl4r commented 8 years ago

Very strange, c7a9746 actually has made the problem worse. It seems that the race condition might be opposite of how we expected. Gdx.setDisplayMode has to be called before PixelonTransmission is finished.

7yl4r commented 8 years ago

Running the test class added in fe7a9c0 reproduces this every time for me. Can you try to reproduce it @BrianErikson?

orelb commented 8 years ago

As I see it now, the only problem is accessing the preferences to get the window size to set it initially, which can't happen since the preferences are initialized when you instantiate the window by the LwjglApplication class:

new LwjglApplication(new PixelonTransmission(), config);

Any call to Gdx.graphics.setDisplayMode() after the application initialization seems to freeze the game. The underlying cause might be on behalf of Gdx or even Lwjgl. I'm going to test it now.

Edit: I'm wrong. The screen freeze only seems to happen when fetching the desktop display mode. LwjglApplicationConfiguration.getDesktopDisplayMode();

Edit 2: 343b585f1f54c6954aa87280d597e9a08149e9e2, I tried omitting the desktop display fetch which I thought at first fixed the issue, but the window still acts weird (not being resized, freezes)

Edit 3: This seems to work. I have no idea how to commit a change to the emergent2dcore submodule, so here's a gist: https://gist.github.com/orelbitton/87a8edb0765a2a5b357c

orelb commented 8 years ago

Solved @ https://github.com/EmergentOrganization/emergent2dcore/commit/080b7a3108e0e4dcd211589f9c1d2bcd3fc5ad47