diff -r d4845b8453a9 multiblock.module
--- a/multiblock.module  Sun Dec 03 15:01:05 2017 +0000
+++ b/multiblock.module  Sun Dec 03 15:27:02 2017 +0000
@@ -67,10 +67,10 @@
  * Fetch a given block from the multiblock database table.
  *
  * @param $delta
- *   Optional. Retreive a single block based on this delta. If none specified,
+ *   Optional. Retrieve a single block based on this delta. If none specified,
  *   all multiblock instances are returned.
  * @param $reset
- *   Optional. Boolean value to reset the interal cache of this function.
+ *   Optional. Boolean value to reset the internal cache of this function.
  */
 function multiblock_get_block($delta = NULL, $reset = FALSE) {
   static $blocks;
@@ -78,12 +78,20 @@
   if (!isset($blocks) || $reset) {
     $blocks = array();
     $result = db_query("SELECT * FROM {multiblock}");
+    $modules = array();
     foreach ($result as $row) {
-      $blocks[$row->delta] = $row;
+      // If we've not checked this module is enabled yet do so.
+      if (!isset($modules[$row->module])) {
+        $modules[$row->module] = module_exists($row->module);
+      }
+      // Only add this block if the module is enabled.
+      if ($modules[$row->module]) {
+        $blocks[$row->delta] = $row;
+      }
     }
   }
-
-  return is_numeric($delta) ? $blocks[$delta] : $blocks;
+
+  return is_numeric($delta) ? (isset($blocks[$delta]) ? $blocks[$delta] : FALSE) : $blocks;
 }
 
 /**
@@ -109,10 +117,11 @@
  *   Information returned by the corresponding module_invoke() call.
  */
 function multiblock_call_block($delta, $op, $edit) {
-  $result = db_query("SELECT module, orig_delta, delta, multi_settings FROM {multiblock} WHERE delta = :delta", array(
-    ':delta' => $delta,
-  ));
-  if ($block_info = $result->fetchObject()) {
+  // Get block info from multiblock_get_block() which now checks that the original module
+  // still exists before returning the info.
+  $block_info = multiblock_get_block($delta);
+  // Check we actually have a block to render.
+  if ($block_info) {
     // If this block is multiblock enabled, send it the delta of the block we're using.
     if ($block_info->multi_settings == 1 ) {
       $edit['multiblock_delta'] = array(
@@ -435,3 +444,13 @@
 
   return $output;
 }
+
+/**
+ * Implements hook_modules_uninstalled().
+ */
+function hook_modules_uninstalled($modules) {
+  // Delete all multiblock instances for the disabled modules.
+  db_delete('multiblock')
+    ->condition('module', $modules, 'IN')
+    ->execute();
+}
\ No newline at end of file
