Hey Garan,
Saw your post from today about the client crash with SetBackground().
There's a way to avoid the client crash that I've been using. It doesn't let you make sure that the image you load is a *good* one (as far as I can tell, the Graphic object gives us no way to do that), but it does at least prevent the client from crashing.
I use this to avoid crashing when I want to have an 'optional' image - i.e. load it if it's there, but proceed without it when it's not.
If I try to load a badly configured image (e.g. renaming a .mp3 to .tga and loading it!) I get weird visual images - I suppose it's just interpreting whatever it loads as image data? But no crash.
You probably already know all this, and you're describing that "is-it-a-real-image" problem?
But, just in case not - or if a forum searcher lands on this page looking to avoid the SetBackground() crashes - here's what works for me:
Code:
local g = nil;
if not pcall(function() g = Turbine.UI.Graphic(fileNameOrImageNumber); end) then
g = nil;
end;
if (g~=nil) then
self:SetBackground (g);
end;
I actually use a version that stores the image for later use -- so the SetBackground() call comes elsewhere. I've just appended it here.
if you're not doing that, there's no need to bother with saving the data in a variable at all. For that use, the following suffices:
Code:
if not pcall(function() self:SetBackground(Turbine.UI.Graphic(fileNameOrImageNumber)); end) then
<Handle failed image load>
end;
Like I said, not ideal... but it does mean the plugin can procede with a missing or funny-looking image rather than crashing entirely!