Skip to content

UI::Image#source= method causes crash if image does not exist #76

@brucemontegani

Description

@brucemontegani

If you pass a string as parameter to the source= method and the image does not exist then application will crash later in the method because the proxy(UIImageView).image is nil and sending the size message to nil causes the crash. Suggest there needs to be a default 'image not found' image provided for all images that cannot be found.

def source=(source)
      if @source != source
        @source = source

        image = case source
          when String
            UIImage.imageNamed(source)
          when NSData
            UIImage.imageWithData(source)
          else
            raise "Expected `String' or `NSData' object, got `#{source.class}'"
        end
        @original_image = proxy.image = image

        if width.nan? and height.nan?
          self.width = proxy.image.size.width
          self.height = proxy.image.size.height
        end
      end
    end

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions