Skip to content
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

Only one asynchronous task per animation can be scheduled #517

Open
pontaoski opened this issue Jan 6, 2022 · 4 comments
Open

Only one asynchronous task per animation can be scheduled #517

pontaoski opened this issue Jan 6, 2022 · 4 comments

Comments

@pontaoski
Copy link

The documentation doesn't mention this, so it seems like you should be able to schedule as many tasks as you want for a single animation. However, trying to do so results in a crash, and looking at the source reveals that the animation can only hold one async task at a time.

@smohantty
Copy link
Contributor

@pontaoski ,
The idea of render() api returning future is user don't have to wait till the rendering finish . whenever user needs the result can get it from the future. Yes Animation instance can't render multiple frames simultaneously because internally it keeps one render tree and updates it for requested frame before rendering.

If you need to generate animation frames for a single resource , then can be done by creating 2 or more animation object with same resource and request different non-overlapping frames from respective animation object.

Just curious do you have any usecase where you need more than one frame at a time ?

@pontaoski
Copy link
Author

I'm using rlottie to implement showing lottie images in a GUI app; the toolkit has an API for animated image formats that consists of essentially loadImage, numFrames, imageForFrame.

What I was hoping to do was something along the lines of this in the loadImage implementation:

std::vector<std::future<Surface>> futures;
for (int i = 0; i < numFrames; i++) {
    futures.push_back(animation.render(i));
}

so that I could queue up all the frames to render in the background, only needing to block to wait on a future if the toolkit requests a specific frame from the image with imageForFrame.

@smohantty
Copy link
Contributor

@pontaoski ,
The above code will simplify your logic but will take lot of memory , as some animations have more than 1000 frames in that case you will end up creating those many buffers.

I will do something like this below.

loadImage()
{
Animation* obj = new Animation();
// request to render the 1st frame
Future req = obj->render(0);
pending_frame = 0;
}

imageForFrame( reqId )
{
if ( reqId == pending_frame){
req.get();
}
// speculatively render the next frame
Future req = obj->render(reqid++);
}`

but then it all depends what the request pattern from the Uitoolkit does it needs all the frames at one time or 1 frame at a time.

@pontaoski
Copy link
Author

there's no way to "cancel" a pending render, right? so i would need a second animation for the case when the toolkit requests a frame that isn't what's being rendered

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants