diff --git a/mi/midispcur.c b/mi/midispcur.c
index 24b9a70..266c7e0 100644
--- a/mi/midispcur.c
+++ b/mi/midispcur.c
@@ -466,6 +466,10 @@ miDCRestoreUnderCursor(DeviceIntPtr pDev, ScreenPtr pScreen,
     GCPtr pGC;
 
     pBuffer = miGetDCDevice(pDev, pScreen);
+
+    if (!pBuffer)
+        return FALSE;
+
     pSave = pBuffer->pSave;
 
     pWin = pScreen->root;
