@Schubido:

Good catch on the memory leak. I hadn't thought of that. I'll definitly tweak the code to not do that. I cant use bmap_createblack to set pixels because I've found out I need to copy a source bitmap to a target bmap without creating a new bitmap. Here's what I'm currently doing to copy the bmap:

Code:
function *bmap_copy(BMAP* target_bmp, BMAP* source_bmp)
{   target_bmp.width = source_bmp.width;
    target_bmp.height = source_bmp.height;
    target_bmp.bytespp = source_bmp.bytespp;
    target_bmp.flags = source_bmp.flags;
    target_bmp.u1 = source_bmp.u1;
    target_bmp.v1 = source_bmp.v1;
    target_bmp.u2 = source_bmp.u2;
    target_bmp.v2 = source_bmp.v2;
    target_bmp.u = source_bmp.u;
    target_bmp.v = source_bmp.v;
    target_bmp.refcount = source_bmp.refcount;
    target_bmp.finalwidth = source_bmp.finalwidth;
    target_bmp.finalheight = source_bmp.finalheight;
    target_bmp.finalbytespp = source_bmp.finalbytespp;
    target_bmp.pitch = source_bmp.pitch;
    target_bmp.finalpitch = source_bmp.finalpitch;
    target_bmp.miplevels = source_bmp.miplevels;
    target_bmp.finalformat = source_bmp.finalformat;
    target_bmp.finalbits = NULL;
    target_bmp.d3dtex = NULL;
    target_bmp.pixels = malloc((source_bmp.width*source_bmp.height)*source_bmp.bytespp);
    memcpy(target_bmp.pixels, source_bmp.pixels, (source_bmp.width*source_bmp.height)*source_bmp.bytespp);
}



Do you think free(target_bmp.pixels); would work?

@HeelX:

Schubido had actually suggested using bmap_blit() to copy the bmap earlier in the thread. I decided against using blit because of concerns over the speed of the command.

I also think i've figured out the cause of the invalid pointer freed error message when exiting the game - its because im setting d3dtex to NULL - Gamestudio is expecting something to be there. I just have to figure out the format of whats stored at d3dtex (or at least how to figure the *size* of whats stored there) and I can copy it. That should fix the error.

Last edited by Caermundh; 04/15/11 14:14.