diff --git a/src/SitemapGenerator.php b/src/SitemapGenerator.php
index 7e959ff..baed90d 100644
--- a/src/SitemapGenerator.php
+++ b/src/SitemapGenerator.php
@@ -100,11 +100,13 @@ class SitemapGenerator {
    */
   private function getCustomUrlsData() {
     $paths = [];
-    foreach ($this->generator->getCustomLinks() as $i => $custom_path) {
-      $paths[$i]['path'] = $custom_path['path'];
-      $paths[$i]['priority'] = isset($custom_path['priority']) ? $custom_path['priority'] : NULL;
-      // todo: implement lastmod.
-      $paths[$i]['lastmod'] = NULL;
+    if (isset($this->generator)) {
+      foreach ($this->generator->getCustomLinks() as $i => $custom_path) {
+        $paths[$i]['path'] = $custom_path['path'];
+        $paths[$i]['priority'] = isset($custom_path['priority']) ? $custom_path['priority'] : NULL;
+        // todo: implement lastmod.
+        $paths[$i]['lastmod'] = NULL;
+      }
     }
     return $paths;
   }
