Commits

illume committed efe9c4a Merge

Another fix for #93 where x or y were less than 0.

  • Participants
  • Parent commits 77c972e, 7cd7afd

Comments (0)

Files changed (2)

         sdlrect.w = rect->w;
         sdlrect.h = rect->h;
         
+
+
+
         // clip the rect to be within the surface.
+        if (sdlrect.x < 0) {
+            sdlrect.x = 0;
+        }
+        if (sdlrect.y < 0) {
+            sdlrect.y = 0;
+        }
+
         if(sdlrect.x + sdlrect.w > surf->w) {
             sdlrect.w = sdlrect.w + (surf->w - (sdlrect.x + sdlrect.w));
         }
         }
 
 
+
         if (blendargs != 0) {
             
             /* 
         return 0;
     }
     view = PgView_New(capsule, self, surf_view_destr);
+    Py_DECREF(capsule);
     if (!view) {
         return 0;
     }
 static void
 surf_view_destr(PyObject *view)
 {
-    PySurface_UnlockBy(PgView_GetParent(view), view);
+    PyObject *surf = PgView_GetParent(view);
+
+    PySurface_UnlockBy(surf, view);
+    Py_DECREF(surf);
 }
 
 static PyObject *

test/surface_test.py

 from pygame.compat import xrange_, as_bytes, as_unicode
 from pygame._view import View
 
+import gc
+import weakref
+
 def intify(i):
     """If i is a long, cast to an int while preserving the bits"""
     if 0x80000000 & i:
         s = pygame.Surface((2, 4), 0, 32)
         s.get_view(as_unicode('2'))
         s.get_view(as_bytes('2'))
+        
+        # Garbage collection
+        s = pygame.Surface((2, 4), 0, 32)
+        weak_s = weakref.ref(s)
+        v = s.get_view('3')
+        weak_v = weakref.ref(v)
+        gc.collect()
+        self.assertTrue(weak_s() is s)
+        self.assertTrue(weak_v() is v)
+        del v
+        gc.collect()
+        self.assertTrue(weak_s() is s)
+        self.assertTrue(weak_v() is None)
+        del s
+        gc.collect()
+        self.assertTrue(weak_s() is None)
 
     def test_set_colorkey(self):
 
         self.assert_(s1.get_at((1, 1)) == color)
 
 
+        black = pygame.Color("black")
+        red = pygame.Color("red")
+        self.assertNotEqual(black, red)
+
+        surf = pygame.Surface((10, 10), 0, 32)
+        surf.fill(black)
+        subsurf = surf.subsurface(pygame.Rect(0, 1, 10, 8))
+        self.assertEqual(surf.get_at((0, 0)), black)
+        self.assertEqual(surf.get_at((0, 9)), black)
+
+        subsurf.fill(red, (0, -1, 10, 1), pygame.BLEND_RGB_ADD)
+        self.assertEqual(surf.get_at((0, 0)), black)
+        self.assertEqual(surf.get_at((0, 9)), black)
+
+        subsurf.fill(red, (0, 8, 10, 1), pygame.BLEND_RGB_ADD)
+        self.assertEqual(surf.get_at((0, 0)), black)
+        self.assertEqual(surf.get_at((0, 9)), black)
+