HipByte / Flow

Cross-platform libraries for RubyMotion
BSD 2-Clause "Simplified" License
141 stars 29 forks source link

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

Open brucemontegani opened 7 years ago

brucemontegani commented 7 years ago

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