I have started to learn Direct3D 11 graphics recently and was able to create a simple interface capable of rendering 3D graphics, and them I've tried to organize it in classes, but a problem is already giving me a headache. I have created my ID3D11Device and initialized it with D3D11CreateDeviceAndSwapChain function, but what happens is, right after the function where I initialized it ends, the device goes back to a nullptr value, so when I need it in another parts of the code, it's value is not initialized anymore(this also happens with device context). I have already tried everything I could think of, make it static, declare in global space, pass it's value by reference before it gets reset, declare other functions that uses it in the same function and even set them to be inline, but nothing worked. I really don't know why it loses the value assigned to it, hope someone can help me to solve this. Here's part of the code where the issue happens:
//Code goes here...
hr = D3D11CreateDeviceAndSwapChain(NULL, D3D_DRIVER_TYPE_HARDWARE, NULL, D3D11_CREATE_DEVICE_DEBUG, NULL, NULL, D3D11_SDK_VERSION, &scd, &pSwapChain, &pDevice, NULL, &pDeviceContext);
// Function goes fine, now pDevice is a valid COM object until the end of the function.
//Code goes here...
//End of the function.
LoadShaders()
pDevice->CreateVertexShader(code here); //Impossible to create vertex shader because pDevice is nullptr again.
Just to be clear my program is initiliazing Direct3D 11 normally, I've already tested it, my only problem is my objects losing data(apparently).