Open badsectoracula opened 1 day ago
However, a memory leak occurs if I cancel baking while indirect light is being calculated:
I'm not surprised, these early return error conditions will need to free the GPU resources before returning as we do with the current error handling.
See for example
I updated the PR, it should release memory now (thanks to @Calinou 's video i also learned the AMD equivalent to the tool he uses - amdgpu_top
- so i ran a bunch of bakes and cancelled them at various points and memory returned at the pre-bake numbers).
There were already some existing early exits in the function so i thought it was ok to exit, i guess they are also leaks. There are a lot of exit points in this so it should probably be refactored to have a single exit point with some sort of "if (error) goto fail" at the end of the function that cleans up everything, so perhaps someone more familiar with the code could clean it up (i could do it in the future if nobody does but i think some stuff may need to be moved around and at the moment i do not feel confident enough to touch anything that would affect the code's logic).
This enables the "Cancel" button in the lightmap baking progress window and checks the cancel request whenever a progress is updated/reported during lightmap baking. Most of the functionality was already there, including a potential cancel request by the callback, but callback's return value was never checked.
This adds some checks where possible. A couple of progress updates wouldn't forward a cancellation result so i didn't add them but in practice i never saw them when testing cancelling (though i mainly tested with the GI demo). The main part that takes most of the time, indirect light integration, does get cancelled.
The patch just stops the lightmap calculation when it gets cancelled. I didn't notice this creating any leaks, but i might have missed them as this is the first time i saw the lightmapper code, so someone who is more familiar with this should review it.
This should address https://github.com/godotengine/godot-proposals/issues/8181.