Commits

pygame  committed bc10c4b

fixed blitting bug, better internal module handling

  • Participants
  • Parent commits 69a6c55

Comments (0)

Files changed (6)

 # BREAK = change breaks existing code
 # BUG   = fixed a bug that was crashing
 
+Mar 14, 2001
+	smarter internal module handling
+	fixed blit() (broken on May 9th change)
+
 May 10, 2001
 	USEREVENT events now pass through the queue
 	Event() may be called with keyword args and/or a dict
 		if(PyCObject_Check(c_api)) {\
 			void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			memcpy(PyFONT_C_API, localptr, sizeof(void*)*PYGAMEAPI_FONT_NUMSLOTS); \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 
 		dict = PyModule_GetDict(music);
 		ptr = PyDict_GetItemString(dict, "_MUSIC_POINTER");
 		current_music = (Mix_Music**)PyCObject_AsVoidPtr(ptr);
+		Py_DECREF(music);
 	}	
 	else /*music module not compiled? cleanly ignore*/
 	{
 		if(PyCObject_Check(c_api)) {\
 			void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			memcpy(PyMIXER_C_API, localptr, sizeof(void*)*PYGAMEAPI_MIXER_NUMSLOTS); \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 

File src/pygame.h

 			int i; void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			for(i = 0; i < PYGAMEAPI_BASE_NUMSLOTS; ++i) \
 				PyGAME_C_API[i + PYGAMEAPI_BASE_FIRSTSLOT] = localptr[i]; \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 
 			int i; void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			for(i = 0; i < PYGAMEAPI_RECT_NUMSLOTS; ++i) \
 				PyGAME_C_API[i + PYGAMEAPI_RECT_FIRSTSLOT] = localptr[i]; \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 
 			int i; void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			for(i = 0; i < PYGAMEAPI_CDROM_NUMSLOTS; ++i) \
 				PyGAME_C_API[i + PYGAMEAPI_CDROM_FIRSTSLOT] = localptr[i]; \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 
 			int i; void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			for(i = 0; i < PYGAMEAPI_JOYSTICK_NUMSLOTS; ++i) \
 				PyGAME_C_API[i + PYGAMEAPI_JOYSTICK_FIRSTSLOT] = localptr[i]; \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 
 			int i; void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			for(i = 0; i < PYGAMEAPI_DISPLAY_NUMSLOTS; ++i) \
 				PyGAME_C_API[i + PYGAMEAPI_DISPLAY_FIRSTSLOT] = localptr[i]; \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 
 			int i; void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			for(i = 0; i < PYGAMEAPI_SURFACE_NUMSLOTS; ++i) \
 				PyGAME_C_API[i + PYGAMEAPI_SURFACE_FIRSTSLOT] = localptr[i]; \
-	} } \
+	} Py_DECREF(module); } \
 	module = PyImport_ImportModule("pygame.surflock"); \
 	if (module != NULL) { \
 		PyObject *dict = PyModule_GetDict(module); \
 			int i; void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			for(i = 0; i < PYGAMEAPI_SURFLOCK_NUMSLOTS; ++i) \
 				PyGAME_C_API[i + PYGAMEAPI_SURFLOCK_FIRSTSLOT] = localptr[i]; \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 
 			int i; void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			for(i = 0; i < PYGAMEAPI_EVENT_NUMSLOTS; ++i) \
 				PyGAME_C_API[i + PYGAMEAPI_EVENT_FIRSTSLOT] = localptr[i]; \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 
 			int i; void** localptr = (void*)PyCObject_AsVoidPtr(c_api); \
 			for(i = 0; i < PYGAMEAPI_RWOBJECT_NUMSLOTS; ++i) \
 				PyGAME_C_API[i + PYGAMEAPI_RWOBJECT_FIRSTSLOT] = localptr[i]; \
-} } }
+} Py_DECREF(module); } }
 #endif
 
 

File src/surface.c

 
 
 
-
     /*DOC*/ static char doc_surf_blit[] =
     /*DOC*/    "Surface.blit(source, destpos, [sourcerect]) -> Rect\n"
     /*DOC*/    "copy a one Surface to another.\n"
     /*DOC*/    "rectangle sizes will be ignored.\n"
 #if 0  /* "" */
     /*DOC*/    "\n"
-    /*DOC*/    "Note that blitting alpha surfaces onto an 8bit destination will\n"
-    /*DOC*/    "crash SDL. Pygame will disable the alpha when these blits are attempted.\n"
+    /*DOC*/    "Note that blitting surfaces with alpha onto 8bit destinations will\n"
+    /*DOC*/    "not use the surface alpha values.\n"
 #endif /* "" */
     /*DOC*/ ;
 
 	int dx, dy, result;
 	SDL_Rect dest_rect;
 	short sx, sy;
-	int didconvert;
+	int didconvert = 0;
 
 	VIDEO_INIT_CHECK();
+
 	if(!PyArg_ParseTuple(args, "O!O|O", &PySurface_Type, &srcobject, &argpos, &argrect))
 		return NULL;
 	src = PySurface_AsSurface(srcobject);
 	if(dest->flags & SDL_OPENGL && !(dest->flags&(SDL_OPENGLBLIT&~SDL_OPENGL)))
 		return RAISE(PyExc_SDLError, "Cannot blit to OPENGL Surfaces (OPENGLBLIT is ok)");
 
+	if(dest->format->BytesPerPixel == 1 && (src->flags&SDL_SRCALPHA || src->format->Amask))
+		return RAISE(PyExc_SDLError, "Alpha blits to 8bit surfaces currently unimplemented");
+
 	if((src_rect = GameRect_FromObject(argpos, &temp)))
 	{
 		dx = src_rect->x;
 	PySurface_Prep(self);
 	PySurface_Prep(srcobject);
 	Py_BEGIN_ALLOW_THREADS
+
 	/*can't blit alpha to 8bit, crashes SDL*/
-	if(dest->format->BytesPerPixel==1 && (src->format->Amask || src->flags&SDL_SRCALPHA))
-	{
-		didconvert = 1;
-		src = SDL_DisplayFormat(src);
-	}
+ 	if(dest->format->BytesPerPixel==1 && (src->format->Amask || src->flags&SDL_SRCALPHA))
+ 	{
+ 		didconvert = 1;
+ 		src = SDL_DisplayFormat(src);
+ 	}
 	result = SDL_BlitSurface(src, (SDL_Rect*)src_rect, dest, &dest_rect);
-	if(didconvert)
-		SDL_FreeSurface(src);
+ 	if(didconvert)
+ 		SDL_FreeSurface(src);
+
 	Py_END_ALLOW_THREADS
 	PySurface_Unprep(self);
 	PySurface_Unprep(srcobject);
 
+
 	if(result == -1)
 		return RAISE(PyExc_SDLError, SDL_GetError());
 	if(result == -2)
 
 	/*import the surflock module manually*/
 	lockmodule = PyImport_ImportModule("pygame.surflock");
-	if (module != NULL)
+	if(lockmodule != NULL)
 	{
 		PyObject *dict = PyModule_GetDict(lockmodule);
 		PyObject *c_api = PyDict_GetItemString(dict, PYGAMEAPI_LOCAL_ENTRY);
 				PyGAME_C_API[i + PYGAMEAPI_SURFLOCK_FIRSTSLOT] = localptr[i];
 		}
 	}
+	Py_XDECREF(lockmodule);
 }