1
Vote

Crashed when search

description

Started Photo Browser, tried to start search. Inputed some keyword, pressed "Search" button, app crashed. Debug showed the following problem in FlickrPhotos.cs:
 
 
    /// <summary>
    /// Gets the photo at the specified index
    /// </summary>
    /// <param name="index"></param>
    /// <returns></returns>
    public FlickrPhoto GetPhoto(int index)
    {
        FlickrPhoto photo = null;

        lock (this)
        {
            // get the page index of the photos
            int page = index / NumPerPage + 1;
            List<FlickrPhoto> photos = null;
 
            if (Cache.ContainsKey(page))
            {
                photos = Cache[page];
            }
            else
            {
                PhotoQuery.AddParameter("page", page.ToString());
                PhotoQuery.AddParameter("per_page", NumPerPage.ToString());                    
 
                photos = Flickr.GetPhotos(PhotoQuery, ref _count);
            }
 
            // now get the actual photo
            if (index >= _count) return null;

                photo = photos[index % NumPerPage];

                PROBLEM WAS HERE: INDEX WAS OUT OF RANGE!!!

            AddToCache(photos, page);                
        }
 
        return photo;
    }

comments