I am trying to create a Directx 11 program using c++ . The code used to work before I added Normal to the code .Now it doesnt compile the shader at all .It keeps giving me access Violation 0X0000 Error.
I tried using d3dErrorBlolb but wasnt very helpful.The problem seems to lie in this part of the code.
void InitPipeline(HWND hwnd)
{
ID3D10Blob * BVS = 0,*BPS = 0;
ID3D10Blob * BErrorVS,*BErrorPs;
HRESULT hr1 = D3DX11CompileFromFile(L"Test.fx",0,0,"VS","vs_4_0",0,0,0,&BVS,&BErrorVS,0);
HRESULT hr = D3DX11CompileFromFile(L"Test.fx",0,0,"PS","ps_4_0",0,0,0,&BPS,&BErrorPs,0);
if(FAILED(hr))
{
printf("Error %08X %5s\n",hr,(char*)BErrorVS);
MessageBox(hwnd,L"Pixel shader not created ",L"",0);
}
if(FAILED(hr1))
{ MessageBox(hwnd,L"Vertex shader not created ",L"",0);}
dev->CreateVertexShader(BVS->GetBufferPointer(),BVS->GetBufferSize(),0,&BoxVShader);
dev->CreatePixelShader(BPS->GetBufferPointer(),BPS->GetBufferSize(),0,&BoxPixelShader);
// create the input layout object
D3D11_INPUT_ELEMENT_DESC ied[] =
{
{"POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0},
{"NORMAL",0,DXGI_FORMAT_R32G32B32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0}
// {"COLOR", 0, DXGI_FORMAT_R32G32B32A32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0}
};
//SecureZeroMemory(&Bin);
dev->CreateInputLayout(ied,2,BVS->GetBufferPointer(),BVS->GetBufferSize(),&BInputLayout);
devcon->VSSetShader(BoxVShader,0,0);
devcon->PSSetShader(BoxPixelShader,0,0);
devcon->IASetInputLayout(BInputLayout);
}
The Test.fx file
ecbuffer ConstantBuffer:register(b0)
{
matrix world;
matrix view;
matrix project;
float3[2] LightDir;
float4[2] LightColor;
}
struct Vout{
float4 pos:SV_POSITION;
float4 normal : NORMAL;
};
Vout VS(float3 pos:POSITION,float3 Norm:NORMAL)
{
Vout vo = (Vout)0;
vo.pos = mul(float4(pos,1),world);
vo.pos = mul(vo.pos,view);
vo.pos = mul(vo.pos,project);
vo.normal = mul(float4(Norm,1),world);
return vo;
}
float4 PS(float4 pos:SV_POSITION,float4 normal:NORMAL):SV_TARGET
{
float4 col;
for(int i=0; i < 2;++i)
{
col += saturate(dot(normal,LightDir[i])) * LightColor[i] ;
}
return col;
}
Can anyone please be kind enough to help me out...
If possible please do explain why this keeps happening always..What am I doing wrong here
Please do help me.I desperately need to solve this problem....
Thank you...
While compiling HLSL at runtime is nice for learning and iteration, it's actually a lot easier to debug the HLSL by compiling it with the command-line:
fxc test.fx /Tvs_4_0 /EVS and fxc test.fx /Tps_4_0 /EPS
The second fails because you failed to set the initial value for col in the Pixel Shader:
test.fx(40,25-47): warning X3206: 'dot': implicit truncation of vector type
test.fx(40,9-64): error X4000: variable 'col' used without having been completely initialized
compilation failed; no code produced
The fix is trivial:
float4 PS(float4 pos:SV_POSITION,float4 normal:NORMAL):SV_TARGET
{
float4 col = 0;
for(int i=0; i < 2;++i)
{
col += saturate(dot(normal,LightDir[i])) * LightColor[i] ;
}
return col;
}
You are getting an AV because you have the wrong handling of the failed compiler output, you forgot to initialize both BErrorVS and BErrorPS to null, and you are trying to output BErrorVS when the VS succeeded, but the PS failed. It should be:
if(FAILED(hr))
{
printf("Error %08X %5s\n",hr,(char*)BErrorPS->GetBufferPointer());
MessageBox(hwnd,L"Pixel shader not created ",L"",0);
}
Also you should remember that BErrorVS and BErrorPS can be set to a non-null value even if SUCCEEDED(hr)) since it can be reporting only non-fatal warnings.
See HLSL, FXC, and D3DCompile
Related
I'm working on a ray tracing pixel shader and came across a weird error. I wrote the following code solely to generate the error, it's pointless but I can't figure out what's wrong with it.
float4 main(/*Any input*/) : SV_TARGET
{
uint uints[2];
float4 light[2];
uints[0] = 0;
uints[1] = 0;
uint c = 1;
[loop] while (c > 0) {
if (uints[c] == 0)
light[c - 1] = 0.0f;
else
light[c - 1] = 0.0f;
c--;
break;
}
return light[0];
}
When compiled with shader model 5_0 (with and without optimizations) I get the following error:
error MSB6006: "fxc.exe" exited with code -1073741819
Doing seemingly meaningless things to the code, like removing c--;, gets rid of the error. Can anyone figure out what this weird error comes from?
In my case it compiles if I remove the [loop] tag.
// Compiling pixel shader
ComPtr<ID3DBlob> pixelBlob = nullptr;
ComPtr<ID3DBlob> pixelErrorBlob = nullptr;
result = D3DCompile(pixelShaderByteCode.c_str(),
pixelShaderByteCode.length(),
nullptr,
nullptr,
nullptr,
"main", "ps_5_0",
compileFlags, 0,
pixelBlob.GetAddressOf(),
pixelErrorBlob.GetAddressOf());
float4 main(PixelInput input) : SV_TARGET
{
uint uints[2];
float4 light[2];
uints[0] = 0;
uints[1] = 0;
uint c = 1;
while (c > 0) {
if (uints[c] == 0)
light[c - 1] = 0.0f;
else
light[c - 1] = 0.0f;
c--;
break;
}
return light[0];
}
I am working on a game engine using DirectX 11 and am having trouble getting shaders to encode properly. I am precompiling shaders to .csh files and creating shaders with the byte codes.
I get this error when I try to create any shader, but for this example I will use my PassThrough vertex shader.
D3D11 ERROR: ID3D11Device::CreateVertexShader: Encoded Vertex Shader size doesn't match specified size. [ STATE_CREATION ERROR #166: CREATEVERTEXSHADER_INVALIDSHADERBYTECODE]
The Shader:
#include "../VertexLayouts.hlsli"
// structs in included file
struct PASS_THROUGH_VS
{
float3 pos : POSITION;
float2 texCoord : TEXCOORD;
};
struct PASS_THROUGH_PS
{
float4 pos : SV_POSITION;
float2 texCoord : TEXCOORD;
};
PASS_THROUGH_PS main( PASS_THROUGH_VS input )
{
PASS_THROUGH_PS output = (PASS_THROUGH_PS)(0);
output.pos = float4(input.pos, 1);
output.texCoord = input.texCoord;
return output;
}
with these settings:
PassThrough_PS properties
In Renderer.h
#include "Vertex Shaders\PassThrough_VS.csh"
In Renderer.cpp
HRESULT hrReturn;
hrReturn = CreateVertexShader(&PassThrough_VS, sizeof(PassThrough_VS), Pass_Through_VS);
if (FAILED(hrReturn)) {}
//return hrReturn;
HRESULT CRenderer::CreateVertexShader(const void* ptrByteCode, SIZE_T szByteCodeLength, eVertexShaderType type)
{
HRESULT hrReturn;
tVertShader newShader = {};
hrReturn = D3Device->CreateVertexShader(&ptrByteCode, szByteCodeLength, nullptr, &(newShader.m_id3dShader)); // WHERE ERROR OCCURS
if (FAILED(hrReturn))
return hrReturn;
newShader.m_ptrByteCode = ptrByteCode;
newShader.m_szByteCodeLength = szByteCodeLength;
D3VertexShaders[type] = newShader;
return hrReturn;
}
The problem is you are passing a pointer-to-a-pointer, so you aren't actually passing the shader blob data to Direct3D.
HRESULT CRenderer::CreateVertexShader(const void* ptrByteCode, SIZE_T szByteCodeLength, eVertexShaderType type)
{
HRESULT hrReturn;
tVertShader newShader = {};
hrReturn = D3Device->CreateVertexShader(&ptrByteCode, szByteCodeLength,
nullptr, &(newShader.m_id3dShader));
...
The correct code is:
HRESULT CRenderer::CreateVertexShader(const void* ptrByteCode, SIZE_T szByteCodeLength, eVertexShaderType type)
{
HRESULT hrReturn;
tVertShader newShader = {};
hrReturn = D3Device->CreateVertexShader(ptrByteCode, szByteCodeLength,
nullptr, &(newShader.m_id3dShader));
...
You should take a look at DirectX Tool Kit and the tutorials in particular.
You didn't include any details about the tVertShader type, but you could well have reference counting problems. Consider using Microsoft::WRL::ComPtr instead of raw pointers for managing the lifetimes of Direct3D COM objects. See this article.
I've just started up using Direct compute in an attempt to move a fluid simulation I have been working on, onto the GPU. I have found a very similar (if not identical) question here however seems the resolution to my problem is not the same as theirs; I do have my CopyResource the right way round for sure! As with the pasted question, I only get a buffer filled with 0's when copy back from the GPU. I really can't see the error as I don't understand how I can be reaching out of bounds limits. I'm going to apologise for the mass amount of code pasting about to occur but I want be sure I've not got any of the setup wrong.
Output Buffer, UAV and System Buffer set up
outputDesc.Usage = D3D11_USAGE_DEFAULT;
outputDesc.BindFlags = D3D11_BIND_UNORDERED_ACCESS;
outputDesc.ByteWidth = sizeof(BoundaryConditions) * numElements;
outputDesc.CPUAccessFlags = 0;
outputDesc.StructureByteStride = sizeof(BoundaryConditions);
outputDesc.MiscFlags = D3D11_RESOURCE_MISC_BUFFER_STRUCTURED;
result =_device->CreateBuffer(&outputDesc, 0, &m_outputBuffer);
outputDesc.Usage = D3D11_USAGE_STAGING;
outputDesc.BindFlags = 0;
outputDesc.CPUAccessFlags = D3D11_CPU_ACCESS_READ;
result = _device->CreateBuffer(&outputDesc, 0, &m_outputresult);
D3D11_UNORDERED_ACCESS_VIEW_DESC uavDesc;
uavDesc.Format = DXGI_FORMAT_UNKNOWN;
uavDesc.ViewDimension = D3D11_UAV_DIMENSION_BUFFER;
uavDesc.Buffer.FirstElement = 0;
uavDesc.Buffer.Flags = 0;
uavDesc.Buffer.NumElements = numElements;
result =_device->CreateUnorderedAccessView(m_outputBuffer, &uavDesc, &m_BoundaryConditionsUAV);
Running the Shader in my frame loop
HRESULT result;
D3D11_MAPPED_SUBRESOURCE mappedResource;
_deviceContext->CSSetShader(m_BoundaryConditionsCS, nullptr, 0);
_deviceContext->CSSetUnorderedAccessViews(0, 1, &m_BoundaryConditionsUAV, 0);
_deviceContext->Dispatch(1, 1, 1);
// Unbind output from compute shader
ID3D11UnorderedAccessView* nullUAV[] = { NULL };
_deviceContext->CSSetUnorderedAccessViews(0, 1, nullUAV, 0);
// Disable Compute Shader
_deviceContext->CSSetShader(nullptr, nullptr, 0);
_deviceContext->CopyResource(m_outputresult, m_outputBuffer);
D3D11_MAPPED_SUBRESOURCE mappedData;
result = _deviceContext->Map(m_outputresult, 0, D3D11_MAP_READ, 0, &mappedData);
BoundaryConditions* newbc = reinterpret_cast<BoundaryConditions*>(mappedData.pData);
for (int i = 0; i < 4; i++)
{
Debug::Instance()->Log(newbc[i].x.x);
}
_deviceContext->Unmap(m_outputresult, 0);
HLSL
struct BoundaryConditions
{
float3 x;
float3 y;
};
RWStructuredBuffer<BoundaryConditions> _boundaryConditions;
[numthreads(4, 1, 1)]
void ComputeBoundaryConditions(int3 id : SV_DispatchThreadID)
{
_boundaryConditions[id.x].x = float3(id.x,id.y,id.z);
}
I dispatch the Compute shader after I begin a frame and before I end the frame. I have played around with moving the shaders dispatch call outside of the end scene and before the present ect but nothing seems to effect the process. Can't seem to figure this one out!
Holy Smokes I fixed the error! I was creating the compute shader to a different ID3D11ComputeShader pointer! D: Works like a charm! Pheew Sorry and thanks Adam!
I've been search for a good text methodolgy recently and found one at http://www.braynzarsoft.net/Articles/index.php?p=VA&article=Easy-Font-Rendering-in-DirectX-11 , which is a good site. I can't seem to get it to run! I've resolved most of the errors but, however on debug, I get HLSL errors:
D3D11: ERROR: ID3D11DeviceContext::Draw: The Vertex Shader expects application provided input data (which is to say data other than hardware auto-generated values such as VertexID or InstanceID). Therefore an Input Assembler object is expected, but none is bound. [ EXECUTION ERROR #349: DEVICE_DRAW_INPUTLAYOUT_NOT_SET ]
Creeped? I am! Since this message is spamming like mad, the issue is most likely happening in my DrawText() function or a bad implementation in the initialize function (Below)
The InitializeGeneralResources() function:
void InfiniteText::InitializeGeneralResources(){
float textureWidth=1024.0f;
UINT numLetters=32;
D3DX11CompileFromFile(L"Font.hlsl", NULL, NULL, "FONT_VS", "vs_5_0",0,0,0,&FontvsBuffer,0,0);
D3DX11CompileFromFile(L"Font.hlsl", NULL, NULL, "FONT_PS", "ps_5_0",0,0,0,&FontpsBuffer,&ppErrorMsgs,0);
iD3D.Device->CreateVertexShader(FontvsBuffer->GetBufferPointer(),FontvsBuffer->GetBufferSize(), NULL, &Fontvs);
iD3D.Device->CreatePixelShader(FontpsBuffer->GetBufferPointer(),FontpsBuffer->GetBufferSize(), NULL, &Fontps);
ID3D11InputLayout* InLayout;
D3D11_INPUT_ELEMENT_DESC IEDesc[]={
{"POSITION",0,DXGI_FORMAT_R32G32B32_FLOAT,0,0,D3D11_INPUT_PER_VERTEX_DATA,0},
{"TEXCOORD",0,DXGI_FORMAT_R32G32_FLOAT,0,12,D3D11_INPUT_PER_VERTEX_DATA,0},
};
UINT NumElements = ARRAYSIZE(IEDesc);
iD3D.Device->CreateInputLayout(IEDesc,NumElements,FontvsBuffer->GetBufferPointer(),FontvsBuffer->GetBufferSize(),&InLayout);
iD3D.DeviceContext->IASetInputLayout(InLayout);
D3D11_SAMPLER_DESC FontSamplerDesc;
FontSamplerDesc.MaxAnisotropy=1;
FontSamplerDesc.AddressU=D3D11_TEXTURE_ADDRESS_WRAP;
FontSamplerDesc.AddressV=D3D11_TEXTURE_ADDRESS_WRAP;
FontSamplerDesc.AddressW=D3D11_TEXTURE_ADDRESS_WRAP;
FontSamplerDesc.Filter=D3D11_FILTER_MIN_MAG_MIP_LINEAR;
FontSamplerDesc.MipLODBias=0.0f;
D3DX11CreateShaderResourceViewFromFile(iD3D.Device, L"Font.dds", NULL, NULL, &FontSRV, NULL);
iD3D.Device->CreateSamplerState(&FontSamplerDesc, &FontSRVSampler);
D3D11_BUFFER_DESC Vbufferdescription;
ZeroMemory(&Vbufferdescription, sizeof(Vbufferdescription));
Vbufferdescription.BindFlags=D3D11_BIND_VERTEX_BUFFER;
Vbufferdescription.Usage=D3D11_USAGE_DYNAMIC;
Vbufferdescription.CPUAccessFlags=D3D11_CPU_ACCESS_WRITE;
Vbufferdescription.ByteWidth=sizeof(VertexText)*6*numLetters;
Vbufferdescription.MiscFlags=0;
iD3D.Device->CreateBuffer(&Vbufferdescription, NULL, &FontVertexBuffer);
}
I have a rather simple HLSL file:
cbuffer ConstantBuffer:register( b0 )
{
float4x4 WVP;
}
struct VOut
{
float4 position : SV_POSITION;
float2 TexCoord : TEXCOORD0;
};
VOut FONT_VS(float4 position : POSITION, float2 TexCoord : TEXCOORD)
{
VOut output;
output.position = mul(position, WVP);
output.TexCoord = TexCoord;
return output;
}
float2 FONT_PS(float4 position : SV_POSITION, float2 TexCoord : TEXCOORD0) : SV_TARGET
{
return TexCoord;
}
(The DrawString() function)
bool InfiniteText::DrawString(char* Text, float xPos, float yPos){
int letterSize = sizeof(VertexText)*6;
int textSize = strlen(Text);
if(textSize > numLetters)
textSize=numLetters;
float cScreenWidth = 32.0f/iD3D.cWidth;
float cScreenHeight= 32.0f/iD3D.cHeight;
float TexelWidth= 32.0f/textureWidth;
D3D11_MAPPED_SUBRESOURCE MappedSub;
iD3D.DeviceContext->Map(FontVertexBuffer, 0, D3D11_MAP_WRITE_DISCARD, 0, &MappedSub);
VertexText* Sprite = (VertexText*)MappedSub.pData;
const int indexA = static_cast<int>('A');
const int indexZ = static_cast<int>('Z');
for(int i=0; i<textSize;i++){
float thisStartX=xPos+(cScreenWidth*static_cast<char>(i));
float thisEndX=thisStartX + cScreenWidth;
float thisStartY=yPos;
float thisEndY=thisStartY + cScreenHeight;
Sprite[0].Translation=XMFLOAT3(thisEndX,thisEndY,1.0f);
Sprite[1].Translation=XMFLOAT3(thisEndX,yPos,1.0f);
Sprite[2].Translation=XMFLOAT3(thisStartX,yPos,1.0f);
Sprite[3].Translation=XMFLOAT3(thisStartX,yPos,1.0f);
Sprite[4].Translation=XMFLOAT3(thisStartX,thisEndY,1.0f);
Sprite[5].Translation=XMFLOAT3(thisEndX,thisEndY,1.0f);
UINT TexLookup=0;
UINT Letter= static_cast<int>(Text[i]);
if (Letter < indexA || Letter > indexZ){
TexLookup=(indexA - indexZ) +1;
}
else{
TexLookup=(Letter-indexA);
}
float texStart = 0.0f + (TexelWidth*static_cast<float>(TexLookup));
float TexEnd = texStart + TexelWidth;
Sprite[0].TextureCoord = XMFLOAT2(TexEnd,0.0f);
Sprite[1].TextureCoord = XMFLOAT2(TexEnd,1.0f);
Sprite[2].TextureCoord = XMFLOAT2(texStart,1.0f);
Sprite[3].TextureCoord = XMFLOAT2(texStart,1.0f);
Sprite[4].TextureCoord = XMFLOAT2(texStart,0.0f);
Sprite[5].TextureCoord = XMFLOAT2(TexEnd,0.0f);
Sprite= Sprite + 6;
}
iD3D.DeviceContext->Unmap(FontVertexBuffer,0); //MAP END
UINT stride=sizeof(VertexText);
UINT offset=0;
iD3D.DeviceContext->VSSetShader(iText.Fontvs,0,0);
iD3D.DeviceContext->PSSetShader(iText.Fontps,0,0);
//Projection=XMMatrixPerspectiveFovLH(XM_PIDIV2, 1.0, 0.0f, 1000.0f);
Projection=iD3D.mProjection;
iD3D.WorldCB.mWorldVP=XMMatrixTranspose(Projection);
iD3D.DeviceContext->UpdateSubresource(iD3D.MatrixBuffer, 0, NULL, &iD3D.WorldCB, 0, 0);
iD3D.DeviceContext->VSSetConstantBuffers(0,1,&iD3D.MatrixBuffer);
iD3D.DeviceContext->IASetVertexBuffers(0,1, &iText.FontVertexBuffer, &stride, &offset);
iD3D.DeviceContext->PSSetShaderResources(0,1, &iText.FontSRV);
iD3D.DeviceContext->PSSetSamplers(0,1,&iText.FontSRVSampler);
iD3D.DeviceContext->IASetPrimitiveTopology( D3D_PRIMITIVE_TOPOLOGY_TRIANGLELIST );
iD3D.DeviceContext->Draw(6*textSize,0);
return true;
}
If you made it this far, thank you. I think that it might be that my .hlsl file might not be configured properly to receive textures, and I might need to know how textures interface properly with the shader to produce the output. Thanks!
The HLSL was not written correctly to include Texture2D x: register( t0 ) or SamplerState x : register( s0 ), taking in necessary resources for the texture. Another problem has surfaced, but this question has been solved.
I am getting a vector subscript out of range when I try to load Obj files that doesnt have normals or texture coordinates. If I load an obj file that has normals and texture coordinates, then everything works fine. So I am just asking how can I modify my code to load obj files without normals and texture coordinates.
this is my struct to store VERTEX data
struct VERTEX
{
XMFLOAT3 position;
XMFLOAT3 normal;
XMFLOAT2 texcoord;
};
and these vertex's are used to store the data in
std::vector<XMFLOAT3> m_position;
std::vector<XMFLOAT2> m_texCoords;
std::vector<XMFLOAT3> m_normals;
std::vector<VERTEX> m_vertices;
std::vector<DWORD> m_Indices;
VERTEX vertex;
This is how I read the lines for my faces. This all works fine but I am not sure if it may be the cause to why my program breaks when loading obj files without normals and texture coordinates.
else if (strcmp(buffer, "f") == 0)
{
int fPosition, fTexCoord, fNormal; //data of a single vertex
for (int iFace = 0; iFace < 3; iFace++)
{
ZeroMemory(&vertex, sizeof(VERTEX));
file >> fPosition;
vertex.position = m_position[fPosition - 1];
if (file.peek() == '/')
{
file.ignore();
if (file.peek() != '/')
{
file >> fTexCoord;
vertex.texcoord = m_texCoords[fTexCoord - 1];
}
if (file.peek() == '/')
{
file.ignore();
file >> fNormal;
vertex.normal = m_normals[fNormal -1];
}
m_vertices.push_back(vertex);
m_Indices.push_back(m_vertices.size() - 1);
}
}
}
and finally this is how I set up my vertex buffer
D3D11_INPUT_ELEMENT_DESC vertlayout[] =
{
{ "POSITION", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 0, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "NORMAL", 0, DXGI_FORMAT_R32G32B32_FLOAT, 0, 24, D3D11_INPUT_PER_VERTEX_DATA, 0 },
{ "TEXCOORD", 0, DXGI_FORMAT_R32G32_FLOAT, 0, 36, D3D11_INPUT_PER_VERTEX_DATA, 0 },
};
ID3D11Device* pDevice = m_shader->GetDevice();
ID3DBlob* pVSBlob = m_shader->GetVSBlob();
pDevice->CreateInputLayout(vertlayout, ARRAYSIZE(vertlayout), pVSBlob->GetBufferPointer(),
pVSBlob->GetBufferSize(), &m_vertexLayout);
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(VERTEX)* m_vertices.size();
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
bd.CPUAccessFlags = 0;
D3D11_SUBRESOURCE_DATA initData;
ZeroMemory(&initData, sizeof(initData));
initData.pSysMem = &m_vertices[0]; //This is where it breaks
pDevice->CreateBuffer(&bd, &initData, &m_vertexBuffer);
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(DWORD)* m_Indices.size();
bd.BindFlags = D3D11_BIND_INDEX_BUFFER;
bd.CPUAccessFlags = 0;
initData.pSysMem = &m_Indices[0]; //and it breaks here too
pDevice->CreateBuffer(&bd, &initData, &m_indexBuffer);
}
as the comment says, on the lines with initData.pSysMem = &m_vertices[0]; and initData.pSysMem = &m_Indices[0];, my program will break and I will get the vector subscript out of range error. if I remove the [0] from &m_vertices and &m_Indices, it wont break however nothing will get rendered.
I would just like to know what can I do to have my obj loader load obj files that doesnt need to have always all 4 vertices, normals, texture coordinates and faces.
In general
You cannot find out why your app crashes just by guessing. And you don't need to. As programmers, we have decent tools to solve such issues. So, general advice: learn to use your debugger.
Concrete issue
Your vectors are empty.
When you are trying to access first elements (m_vertices[0] and m_Indices[0]), which do not exist, you get this assertion failure (because you are in debug mode; in release mode it will silently trigger undefined behavior).
How to check
When program execution breaks on those lines, check "Call stack" window, to see in which function you are. Find one of your functions, that are highest on the stack and click it. Check "Locals", "Auto" or "Watch" windows (menu "Debug"->"Windows") to see contents of the vectors and other variables in scope. Place breakpoints and restart app if needed.
How to fix
Set breakpoints earlier in the program, to see why your vectors are empty. Move line by line, function by function, using "Step into" and "Step over", , watch variables, untill you will find source of error.
If it is valid to have empty vectors there, you can just make branches to avoid code paths where you accessing it's contents:
if(!m_vertices.empty())
{
// Create buffers with data
}
else
{
// Create empty buffers or report an error
}`
Hope it helps.