Fix null dereference when hooking a vertical box with a generic slot - #428
Open
DegradingAnt wants to merge 1 commit into
Open
Fix null dereference when hooking a vertical box with a generic slot#428DegradingAnt wants to merge 1 commit into
DegradingAnt wants to merge 1 commit into
Conversation
UWidgetBlueprintHookSlot_Generic::SetupPanelSlot dereferences HorizontalBoxSlot inside the UVerticalBoxSlot branch. That variable belongs to the preceding else-if, so it is always null by the time the vertical box branch runs. Any mod that registers a widget hook whose parent is a vertical box and whose slot configuration is the generic one will crash the game during UGameInstance::Init, before the main menu appears. The access violation reads address 0x38, which is the offset of the member SetSize touches on a null this. The other branches in the function each call their own slot's setters, so this looks like a copy-paste from the horizontal box branch above.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
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.
UWidgetBlueprintHookSlot_Generic::SetupPanelSlotdereferences the wrong variable in its vertical box branch:HorizontalBoxSlotis declared by the precedingelse if. If control reaches the vertical box branch, that cast returned null, so the very first statement calls a member function on a null pointer.What it does
Any mod that registers a
UWidgetBlueprintHookDatawhose parent widget is a vertical box, withSlotConfigurationset to aUWidgetBlueprintHookSlot_Generic, crashes the game duringUGameInstance::Init. It happens before the main menu, so the game never becomes usable.0x38is the offset of the memberSetSizewrites, which is what a nullthisproduces here.The workaround is to leave
SlotConfigurationnull, since both call sites already guard on it. That avoids the crash but gives up control of padding and alignment for the hooked widget.The fix
One word.
HorizontalBoxSlot->SetSize(Size)becomesVerticalBoxSlot->SetSize(Size).UVerticalBoxSlot::SetSize(FSlateChildSize)exists and takes the same argument type as the horizontal box version, so the intent of the line is met rather than worked around. Every other branch in the function calls setters on its own slot, which is why this reads as a copy-paste from the horizontal box branch directly above it.Testing
Reproduced on 3.12.0 with a mod hooking
mGameProgressionVBoxinWidget_PlayerHUD. Three consecutive launches crashed at the same address, before the main menu, every time. With the patch applied and SML rebuilt, the same build reached the main menu and loaded a save with no crash at the hook site.