Skip to content

Commit

Permalink
Fixed late update bug.
Browse files Browse the repository at this point in the history
Fixed a bug where a widget would wait a frame to update but would not check whether it had been destroyed. Most promimently causing issues when the style of a slider widget constantly changed and was therefore destroyed and created every frame. Fixed by adding a check to make sure the widget was not discarded.
  • Loading branch information
SirMallard committed Aug 13, 2024
1 parent 36c7da0 commit b5c09e3
Show file tree
Hide file tree
Showing 4 changed files with 31 additions and 12 deletions.
5 changes: 3 additions & 2 deletions lib/Internal.lua
Original file line number Diff line number Diff line change
Expand Up @@ -438,8 +438,6 @@ return function(Iris: Types.Iris): Types.Internal
if Internal._localRefreshActive then
-- we are redrawing every widget.
Internal._DiscardWidget(lastWidget)
-- so we don't accidentally discard it twice
lastWidget.lastCycleTick = -1
lastWidget = nil
end
end
Expand Down Expand Up @@ -616,6 +614,9 @@ return function(Iris: Types.Iris): Types.Internal

-- using the widget class discard function.
Internal._widgets[widgetToDiscard.type].Discard(widgetToDiscard)

-- mark as discarded
widgetToDiscard.lastCycleTick = -1
end

--[=[
Expand Down
30 changes: 22 additions & 8 deletions lib/demoWindow.lua
Original file line number Diff line number Diff line change
Expand Up @@ -77,11 +77,6 @@ return function(Iris: Types.Iris)
local ImageTransparencyState = Iris.State(Iris._config.ImageTransparency)
Iris.InputColor4({ "Image Tint" }, { color = ImageColorState, transparency = ImageTransparencyState })

Iris.PushConfig({
ImageColor = ImageColorState:get(),
ImageTransparency = ImageTransparencyState:get(),
})

Iris.Combo({ "Asset" }, { index = AssetState })
do
Iris.Selectable({ "Robux Small", "rbxasset://textures/ui/common/robux.png" }, { index = AssetState })
Expand All @@ -105,32 +100,51 @@ return function(Iris: Types.Iris)
Iris.End()
Iris.Checkbox({ "Pixelated" }, { isChecked = PixelatedCheckState })

Iris.PushConfig({
ImageColor = ImageColorState:get(),
ImageTransparency = ImageTransparencyState:get(),
})
Iris.Image({ AssetState:get(), SizeState:get(), RectState:get(), ScaleTypeState:get(), PixelatedState:get() })
Iris.PopConfig()

Iris.SeparatorText({ "Tile" })
local TileState = Iris.State(UDim2.fromScale(1, 1))
local TileState = Iris.State(UDim2.fromScale(0.5, 0.5))
Iris.SliderUDim2({ "Tile Size", nil, nil, UDim2.new(1, 240, 1, 240) }, { number = TileState })

Iris.PushConfig({
ImageColor = ImageColorState:get(),
ImageTransparency = ImageTransparencyState:get(),
})
Iris.Image({ "rbxasset://textures/grid2.png", SizeState:get(), nil, Enum.ScaleType.Tile, PixelatedState:get(), TileState:get() })
Iris.PopConfig()

Iris.SeparatorText({ "Slice" })
local SliceScaleState = Iris.State(1)
Iris.SliderNum({ "Image Slice Scale", 0.1, 0.1, 5 }, { number = SliceScaleState })

Iris.PushConfig({
ImageColor = ImageColorState:get(),
ImageTransparency = ImageTransparencyState:get(),
})
Iris.Image({ "rbxasset://textures/ui/chatBubble_blue_notify_bkg.png", SizeState:get(), nil, Enum.ScaleType.Slice, PixelatedState:get(), nil, Rect.new(12, 12, 56, 56), 1 }, SliceScaleState:get())
Iris.PopConfig()

Iris.SeparatorText({ "Image Button" })
local count = Iris.State(0)

Iris.SameLine()
do
Iris.PushConfig({
ImageColor = ImageColorState:get(),
ImageTransparency = ImageTransparencyState:get(),
})
if Iris.ImageButton({ "rbxasset://textures/AvatarCompatibilityPreviewer/add.png", UDim2.fromOffset(20, 20) }).clicked() then
count:set(count.value + 1)
end
Iris.PopConfig()

Iris.Text({ `Click count: {count.value}` })
end

Iris.PopConfig()
Iris.End()
end
Iris.End()
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/Input.lua
Original file line number Diff line number Diff line change
Expand Up @@ -1136,7 +1136,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
local desiredCycleTick: number = Iris._cycleTick + 1
Iris._postCycleCallbacks[callbackIndex] = function()
if Iris._cycleTick >= desiredCycleTick then
Iris._widgets[`Slider{dataType}`].UpdateState(thisWidget)
if thisWidget.lastCycleTick ~= -1 then
Iris._widgets[`Slider{dataType}`].UpdateState(thisWidget)
end
Iris._postCycleCallbacks[callbackIndex] = nil
end
end
Expand Down
4 changes: 3 additions & 1 deletion lib/widgets/Window.lua
Original file line number Diff line number Diff line change
Expand Up @@ -859,7 +859,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
local desiredCycleTick: number = Iris._cycleTick + 1
Iris._postCycleCallbacks[callbackIndex] = function()
if Iris._cycleTick >= desiredCycleTick then
ChildContainer.CanvasPosition = Vector2.new(0, stateScrollDistance)
if thisWidget.lastCycleTick ~= -1 then
ChildContainer.CanvasPosition = Vector2.new(0, stateScrollDistance)
end
Iris._postCycleCallbacks[callbackIndex] = nil
end
end
Expand Down

0 comments on commit b5c09e3

Please sign in to comment.