Hi Beth,
Make sure you are doing it in the context of a CMS page where the Image Gallery instance exists not from Content Manager which has no pageid associated with it.
Other than that since you are deploying your own builds from source code I'd suggest trying to produce the problem in your dev environment and if you are able to produce it then step through the code and find out what exactly is null.
Hope that helps,
Joe