Skip to content

Instantly share code, notes, and snippets.

@Meorawr
Created July 7, 2022 13:19
Show Gist options
  • Save Meorawr/b52d7999d27dbf6d4030d682efd4a27d to your computer and use it in GitHub Desktop.
Save Meorawr/b52d7999d27dbf6d4030d682efd4a27d to your computer and use it in GitHub Desktop.
Texture Load Watcher
local TextureParent = CreateFrame("Frame")
TextureParent:SetPoint("BOTTOMRIGHT", nil, "TOPLEFT")
TextureParent:SetSize(1, 1)
local TexturePool = CreateTexturePool(TextureParent)
local WatcherPool = CreateFramePool("Frame", TextureParent)
function ContinueOnTextureLoad(path, callback)
local texture = TexturePool:Acquire()
local watcher
local OnTextureLoad = function()
if texture:GetTextureFileID() then
xpcall(callback, CallErrorHandler, path, true, texture:GetSize())
else -- Path doesn't exist.
xpcall(callback, CallErrorHandler, path, false, 0, 0)
end
if watcher then
watcher:SetScript("OnSizeChanged", nil)
WatcherPool:Release(watcher)
end
texture:SetTexture(nil)
TexturePool:Release(texture)
end
texture:SetPoint("BOTTOMRIGHT")
texture:SetTexture(path)
texture:Show()
if texture:GetRect() then
OnTextureLoad();
else
watcher = WatcherPool:Acquire()
watcher:SetAllPoints(texture)
watcher:SetScript("OnSizeChanged", OnTextureLoad)
watcher:Show()
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment