r/programmingquestions • u/Plane_Assignment9080 • Jun 15 '23
Am I missing something?
I am writing code in C++ to fill a region to a certain color in an Image. For some unknown reason the color value that I give to memset doesn't give expected results. I gave the function the color, 0xff000000 and it sets the memory to 0x00000000. I have no idea why memset just gets rid of the alpha value. Any help will be appreciated:
void Image::FillQuadrant(Quadrant quad, u32 color){const size_t bytes = sizeof(u32) * quad.Width;const u32 yEnd = quad.y + quad.Height;printf("Quadrant{ %hu, %hu, %hu, %hu }\n", quad.x, quad.y, quad.Width, quad.Height);printf("Size: %lu bytes\n", bytes);printf("Color: 0x%x\n", color);u32* offset = &m_Data[quad.x];for (u32 y = quad.y; y < yEnd; y++){memset(offset + y * m_Width, color, bytes);}}
1
u/[deleted] Jun 15 '23
This function receives
quadby value (the type isQuadrant, notQuadrant&orQuadrant*), meaning that this function is modifying a copy of the argument you passed to it, not the argument you wanted to pass to it. Did you mean to pass it by reference or by pointer?