diff --git a/sys/d3dvideosink/d3dvideosink.c b/sys/d3dvideosink/d3dvideosink.c
index 2284ee6..40c3fa3 100644
--- a/sys/d3dvideosink/d3dvideosink.c
+++ b/sys/d3dvideosink/d3dvideosink.c
@@ -2017,6 +2017,8 @@ gst_d3dvideosink_initialize_d3d_device (GstD3DVideoSink * sink)
   D3DTEXTUREFILTERTYPE d3dfiltertype;
   gint width, height;
 
+  gst_d3dvideosink_release_d3d_device (sink);
+
   /* Get the current size of the window */
   gst_d3dvideosink_window_size (sink, &width, &height);
 
@@ -2275,6 +2277,10 @@ gst_d3dvideosink_release_direct3d (GstD3DVideoSink * sink)
   /* Remove item from the list */
   shared.element_list = g_list_remove (shared.element_list, sink);
 
+  GST_D3DVIDEOSINK_D3D_DEVICE_LOCK (sink);
+  gst_d3dvideosink_release_d3d_device (sink);
+  GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK (sink);
+
   /* Decrement our count of the number of elements we have */
   shared.element_count--;
   if (shared.element_count < 0)
@@ -2282,10 +2288,6 @@ gst_d3dvideosink_release_direct3d (GstD3DVideoSink * sink)
   if (shared.element_count > 0)
     goto success;
 
-  GST_D3DVIDEOSINK_D3D_DEVICE_LOCK (sink);
-  gst_d3dvideosink_release_d3d_device (sink);
-  GST_D3DVIDEOSINK_D3D_DEVICE_UNLOCK (sink);
-
   if (shared.d3d) {
     int ref_count;
     ref_count = IDirect3D9_Release (shared.d3d);
