Sign in to follow this  

More vs2003 trouble

This topic is 4532 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

Hi, I am trying to make a tetris clone with c++ vs2003, and directx. I have an area where just a plain block, for right now, drops to the bottom. When it hits the bottom I stop it and create another block. The problem I am having is when I hit the play button in debug, when it tries to create a new block it error's out in the memcpy function when It creates the vertices. If i hit ctrl-f5 to run, it creates the next block but when it tries to create the 4th one it gives me the memory referenced at whatever address could not be read. So that tells me it doesn't exist yet. When I change it to release it just errors out in the memcpy. VS2003 is getting on my nerves. First of all could this be a problem with my computer memory, or vs2003, or my code is all wacked out only sometimes its ran. if its vs2003 is there a compiler i could use, i dont need a visual interface.

Share this post


Link to post
Share on other sites
There is only a 0.000001% probability that the problem is with the compiler or your computer, and a 99.99999% probability that the problem is in your code.

Figure out what memcpy is complaining about. Find out where the addresses come from and verify that they are valid. Make sure the size value is correct.

Consider replacing memcpy with something not so prone to generating bugs.

Share this post


Link to post
Share on other sites
I can't figure where it comes from in my code, because it works sometimes. If something works how do you make it work, when it errors out sometimes? I've never had a problem like this before I switched to 2003.

EDIT: Well I can't get anything to render now, it look like it giving me a memory error before WinMain. Here is my code, please tell me theres something wrong with it because I am going crazy.




m_VerticesTextured[0].Position = m_v3Points[0];
m_VerticesTextured[0].Tu = 0.0f;
m_VerticesTextured[0].Tv = 0.0f;
m_VerticesTextured[1].Position = m_v3Points[1];
m_VerticesTextured[1].Tu = 0.0f;
m_VerticesTextured[1].Tv = 1.0f;
m_VerticesTextured[2].Position = m_v3Points[2];
m_VerticesTextured[2].Tu = 1.0f;
m_VerticesTextured[2].Tv = 1.0f;
m_VerticesTextured[3].Position = m_v3Points[3];
m_VerticesTextured[3].Tu = 1.0f;
m_VerticesTextured[3].Tv = 0.0f;

if(FAILED(GetDevice()->CreateVertexBuffer(sizeof(m_VerticesTextured) * 4,
D3DUSAGE_WRITEONLY, xCustomVertex::PositionTextured::Format,
D3DPOOL_DEFAULT, &m_pVB, NULL)))
{
return;
}

VOID *Ptr = NULL;
m_pVB->Lock(0, sizeof(m_VerticesTextured) * 4, (VOID**)&Ptr, 0);
memcpy(Ptr, m_VerticesTextured, sizeof(m_VerticesTextured) * 4); //ERRORS RIGHT HERE
m_pVB->Unlock();




[Edited by - cptrnet on July 18, 2005 3:41:49 PM]

Share this post


Link to post
Share on other sites
I concur; while I have seen bugs in compilers before, I'd say the chance of a given bug in a program being the compiler's fault is like 0.01% or less. Verify that all the things you memcpy are valid pointers, and that the sizes you memcpy are correct. Also, the way it compiles code in debug and release build is different, so problems in your code may cause different bad things to happen in debug and release build even if the compiler has made no errors.

EDIT:
memcpy(Ptr, m_VerticesTextured, sizeof(m_VerticesTextured) * 4); //ERRORS RIGHT HERE

Uhh... shouldn't it be impossible to memcpy 4x the size of m_VerticesTextured from m_VerticesTextured itself? If it's not impossible, you're doing something very evil, like copying multiple arrays in a single memcpy, which the compiler could be doing something to break.

[Edited by - Catafriggm on July 18, 2005 4:56:05 PM]

Share this post


Link to post
Share on other sites
Where do you declare m_VerticesTextured? Cause if it's like this:

VERTEX m_VerticesTextured[4];

(Replacing VERTEX with the name of whatever structure you use), then you problem is this line:

memcpy(Ptr, m_VerticesTextured, sizeof(m_VerticesTextured) * 4);

Where sizeof(m_VerticesTextured) will already be the complete size of the structure * 4. If it's just declared as a pointer, then sizeof(m_VerticesTextured) will be 4 on a 32-bit compiler.

So either way, you're doing something wrong there. Try replace the sizeof with sizeof(VERTEX) (again, whatever the name of your actual structure is) in both that line and the one above it, and see what happens.

And it's usually a better idea to think a bug is not in your compiler. Period. I wouldn't even put that "0.0001%" qualifier that the other guys put in there, because it's probably much lower than even that. The C++ compiler in VC++ 2003 is one of the best compilers money can buy.

Share this post


Link to post
Share on other sites

This topic is 4532 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.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this