question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Posting lazy runnables

See original GitHub issue

If you call Gdx.app.postRunnable(), all the backends also call Gdx.graphics.requestRendering() (except Lwjgl3Application for some reason, and GwtApplication which doesn’t support non-continuous rendering).

If you’re using non-continuous rendering, this means you need to create your own solution for lazily doing something the next time rendering occurs, such as your own Runnable manager that is called at the beginning of render(). If you have a multi-window application (or an Android live wallpaper / screen saver), then you can’t simply make this manager static either. You have to pass it around everywhere or do weird workarounds like this or this.

I ran into this problem because I was trying to set some things to be freed to pools at the end of the frame. But that triggers the next call to render(), so everything is needlessly drawn again, and new items need to be returned to the pool again, and we now have a continuous rendering cycle.

So I’m proposing either:

  1. Remove Gdx.graphics.requestRendering() calls from the backends that automatically call it when you post a runnable. This breaks current behavior, but it was already inconsistent behavior between backends. People using non-continuous rendering are probably a minority, but will probably also appreciate the extra control given by having the choice of whether a runnable should also trigger rendering.

  2. Add Gdx.app.postLazyRunnable(Runnable runnable).

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:7 (7 by maintainers)

github_iconTop GitHub Comments

2reactions
MrStahlfelgecommented, Nov 14, 2020

I am in favor of solution 1.

Which one do you prefer btw?

1reaction
cypherdarecommented, Nov 15, 2020

You mean if we go for option 1, right?

Doing a where-used search in the library shows that it is used all over the place in the various backends, and usually in response to events where you would want to trigger a render when using non-continuous rendering.

That kind of makes me lean towards option 2 (and fixing the Lwjgl3 backend to behave correctly). Maybe I underestimated how often people would rely on this feature, since we’ve used it extensively in the backends.

If we went with option 1, we would need to carefully add manual calls to requestRendering almost everywhere libGDX calls postRunnable.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Is lazy initialization worthy to be for small piece of code?
I have singleton A.class . Runnable loadTask may be evoked or not, that's why I'm thinking about lazy initialization. I'm concerned about memory ......
Read more >
Android Handler Memory Leaks - Medium
Once you post Runnable or Message into Handler , it's then stored in list of Message commands referenced from LooperThread until the message...
Read more >
A Lazy Developers Introduction to Java Concurrency Executors
The submit method of the ExecutorService is overloaded and accepts either a Callable or Runnable. Since the run method of the Runnable returns ......
Read more >
EFCore 3.1 lazy loading makes some navigational properties ...
I am not 100% sure how to reproduce this, but I think the StackOverflow post shows it pretty well. I'll give you an...
Read more >
A blocking lazy sequence populated by multiple worker threads
the following would need to reify itself to be a Runnable, not got that far yet :) (defn execute [job result-queue] (let [result...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found