Re: Loop Does'nt Work, Hard code does

From: Daniel T. (postmaster_at_eathlink.net)
Date: 08/31/04


Date: Tue, 31 Aug 2004 11:28:22 GMT

In article <86VYc.263646$eM2.249913@attbi_s51>,
 "Nick L" <Fearnot003@mchsi.com> wrote:

> I'm working on a function which creates a pointers to an array of unsigned
> ints based off a number read from a file. I then continue to read file names
> from the file, convert the name to a char* and use it to load an texture
> from some outside functions. My problem lies in the "for loop", the Code
> goes as follows.
>
> //I create the array of pointers, I'm using 2 just for the sake of an
> example
> MapTextures = new unsigned int[2];
>
> //Start up a for loop
> for(int I = 0; I < 2; I++)
> { //I then read the filename from the file.
> LevelStream >> Cmd;
> //Convert the string I read to a char*
> Name = strdup (Cmd.c_str());
> //Use the filename to load the coorisponding image into the first
> element on the array
> MapTextures[I] = LoadTextureWithAlpha(Name);
> }

Your code looks like it leaks memory. Why are you using strdup?

const size_t limit = 2;
unsigned* MapTextures = new unsigned[limit];

for ( unsigned i = 0; i < limit; ++i ) {
   string Cmd;
   LevelStream >> Cmd;
   MapTextures[i] = LoadTextureWithAlpha(Cmd.c_str());
}

> This is the way I'd like to do it, but for some reason it does'nt work and
> for the life of me I can't figure out why. When the code executes it will
> read both file names and convert them just fine, but it will only load one
> texture.

When you say it will only load one texture, do you mean that both
MapTextures elements contain the same value?



Relevant Pages

  • Re: Fast mip-map generation
    ... Mip-Map Generation of this memory ... The next step is linear averaging, where you simply take 0.25*sum(four_source_pixels), possibly after ungamma-conversion of each of the source pixels. ... If you do go this route, then you should probably first convert the source texture to linear format, then generate all the reduced size texture before converting back to whatever format you want your texture to be in. ... load four source pixels into xmm0..xmm3. ...
    (comp.lang.asm.x86)
  • Re: Two simple meshes - memory gone
    ... I load two meshes, tiger.x and bigship1.x (both ... calling a method from an invalid ID3DXBuffer pointer if the model fails to ... name, but there can be materials that don't have a texture mapped to them, ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: Compressed textures
    ... then load the texture into a plain surface in system memory and use ... When a movie is small enough, I readit into system memory as a binary stream defining the texels of different frames. ... Whenever I need a new video frame in the texture, I lock the texture, write the bytes and unlock it. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: How to manualy copy managed texture from systemem to real vide
    ... > Yes, we set D3DCREATE_MULTITHREADED flag. ... > Flying objects in my 3D scene jerk even if I load only one new texture. ... > VRAM) fully STOPS 3D accelerator WHILE it loads a new texture to VRAM. ...
    (microsoft.public.win32.programmer.directx.graphics)
  • Re: DirectX and ScreenSaverProc
    ... just set the new texture pointer for changing it on the cube... ... > How do you suggest that I load all the pictures of a given directory? ... >> app main loop is a big no-no for performance... ...
    (microsoft.public.win32.programmer.directx.graphics)