diff --git a/gmap.module b/gmap.module
index 0f91f7b0f6a099b8c0925fa677ef169aae426edc..59a84686998109b7f9915e0224e5e34926b04866 100644
--- a/gmap.module
+++ b/gmap.module
@@ -565,7 +565,9 @@ function gmap_regenerate_markers() {
   // Make sure js/ exists in the files folder.
   if (file_prepare_directory($dir, FILE_CREATE_DIRECTORY)) {
     $file = file_save_data($contents, 'public://js/gmap_markers.js', FILE_EXISTS_REPLACE);
-    variable_set('gmap_marker_file', $file->fid);
+    if (!empty($file)) {
+      variable_set('gmap_marker_file', $file->fid);
+    }
   }
   else {
     drupal_set_message(t('GMap is unable to save the marker bundle. Markers will not work!'), 'error');