One of my friends helped me debug the error, and we came up with a solution, not sure if it's the best one though.
$files = DataObject::get(
singleton(str_replace("_Controller","",$this->class))->itemClass, //This line is the problem itemClass is a protected value
"AlbumID = {$current_album->ID} AND ImageGalleryPageID = {$this->ID}",
null,
"",
$limit
);
singleton(str_replace("_Controller","",$this->class))->itemClass,
we replaced this line with
singleton(str_replace("_Controller","",$this->class))->getItemClass(),
and we also created a method in the ImageGalleryPage
public function getItemClass()
{
return $this->itemClass;
}
And everything works now, as far as I can see.
[EDIT]
Patch file included as attachment