Improve logic related to editing audio buses (and prevent crashes) #74560
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Fixes #74374 and a bunch of related errors.
Generally speaking, the
EditorAudioBus
andEditorAudioBuses
code is pretty nasty. I'm not exactly sure why issues are only reported now for 4.0 stable, because most of the relevant code has been like that for some time. Perhaps there are other reports that are relevant here? Do link them if you know them.Handling of bus renaming is all sorts of incorrect, and the same applies to reordering them as well. Most of the problems are obvious now because
AudioServer
emits thebus_layout_changed
signal when buses are renamed, which triggers a rebuild of the entire layout editor. When this happens old code memdeletes all the existing nodes in place, which is a big no-no as it leads to nasty race conditions and bad memory bugs (and that's the reason for the reported crash, more or less). I've replaced it with a graceful remove_child & queue_free. Same is done to the placeholder node used for drag'n'drop indication.But the thing is, the part of the editor that handles bus renames is written in a way that doesn't assume that the entire layout is rebuilt. There is a lot of code to gracefully handle that case and update only the relevant parts. Furthermore, I'm not sure if
AudioServer
firing thebus_layout_changed
signal is intended or a bug. It doesn't send one when setting the bus send value, for example. Something is fishy here. But I am not familiar with the audio system, so I can only patch the editor side. And thus I added a flag to prevent full rebuild of the layout panel when we are already handling it gracefully via the renaming handler.I've tested a bunch of cases of renaming and reordering buses and fixed issues as they appeared, so there are some extra fixes on top of all that. Overall, it should work better and faster now.
Although, drag'n'drop seems to still be slow, and it has issues with detecting which node we're hovering over due to controls eating input. It wasn't critical enough for me to dive into now, but it's something worth fixing in future.