Skip to content

Commit b5c09e3

Browse files
committed
Fixed late update bug.
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.
1 parent 36c7da0 commit b5c09e3

File tree

4 files changed

+31
-12
lines changed

4 files changed

+31
-12
lines changed

lib/Internal.lua

+3-2
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,6 @@ return function(Iris: Types.Iris): Types.Internal
438438
if Internal._localRefreshActive then
439439
-- we are redrawing every widget.
440440
Internal._DiscardWidget(lastWidget)
441-
-- so we don't accidentally discard it twice
442-
lastWidget.lastCycleTick = -1
443441
lastWidget = nil
444442
end
445443
end
@@ -616,6 +614,9 @@ return function(Iris: Types.Iris): Types.Internal
616614

617615
-- using the widget class discard function.
618616
Internal._widgets[widgetToDiscard.type].Discard(widgetToDiscard)
617+
618+
-- mark as discarded
619+
widgetToDiscard.lastCycleTick = -1
619620
end
620621

621622
--[=[

lib/demoWindow.lua

+22-8
Original file line numberDiff line numberDiff line change
@@ -77,11 +77,6 @@ return function(Iris: Types.Iris)
7777
local ImageTransparencyState = Iris.State(Iris._config.ImageTransparency)
7878
Iris.InputColor4({ "Image Tint" }, { color = ImageColorState, transparency = ImageTransparencyState })
7979

80-
Iris.PushConfig({
81-
ImageColor = ImageColorState:get(),
82-
ImageTransparency = ImageTransparencyState:get(),
83-
})
84-
8580
Iris.Combo({ "Asset" }, { index = AssetState })
8681
do
8782
Iris.Selectable({ "Robux Small", "rbxasset://textures/ui/common/robux.png" }, { index = AssetState })
@@ -105,32 +100,51 @@ return function(Iris: Types.Iris)
105100
Iris.End()
106101
Iris.Checkbox({ "Pixelated" }, { isChecked = PixelatedCheckState })
107102

103+
Iris.PushConfig({
104+
ImageColor = ImageColorState:get(),
105+
ImageTransparency = ImageTransparencyState:get(),
106+
})
108107
Iris.Image({ AssetState:get(), SizeState:get(), RectState:get(), ScaleTypeState:get(), PixelatedState:get() })
108+
Iris.PopConfig()
109109

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

114+
Iris.PushConfig({
115+
ImageColor = ImageColorState:get(),
116+
ImageTransparency = ImageTransparencyState:get(),
117+
})
114118
Iris.Image({ "rbxasset://textures/grid2.png", SizeState:get(), nil, Enum.ScaleType.Tile, PixelatedState:get(), TileState:get() })
119+
Iris.PopConfig()
115120

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

125+
Iris.PushConfig({
126+
ImageColor = ImageColorState:get(),
127+
ImageTransparency = ImageTransparencyState:get(),
128+
})
120129
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())
130+
Iris.PopConfig()
121131

122132
Iris.SeparatorText({ "Image Button" })
123133
local count = Iris.State(0)
134+
124135
Iris.SameLine()
125136
do
137+
Iris.PushConfig({
138+
ImageColor = ImageColorState:get(),
139+
ImageTransparency = ImageTransparencyState:get(),
140+
})
126141
if Iris.ImageButton({ "rbxasset://textures/AvatarCompatibilityPreviewer/add.png", UDim2.fromOffset(20, 20) }).clicked() then
127142
count:set(count.value + 1)
128143
end
144+
Iris.PopConfig()
129145

130146
Iris.Text({ `Click count: {count.value}` })
131147
end
132-
133-
Iris.PopConfig()
134148
Iris.End()
135149
end
136150
Iris.End()

lib/widgets/Input.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -1136,7 +1136,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
11361136
local desiredCycleTick: number = Iris._cycleTick + 1
11371137
Iris._postCycleCallbacks[callbackIndex] = function()
11381138
if Iris._cycleTick >= desiredCycleTick then
1139-
Iris._widgets[`Slider{dataType}`].UpdateState(thisWidget)
1139+
if thisWidget.lastCycleTick ~= -1 then
1140+
Iris._widgets[`Slider{dataType}`].UpdateState(thisWidget)
1141+
end
11401142
Iris._postCycleCallbacks[callbackIndex] = nil
11411143
end
11421144
end

lib/widgets/Window.lua

+3-1
Original file line numberDiff line numberDiff line change
@@ -859,7 +859,9 @@ return function(Iris: Types.Internal, widgets: Types.WidgetUtility)
859859
local desiredCycleTick: number = Iris._cycleTick + 1
860860
Iris._postCycleCallbacks[callbackIndex] = function()
861861
if Iris._cycleTick >= desiredCycleTick then
862-
ChildContainer.CanvasPosition = Vector2.new(0, stateScrollDistance)
862+
if thisWidget.lastCycleTick ~= -1 then
863+
ChildContainer.CanvasPosition = Vector2.new(0, stateScrollDistance)
864+
end
863865
Iris._postCycleCallbacks[callbackIndex] = nil
864866
end
865867
end

0 commit comments

Comments
 (0)