diff --git a/includes/common.inc b/includes/common.inc
index ad2a345..5e9cc72 100644
--- a/includes/common.inc
+++ b/includes/common.inc
@@ -5155,6 +5155,9 @@ function drupal_valid_token($token, $value = '', $skip_anonymous = FALSE) {
 }
 
 function _drupal_bootstrap_full() {
+  // Initialize the drupal_theme_init to indicate the theme init hasn't happened
+  variable_set('drupal_theme_init', 0);
+
   static $called = FALSE;
 
   if ($called) {
@@ -5211,6 +5214,9 @@ function _drupal_bootstrap_full() {
     //   (e.g., hook_form_alter(), hook_node_view_alter(), hook_page_alter()),
     //   ahead of when rendering starts.
     menu_set_custom_theme();
+
+    // Set a variable indicating that the theme has been initialized
+    variable_set('drupal_theme_init', 1);
     drupal_theme_initialize();
     module_invoke_all('init');
   }
diff --git a/includes/theme.inc b/includes/theme.inc
index ed34b82..4aea6bd 100644
--- a/includes/theme.inc
+++ b/includes/theme.inc
@@ -68,6 +68,10 @@ function _drupal_theme_access($theme) {
  * Initializes the theme system by loading the theme.
  */
 function drupal_theme_initialize() {
+  // Only set the theme after the bootstrap is finished, see _drupal_bootstrap_full in common.inc
+  if (!variable_get('drupal_theme_init', 0)) {
+    return false;
+  }
   global $theme, $user, $theme_key;
 
   // If $theme is already set, assume the others are set, too, and do nothing
@@ -253,6 +257,10 @@ function _drupal_theme_initialize($theme, $base_theme = array(), $registry_callb
  *   class.
  */
 function theme_get_registry($complete = TRUE) {
+  // if the theme has not been initialized yet, don't initialize a theme
+  if (!variable_get('drupal_theme_init', 0)) {
+    return false;
+  }
   // Use the advanced drupal_static() pattern, since this is called very often.
   static $drupal_static_fast;
   if (!isset($drupal_static_fast)) {
