Skip to main content
GameDev.net gamedev.net
🔒 Locked

problem coping LPDIRECTDRAWSURFACE7

Started by kubicon Dec 26, 2004 at 6:59 PM 3 replies 1k views
Original Post
kubicon
kubicon
Hello guys, this is my first post to these forums. I've been here for a short period of time and I already like it. I'm having trouble making a copy of a directdraw surface in one of my classes' copy contructor. What is the correct way to do it? I don't know what the code tags are, and I don't see a code tag button so I'm just gonna take a guess for now. Animation::Animation(const Animation & rhs) { m_width = rhs.m_width; m_height = rhs.m_height; m_bpp = rhs.m_bpp; Dialog::error("Animation::Animation(copy)","before"); //m_surface = rhs.m_surface; // this just copies the pointer? //****************************************************// //**************** RIGHT HERE ************************// //****************************************************// memcpy(m_surface,rhs.m_surface, sizeof(rhs.m_surface)); Dialog::error("Animation::Animation(copy)","after"); }
VolkerG
VolkerG
When copying you should call m_surface->AddRef (). In the destructor call m_surface->Release (). This will do the correct reference counting. But remember that this will not copy the contents of the surface. If this is what you want you will have to create a new surface in the constructor and to Blt. But I doubt that this is what you really want to do.

And for the tags have a look at the FAQ.
Muhammad Haggag
Muhammad Haggag
Quote:
Original post by kubicon
I don't know what the code tags are, and I don't see a code tag button so I'm just gonna take a guess for now.

For the formatting rules, read GDNet Forums FAQ

Quote:

//m_surface = rhs.m_surface; // this just copies the pointer?

Yes, this would just copy the pointer.

Quote:
memcpy(m_surface,rhs.m_surface, sizeof(rhs.m_surface));

sizeof(rhs.m_surface) is the size of the pointer, which is 4 bytes on our 32-bit systems.

if m_surface is LPDIRECTDRAWSURFACE, then copying should be done in a different way. You should create another surface with the same dimensions, and IDirectDrawSurface7::Blt to it.

kubicon
kubicon
Quote:

When copying you should call m_surface->AddRef (). In the destructor call m_surface->Release (). This will do the correct reference counting. But remember that this will not copy the contents of the surface. If this is what you want you will have to create a new surface in the constructor and to Blt. But I doubt that this is what you really want to do.


Yeah, AddRef()/Release() sounds like what I'm looking for.

Thanks

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.