@Caermundh: Not true, here is the struct copied from avtypes.h
Code:
typedef struct BMAP {
	C_LINK	link;
	long 	width,height; // original size of the bitmap
	long	bytespp;	// original bytes per pixel (1..4)
	void	*ptr;		// internal use
	byte	*pixels;	// ptr to palettized, 565, 4444, 888 or 8888 coded original image
	long	flags;      // see BMPF_... above
	void	*d3dtex;	// 	LPDIRECT3DTEXTURE9 (usually a different format than the original image)
	float	u1,v1,u2,v2; // texture pixel bounds
	long	u,v;		// cutout start size
	long	refcount;	// for implicitely created bmaps
	long	finalwidth,finalheight,finalbytespp;
	long	pitch,finalpitch;
	long	miplevels;
	long    finalformat;
	void	*finalbits;	// bitmap content when locked, otherwise NULL
} BMAP;



As you can see, a BMAP is supposed to be in an linked list (C_LINK link), you destroy this when you copy your BMAP via memcpy. Thus the new BMAP thinks it lives in the linked list and links to its neighbors, but thats not the real case. Calling _ANY_ function that might use this linked list internally will have horrible results. YOU are not the owner of the linked, so don't mess with it!

The next thing ist that there are four pointers, their content isn't copied with memcpy, so you now have two BMAPs that share to some degree their data. Calling _ANY_ function that might alter this data, will alter the data for all BMAPs.

Last but not least: The copy can't be purged from memory via ptr_remove() because it just isn't linked in the linked list. Again, you don't own it, you don't mess with it. When you now use ptr_remove() on the root source BMAP, you will invalidate all copied BMAPs as the shared data is purged and the linked list has changed, thus the copied BMAPs have a wrong state of the linked list (not to mention that this is always the case when a function alters the linked list).


Its _IS_ evil to do it the way MrGuest showed, depending on this function will result for sure in some horrible bugs!


Edit: Another snippet from the atypes.h
Code:
typedef struct C_LINK {
	long	index;		// index number of the object (handle)
	struct C_LINK *next; // pointer to next object
	char	*name;		// pointer to name of object (if any)
} C_LINK;				// object header



Do you still think that you now have two BMAPs with two different handles?

Last edited by JustSid; 04/14/11 14:33.

Shitlord by trade and passion. Graphics programmer at Laminar Research.
I write blog posts at feresignum.com