Jump to content
  • Advertisement

Archived

This topic is now archived and is closed to further replies.

Roof Top Pew Wee

Quite the curious problem with saving surfaces to a file.

This topic is 6079 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

This problem has been troubling me and I have written many posts about it, however, I have narrowed the problem down, but I still don't understand. Here's the code: void savePackage(char* FileName, terrainPackageSurfaces* packageSurfaces) { DDSURFACEDESC2 ddsd; memset(&ddsd, 0, sizeof(ddsd)); ddsd.dwSize = sizeof(ddsd); ofstream outfile; outfile.open(FileName, ios::app | ios::binary); for(int j = 0; j < 84; j++) { if(packageSurfaces->ifAssigned[j] && packageSurfaces->surfaces[j] != NULL) { packageSurfaces->surfaces[j]->GetSurfaceDesc(&ddsd); // get the description for the width outfile.write( (char*)((void*)packageSurfaces->surfaces[j]) , ddsd.lPitch*ddsd.dwHeight); } } outfile.close(); } A terrainPackageSurfaces object contains 84 LPDIRECTDRAWSURFACE7's. So here's the problem. When I save this, I should be getting rather large files (easily over half a MB and up to 18 MB depending on how many I have loaded). However, the file is usually very small, around 2, 4, 6, or 8 KB. I asked a similar question and found out that if the second argument in the write() function, which happens to be the length in bytes, exceeds the length of the first argument, the result is "unpredictable". So it is likely that I am exceedinging the pointer to the surface. However, I don't see how because I am getting the size directly from the surface each loop and using it to write to the file. My first idea was that maybe I am somehow going over, so I erased ddsd.dwHeight, and replaced it with 50 (this is half of what ddsd.dwHeight is because all of the surfaces are 100 pixels high). I still got the problem. I lowered the number to 30, and again got the problem. I then lowered it to 5, and I finally got a file of appropriate size, but I'm sure that my surfaces are taller than 5 pixels. My second idea was that perhaps the memory on the card is not linear, but I asked around and most people told me that almost all cards have linear memory, especially the popular ones. I have a 32 MB TNT2 RIVA card, so I don't think that could be the problem. This has been stumping me for over 2 weeks now, so if anyone could help, I'd much appreciate it. --Vic-- Edited by - Roof Top Pew Wee on November 23, 2001 1:59:31 PM Edited by - Roof Top Pew Wee on November 23, 2001 2:01:34 PM

Share this post


Link to post
Share on other sites
Advertisement
ok... can you post the definitions of your data types ? (esp. terrainPackageSurfaces->surfaces );

Share this post


Link to post
Share on other sites
class terrainPackageSurfaces
{public:
int howManyLoaded;
LPDIRECTDRAWSURFACE7 surfaces[84];
bool ifAssigned[84];
DDSURFACEDESC2* ddsd;
terrainPackageSurfaces(){};
terrainPackageSurfaces(DDSURFACEDESC2* DDSD)
{ ddsd = DDSD; // will be used later
for(int i =0; i < 84; i++)
ifAssigned[ i] = false;
};
~terrainPackageSurfaces()
{
for(int i = 83; i > -1; i--)
if(surfaces[ i])
{
surfaces[ i]->Release();
surfaces[ i] = NULL;
};
}

void makeNew()
{
howManyLoaded = 0;
for(int i = 0; i < 84; i++)
{
ifAssigned[ i] = false;
surfaces[ i] = NULL;
}
}

void fillSurface(int whichToFill, LPDIRECTDRAWSURFACE7 surfaceToUse,
RECT* rectToUse = NULL)
{
surfaces[whichToFill]->Blt(NULL,
surfaceToUse,
rectToUse,
DDBLTFAST_WAIT|DDBLTFAST_NOCOLORKEY,
NULL);
ifAssigned[whichToFill] = true;

bool toFill = true;
howManyLoaded = 0;
for(int i = 0; i < 4; i++)
{
if(ifAssigned[ i] == false)
toFill = false;
}

if(toFill)
{ howManyLoaded++;
}
else
return;

for(int j = 0; j < 4; j++)
{
for(int h = 0; h < 20; h++)
{
if(ifAssigned[4 + h + 20*j] == false)
{
toFill = false;
}// end of if empty
}// end of separate surfaces in one texture
if(toFill)
howManyLoaded++;
else
return;
}// end of each texture
}// end of fillSurface function

LPDIRECTDRAWSURFACE7* assignTexture(int whichToAssign)
{
if(ifAssigned[whichToAssign])
return &surfaces[whichToAssign];
else
return NULL;
}
}; // end of terrainPackageSurfaces class

I don't think this'll help ya much, because there is also the filling of the surfaces, which is quite lengthy because it involves loading bitmaps, splitting them up and some strange assigning. But the surfaces are filled, and if not, there are tests for them. If they were empty, I would have a file size of 0, because that is all that I'm saving. The only other problem I am thinking of is maybe the terrainPackageSurfaces object gets messed up somewhere because there are about 3 or 4 functions it goes through. to get to this one. But again, I have gone over the code over and over again. I will look again. This post was mainly to see if anyone had any other ideas where I might be having errors, or if there are any evident ones.

Oh, one more thing. I have seen people have white squares with code in them. It is much neater than putting code here. Can anyone tell me how to do that?

--Vic--

Edited by - Roof Top Pew Wee on November 23, 2001 2:34:23 PM

Edited by - Roof Top Pew Wee on November 23, 2001 2:36:14 PM

Share this post


Link to post
Share on other sites
LPDIRECTDRAWSURFACE7 objects probably hold a pointer to the surface instead of the surface itself, I''m going to look it up (Need to instal DX first...)

Share this post


Link to post
Share on other sites
Oh, and you display source code by bracketing source and /source in square brackets ''['' and '']''

Share this post


Link to post
Share on other sites
Yeah, LP is long* I believe, but that''s exactly what I want, because I''m using the value in LPDIRECTDRAWSURFACE7 (or the address) as the address of where to look for the memory on the video card. I think this is right. I also checked to see if the surfaces are getting ruined through the different function calls, like if I am messing something up before the function. I moved the save code outside of all of the function calls and tried to write the file with the original object. I know the original object works, because I am blitting from it in my program. I get the same result (a file of about 2.17 kb), so I guess we can assume that the object being passed to the object is correct and the problem is in the function somewhere.

--Vic--

Share this post


Link to post
Share on other sites
No, what I mean is that LPDIRECTDRAWSURFACE7 itself would be a struct like that

struct DDS7
{
pixel_t* data;
.
.
.
};

which means that when you''re printing the object, you''re not printing the data.

Try using DirectDrawSurface7.Lock to get a pointer to the data.

Share this post


Link to post
Share on other sites
I'm not completely sure, what you exactly want, but if you want
to access the bitmap of a surface you have to call the Lock () method of the surface to get a pointer to the surface data (it id the stored in the DDSURFACEDESC2 structure you have to pass
to Lock ()).

Oops, didn't read all of Fruny's post.

Edited by - VolkerG on November 23, 2001 3:30:18 PM

Share this post


Link to post
Share on other sites
quote:
Original post by Fruny
DirectDrawSurface7.Lock

Fruny, you''re a VB coder?

Yeah, just dumping the pointer would have been writing out a load of COM function pointers, hence it only being small...


Superpig
- saving pigs from untimely fates
- sleeps in a ham-mock at www.thebinaryrefinery.cjb.net

Share this post


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!