Help ..Can't convert value to a vector "C" API

I'm having this code copied from a stream which is a game in "C" + API, and I get one error like |error: can't convert value to a vector|, and a warning excess elements in vector initializer.
Now here is the code:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
#include <windows.h>
#include <stdint.h>
#include <emmintrin.h>
..
...
....
typedef struct GAMEBITMAP
{
    BITMAPINFO BitmapInfo; // 44 Bytes
    void* Memory; // 4 Bytes
} GAMEBITMAP;

typedef struct PIXEL32
{
    uint8_t Blue;
    uint8_t Green;
    uint8_t Red;
    uint8_t Alpha;
} PIXEL32;
...
..
..

void RenderFrameGraphics(void)
{
    /*PIXEL32 Pixel = {0};

    Pixel.Blue = 0x7f;
    Pixel.Green = 0;
    Pixel.Red = 0;
    Pixel.Alpha = 0xff;*/ --> this is working

    __m128i QuadPixel = {0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff, 0x7f, 0x00, 0x00, 0xff};

    for(int i = 0; i < GAME_RES_WIDTH * GAME_RES_HEIGHT; i += 4)
    {
        _mm_store_si128((__m128i)BackBuffer.Memory + i, QuadPixel); //NOT working
        //this is working..
        //memcpy((PIXEL32*)BackBuffer.Memory + i, &Pixel, sizeof(PIXEL32));
    }

    HDC DeviceContext = GetDC(gameWindow);

    StretchDIBits(DeviceContext, 0, 0, PerformanceData.MonitorWidth, PerformanceData.MonitorHeight, 0, 0, GAME_RES_WIDTH, GAME_RES_HEIGHT,
                  BackBuffer.Memory, &BackBuffer.BitmapInfo, DIB_RGB_COLORS, SRCCOPY);

    ReleaseDC(gameWindow, DeviceContext);
}


Now I know what I saw and.. yes excess elements in the vector I'm okay with that instead of 16 this probably will be __m128i QuadPixel = {0x7f, 0x00};

But everytime I try to learn something and MAYBE working example I always fail, when everyone is using V.S. it doesn't have problems with the code and even compiles vs Code::Blocks ?
Why in Visual Studio the compiler doesn't complain about this: |error: can't convert value to a vector| and not even for the warnings when exceeded elements.. ?
Can someone clarify me why this ..?
Thank you..
Last edited on
std::vector has a data() method that returns the raw memory that you can use in a program (along with size()),

I don't see the declaration of _mm_store_si128() or BackBuffer.Memory, so I can't comment on their use.
If I'm not mistaken, __m128i is referring to the total size of the register.
0x7f, 0x00, 0xff, etc. are all integers, probably 32-bit each.
So you're exceeding the register value's capacity.
Last edited on
Topic archived. No new replies allowed.