void CStar::Draw(D3DCOLOR* Pixels, int Pitch)
{
int index = ((int)m_y * Pitch + (int)m_x);
for(int i = 0; i < m_length; i++)
{
Pixels[index + i*Pitch] = StarColors[i]; Here
}
}
the MS VC debugger sets the error indicating arrow (the yellow arrow) right in front of the int index = ((int)m_y * Pitch + (int)m_x);
and says "Error writing at location"...
Do i do something wrong with the pointer?...
What drives me crazy is the fact, that this works while trying this with an simple array of x- and y- coordinates outside a class (just within the WM_PAINT-message)...
[EDIT]: when i expand the "this"-Pointer it cant resolve/show me the m_x, m_y, m_dy and m_length - members...
Originally i did let my StarField-Class lock the Surface but that didnt work, too... so i tried to lock it for any access (what definetly is not very fast)
Check for overflow in Pixels[index + i*Pitch] when passing a pointer to be used as an array you should also pass the array size so you can check it
eg:
1 2 3 4 5 6 7 8 9 10 11 12
void CStar::Draw(D3DCOLOR* Pixels, int size, int Pitch)
{
int index = ((int)m_y * Pitch + (int)m_x);
for(int i = 0; i < m_length; i++)
{
int pixel_index = index + i*Pitch;
if ( pixel_index >= size )
break; //exit from the loop as continuing would cause overflow
Pixels[ pixel_index ] = StarColors[i];
}
}
void CStar::Draw(D3DCOLOR* Pixels, int Pitch)
{
>>>Error Marker Goes here<<<int index = ((int)m_y * Pitch + (int)m_x);
for(int i = 0; i < m_length; i++)
{
Pixels[index + i*Pitch] = StarColors[i]; Here
}
}
2. I dont know how to get the size of the the space allocated behind the pointer, because D3DLOCKED_RECT:
1 2 3 4 5
typedefstruct _D3DLOCKED_RECT
{
INT Pitch;
void* pBits;
} D3DLOCKED_RECT;
where pBits is an Pointer to the memory for the Pixels which needs to be casted...
and Pitch is the memory in bytes reserved for image informations in the memory allocated to pBits... I need to divide it by 4, because i use 32bit Color Formats...
[EDIT]:: according to this my Arrays size is (on my GPU - Pitch == 3200) in Bytes would be 3200 bytes * 600 rows... =1920000 bytes... devided by 4 = 480000 ... muahrahrahrhar... the maximum acess i do is 480800 for the point x = 800, y = 600 T_T... but the space behind that should still be accessible, because its about 1920000 bytes for the whole thing ...
(http://msdn.microsoft.com/en-us/library/bb206357%28VS.85%29.aspx)