Topic: Flickr photo viewer widget debugging tips

I'm new to flashlite development and would appreciate some tips on how to track down a couple of problems I've ran into.

I've bought myself and my family 3 chumbys for Christmas with the idea that I'd like to "push" new photosets on my parents remotely whenever I feel like it. The available Flickr widget didn't seem to have support for doing correct authentication for private photosets and picking which sets each chumby should play, so I decided to write my own.

The widget I built goes to my website reads a configuration xml that describes the photosets the chumby should fetch (I can change this config file to push new sets on the chumbys). Then it goes to Flickr does the appropriate authentication (using the mobile app method) to read the private photosets and then starts displaying pictures. I implemented all the functionality and the widget works properly on my desktop and for a while on the 3 chumbys.

The problem I'm running into is that every once in a while the onLoad handler when using loadClip with a MovieClipLoader seems to just hang. Thinking that I have some bad state logic I added an onLoadError handler, and a onFrameEnter text print-out to see if the widget is at least alive. However, it seems like the widget is totally hung, I don't see any updates on the screen when it drops into this mode. The same sort of hang sometimes happens when I try to do a .load on my XML objects when communicating with Flickr's APIs or my own config file. I can reset the widget by going to the next widget in the channel and then coming back, or rebooting the chumby. The 3 chumbys also have completely different behaviour as to when and how often they hang.

Looking at the forums, it seems like this is a problem that other people have run into and that it could be caused by memory leaks. Do people have any tips as to how I should try to debug this issue? Is there any way to get the state of the garbage collector or an object dump from SSH? How about access to trace messages?

I would really appreciate any tips!

2 (edited by jvc 2007-12-09 13:44:27)

Re: Flickr photo viewer widget debugging tips

here's the setup i use

1. set up sshd on launch
http://wiki.chumby.com/mediawiki/index. … at_startup

2. upload the widget to chumby as private and add it to a channel

3. log in:
http://wiki.chumby.com/mediawiki/index. … the_chumby

4. run the commands

stop_control_panel
start_control_panel

you will then see debug stuff & standard trace messages

If you have set the chumby's just to run your one widget you may want to try throwing another widget in there. I had some issues with trying to just run one widget forever. Just adding another widget seemed to help me keep things going.

Re: Flickr photo viewer widget debugging tips

Thanks jvc going to give that a try now,

Did you have any similar issues while developing your Picasa widget where it would freeze on a http fetch at all?

- Baback

Re: Flickr photo viewer widget debugging tips

not really on a fetch... i had some long pauses earlier while the widget was parsing the XML to an Object (lots of recursive functions with Google's large feed). Once I swapped this out with a different version everything went much smoother.

I also started making http requests (loading photos) in batches of 5. I actually don't think this helped that much but I kept in in there.

Are you using one instance of the MovieClipLoader to load all the photos? In my experience it has always been better to use one per photo.

Re: Flickr photo viewer widget debugging tips

In general, you should only load the pictures when they're showing, an unload them when they're no longer visible - there isn't the memory to load tons of images.  If you are able to load images at different sizes, load the ones closest to the screen resolution.

Also, Flash Lite has some internal limitations on the number of network fetches initiated in a single frame, and another on the total number of fetches ongoing at any time.

Re: Flickr photo viewer widget debugging tips

I started using the ssh method jvc suggested and even though I haven't managed to track down the hang yet, it looks like I am getting warnings on realloc failing inside HTTPCacheEntry. What exactly is that piece responsible for? I'm not getting a hang after the following trace is printed out, but it can't be good right?

2007-12-10 23:32:25 TRACE: loading url http://farm3.static.flickr.com/2405/206 … cd3b0e.jpg
2007-12-10 23:32:25 TRACE: new appstate = STATE_LOADING_IMAGE
2007-12-10 23:32:25 NetStreamRequest::Open(203): Opening protocol 'http://' host 'farm3.static.flickr.com' port 80 location '/2405/2061792772_3ad9cd3b0e.jpg'
2007-12-10 23:32:25 NetStreamRequest::Open(203) opened http object id 209
2007-12-10 23:32:25 NetStreamRequest::ProcessHeaders(203) content-type: image/jpeg
2007-12-10 23:32:25 HTTPCacheEntry(194):AddData() WARNING: realloc adding 16385 for total 65537 bytes failed, cancelling capture
2007-12-10 23:32:25 HTTPCurlObject::ReceiveData(id=209) cache capture disabled (probably out of cache memory
2007-12-10 23:32:25 NetStreamRequest::Step(203) done, closing stream (90305 of 90305 bytes, avail=0) status=200

The pictures I'm loading are jpegs at 500x375, at this point in my widget I have two movie clips, I load an image into one of them and remove the previous clip once onLoad returns control:

_root.createEmptyMovieClip(movieName, movieDepth);
LoadPictureFromURL(url, eval(movieName), InitLoadHandler, ProgressLoadHandler, ErrorLoadHandler);

function LoadPictureFromURL(url:String, targetMC:MovieClip, iFunc:Function, pFunc:Function, eFunc:Function):Void
{
    var movieClipLoader:MovieClipLoader = new MovieClipLoader();

    // build the load-movie event handler
    var movieLoadListener:Object = new Object();
    movieLoadListener.onLoadProgress = ProgressLoadHandler;
    movieLoadListener.onLoadInit = iFunc;   
    movieLoadListener.onLoadError = eFunc;
   
    movieClipLoader.addListener(movieLoadListener);
    movieClipLoader.loadClip(url, targetMC);
    trace("loading url " + _global.currentPictureURL);
}

Then InitLoadHandler unloads the last movie:

function InitLoadHandler(mc:MovieClip):Void
{
    // ... set width height etc...

    // remove the last clip, save this clip for next unload
    removeMovieClip(_global.trackingHash["lastLoaded"]);
    _global.trackingHash["lastLoaded"] = mc;
}

Is this the right way to make sure only one image is loaded at any time? The debugger tells me I only have one clip active at any time, is the memory somehow not being free'd up?

Re: Flickr photo viewer widget debugging tips

Update:  The Flickr Viewer widget now handles private photosets.  Give it a try.

As for implementation, one thing to keep in mind is that the current chumby Flash version does not call onLoadError when the MovieClipLoader encounters an error.  What I do instead is check for a _width of 0 at the onLoadInit callback, and call onLoadError manually in that case (I leave the onLoadError in there in case a future firmware version fixes it, and also because it would work in the Virtual Chumby.)