Getting render progress stats

Hi all! I’m working on a way to get render stats from a blender process running in the background. I’ve been looking at the render_stats() callback but it doesn’t seem to get the stats, it gets a None instead.

BLI_callback_exec(G.main, NULL, BLI_CB_EVT_RENDER_STATS);

(from pipeline.c, stats_background())

However the original patch (and commit) seemed to pass the stats:
https://dev-files.blender.org/file/data/2p4tya7zx7jbqzodsgmx/PHID-FILE-3vszp5oxr4k6yid4vo2s/stats_callback.patch

I searched around the git log but can’t find exactly when/why this changed. Is this a bug or is there another way to get the stats? I’d like to avoid parsing stdout if I can :grimacing:

There were never render stats passed to Python I’m afraid. The code in that patch can’t work since the render stats would have to RNA wrapped and exposed, just casting it to an ID* makes no sense.

As far as I know the only solution is to capture stdout.

I see, well I guess I could do with stdout for now.

Can this be done for this callback? Would you guys accept a patch for that?

Yes, I think a patch for this would be good.

Simplest would be to just pass the string that is printed to stdout, or the values in that string as separated by |. More complicated would be to pass some structured data, but the render API doesn’t have a mechanism for renderers to provide that, so that’s probably more work that you’d want to tackle.

Think I’ll try to pass the string that gets printed, and then when/if the API gets extended try to add support for passing a dict. Embedding the values in a string with | would remove the need for a regex but feels kind of fragile.

I made some progress on this patch but I can’t figure out how to pass the string to the callback properly.

I’m building the string in a char * and then trying to pass it like this:
BLI_callback_exec(G.main, (ID *) line, BLI_CB_EVT_RENDER_STATS);

I also tried not casting it, but I always get the same result. It compiles, but when I try to use the callback I get a segfault.

The segfault happens in this line of bpy_rna.c

		/* Refine may have changed types after the first instance was created. */
		if (ptr->type == pyrna->ptr.type) {

The current callback system works with ID*, you can’t pass a string into that no matter how you cast it.

To make this work the BLI_callback system and associated Python code should be extended to support ID* and char* callbacks.

Ah ok, I thought it was possible with the current system.
Thanks, I’ll get to change that too then