Data corruption

This is a discussion on Data corruption within the C++ Programming forums, part of the General Programming Boards category; Hello! I have come to a weird problem. My data seems to corrupt somehow with a little piece of code ...

  1. #1
    Registered User
    Join Date
    Aug 2006
    Posts
    62

    Data corruption

    Hello!
    I have come to a weird problem. My data seems to corrupt somehow with a little piece of code that is not at all connected to the thing that corrupts.

    Code:
    if(FAILED(D3DXCreateTextureFromFile(DirX_Device, render_info[i].tex_name, &Texture[tex_count])))
    			{
    				//Error processing
    			}
    			else
    			{
    				render_info[i].Texture=&Texture[tex_count];
    				tex_count=tex_count+1;
    			}
    This bit of code corrupts data. It always seems to corrupt a certain data, but when I changed some code(not that piece of code) it started corrupting entirely different data.
    My variable which should be 112 changes into something like 78590343 and before a char value "test" changed into "-|>*".

    I have absolutely no idea what do do. The Texture loading code should use the right data, I checked it.

  2. #2
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Quote Originally Posted by fighter92 View Post
    Hello!
    I have come to a weird problem. My data seems to corrupt somehow with a little piece of code that is not at all connected to the thing that corrupts.

    Code:
    if(FAILED(D3DXCreateTextureFromFile(DirX_Device, render_info[i].tex_name, &Texture[tex_count])))
    			{
    				//Error processing
    			}
    			else
    			{
    				render_info[i].Texture=&Texture[tex_count];
    				tex_count=tex_count+1;
    			}
    This bit of code corrupts data. It always seems to corrupt a certain data, but when I changed some code(not that piece of code) it started corrupting entirely different data.
    My variable which should be 112 changes into something like 78590343 and before a char value "test" changed into "-|>*".

    I have absolutely no idea what do do. The Texture loading code should use the right data, I checked it.
    Well, "your variable" (you didn't say which one) obviously is getting set to a value that is not correct. Run your program through a debugger, set breakpoints, or put in printf() statement to watch it as it is changed.

    Debugging 101.
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  3. #3
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    There's no need to name the variable as it isn't used in that code anyway. I have already debugged and I have no idea why it changes there. It seems to have no logical connection. I have never had such problem before. There is nothing that changes that variable there, although I've detected (with the help of debugging) that it changes there.

    How can the variable change if there is nothing that affects that variable?

  4. #4
    Jack of many languages Dino's Avatar
    Join Date
    Nov 2007
    Location
    Katy, Texas
    Posts
    2,309
    Quote Originally Posted by fighter92 View Post
    How can the variable change if there is nothing that affects that variable?
    I suspect your code is broken somewhere, and your variable is getting clobbered by it. So, to state that nothing is affecting it is probably an incorrect assumption on your part, unless your code is just wrong to start with, but I'm giving you the benefit of doubt in that regard.

    Stack overflows caused by programming mistakes happen daily here (if not hourly).
    Mac and Windows cross platform programmer. Ruby lover.

    Quote of the Day
    12/20: Mario F.:I never was, am not, and never will be, one to shut up in the face of something I think is fundamentally wrong.

    Amen brother!

  5. #5
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    I narrowed the variable changing part more down.

    Code:
    D3DXCreateTextureFromFile(DirX_Device, render_info[2].tex_name, &Texture[2]);
    I'm absolutely sure the variable that changes isn't one of those that are used in this line.
    What should I check next?

  6. #6
    and the Hat of Guessing tabstop's Avatar
    Join Date
    Nov 2007
    Posts
    14,185
    If you're certain this line (with this value of i) changes some other variable: then either render_info[2] doesn't exist or Texture[2] doesn't exist. My bet would be the latter, since that's where the texture is supposed to be written to -- if there's not a valid texture variable there you're going to trash some memory.

  7. #7
    Registered User
    Join Date
    Aug 2006
    Posts
    62
    There are two possibilities
    1) I'm an idiot.
    2) My memory fails me.

    Problem is solved.
    Code:
    LPDIRECT3DTEXTURE9		Texture[1];

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 48
    Last Post: 09-26-2008, 03:45 AM
  2. singly linked circular list
    By DarkDot in forum C++ Programming
    Replies: 0
    Last Post: 04-24-2007, 08:55 PM
  3. Heap corruption using zlib inflate
    By The Wazaa in forum C++ Programming
    Replies: 0
    Last Post: 03-29-2007, 12:43 PM
  4. Program Crashing
    By Pressure in forum C Programming
    Replies: 3
    Last Post: 04-18-2005, 10:28 PM
  5. Replies: 1
    Last Post: 07-31-2002, 11:35 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21