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

Find the differences

Started by ofer Jan 13, 2003 at 1:07 PM 4 replies 450+ views
Original Post
ofer
ofer
well, d3d9 is giving me a lot of hard time. this time, the problem is with how i set the index buffer. one way works, and the other doesnt, although its identical. here is the code - method A (works) - short Index[] = {0,3,1,4,2,5,8,4,7,3,6}; int* I; I = NewMesh->LockIB(); memcpy(I,Index,sizeof(Index)); NewMesh->IB->Unlock(); with this method the whole mesh is drawn correctly. method B (doesnt work) 0 short Index[] = {0,3,1,4,2,5,8,4,7,3,6}; int* I; I = NewMesh->LockIB(); for (i=0; i = Index[i]; } NewMesh->IB->Unlock(); with this method, the mesh isnt drawn correctly. i dont see the difference. what i really want to do, is to fill the index buffer procedurally, and it is filled correctly, but the mesh is drawn wrong, so i narrowed the bug to differenc between using those two methods, and i cant get the second one to work. and ideas?
S1CA
S1CA
Unless you're using 32bit indices, then I should be defined as "short*", or more correctly "unsigned short*", and definately not int* which will end up as a pointer to 32bit data under most Windows compilers.

--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com

[edited by - S1CA on January 13, 2003 2:21:16 PM]
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Dave Hunt
Dave Hunt
Well, in your loop, you said

I = index

This sets I (a pointer) to the value of index[i]. What you really want is to store the contents of index at the address pointed to by I. Something like

I[i] = index[i]

That's why the memcpy works - it is correctly copying the contents of index to the address pointed to by I.


EDIT - Never mind. I hate it when we forget to use code tags in our posts

[edited by - Dave Hunt on January 13, 2003 2:30:56 PM]
S1CA
S1CA
quote:
Original post by Dave Hunt
Well, in your loop, you said

I = index

This sets I (a pointer) to the value of index[i]. What you really want is to store the contents of index at the address pointed to by I. Something like

I[i] = index[i]

That's why the memcpy works - it is correctly copying the contents of index to the address pointed to by I.




Unfortunately the board code for introducing italic characters clashes with using i as the index variable for array access
[ i ]  
.

Tell tale sign is the remainder of the text appearing in italics.

A tip that I use to check whether the original poster uses i as an array index or got their code wrong is to click the edit button on the original posters post (you don't need to be a moderator). You can't actually "edit" what they wrote, but you do get to see exactly what they typed before any board formatting was added.

It's the int*, the memcpy() casts the destination pointer and copies as bytes so the fact that int* implies a set of (32bit) integer wide data, memcpy ignores that. The loop and array operator however don't and increment the destination address in 32bit chunks - so half the indices in the IB are screwed.



--
Simon O'Connor
Creative Asylum Ltd
www.creative-asylum.com


[edited by - S1CA on January 13, 2003 2:37:35 PM]
Simon O'Connor | Technical Director (Newcastle) Lockwood Publishing | LinkedIn | Personal site
Dave Hunt
Dave Hunt
Simon,

Thanks for the edit tip.

Your spot on with your explanation of the cause of his problem. I failed to notice the short vs int in his posted code.
ofer
ofer
ill try this bit issue. i hope itll fix it. thank you.


EDIT - well, it looks like it fixed it, thnx alot.

[edited by - ofer on January 13, 2003 4:41:31 PM]

Topic Locked

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

Sign in to reply to this topic.