Quick Links: Download Gideros Studio | Gideros Documentation | Gideros Development Center | Gideros community chat
dealing with errors (assert?, pcall?) - Gideros Forum

dealing with errors (assert?, pcall?)

MoKaLuxMoKaLux Member
edited November 14 in General questions
I need some help please. How would you deal with this error please?

In my app users can load images (textures). Unfortunately sometimes the image format is not valid (bad compression, ...).

I have tried using assert and pcall but the result is always nil :/
-- functions
function X_Anims:isValidTexture()
	local resulte, msg = assert(Texture.new(self.spath), "file is not recognised")
	print(result, msg)
	return result
end
 
function X_Anims:showSS()
	if self.spath and self.spath ~= "" and self:isValidTexture() then
		self.sbmp = Bitmap.new(Texture.new(self.spath))
	end

EDIT: that was a typo :o
local resulte, msg = assert(Texture.new(self.spath), "file is not recognised")
print(result, msg)
That should be working :)
my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Tagged:

Comments

  • MoKaLuxMoKaLux Member
    edited November 14
    EDIT 2: nope that doesn't work :'(

    .../AppData/Local/Temp/gideros/mediafiles/20201109_172943_gideros.png:
    Error while reading image file.
    stack traceback:
    levels/x_anims.lua:236: in function 'isValidTexture'

    How would you do it please?
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
  • MoKaLuxMoKaLux Member
    edited November 14
    EDIT 3: this works :)
    function X_Anims:isValidTexture()
    --	local result, msg = assert(Texture.new(self.spath), "file is not recognised")
    	local result, msg = pcall(Texture.new, self.spath, "file is not recognised")
    	print(result, msg)
    	return result
    end
    Viva gideros!
    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
Sign In or Register to comment.