rnd-20140307-1-src
[rocksndiamonds.git] / src / libgame / gadgets.c
index 26454d470ae616c55063fbb8577d10e78c8547ad..8b99078ebfd62d3963eaa65777eee631192b0ccc 100644 (file)
@@ -26,6 +26,9 @@
 #define DG_BUFFERED            0
 #define DG_DIRECT              1
 
+#define GADGET_DEACTIVATED(g)  ((g)->x < 0 || (g)->y < 0)
+
+
 static struct GadgetInfo *gadget_list_first_entry = NULL;
 static struct GadgetInfo *gadget_list_last_entry = NULL;
 static struct GadgetInfo *last_info_gi = NULL;
@@ -1260,6 +1263,9 @@ void FreeGadget(struct GadgetInfo *gi)
 {
   struct GadgetInfo *gi_previous = gadget_list_first_entry;
 
+  if (gi == NULL)
+    return;
+
   /* prevent "last_info_gi" from pointing to memory that will be freed */
   if (last_info_gi == gi)
     last_info_gi = NULL;
@@ -1304,7 +1310,7 @@ static struct GadgetInfo *last_gi = NULL;
 
 static void MapGadgetExt(struct GadgetInfo *gi, boolean redraw)
 {
-  if (gi == NULL || gi->mapped)
+  if (gi == NULL || gi->mapped || GADGET_DEACTIVATED(gi))
     return;
 
   gi->mapped = TRUE;