I solved the problem! Thank you guys! :)
So my solution to the problem was simple, i solely removed the " tempBuffer = { nullptr }; " line.
Solution:
void BindDataToBuffer(ID3D11Device* gDevice, ID3D11Buffer** &gVertexBufferArray, FBXData &FBX)
{
HRESULT hr;
if (gVertexBufferArray != nullptr)
{
ID3D11Buffer** tempBuffer = new ID3D11Buffer*[this->totalSumMeshes + FBX.meshCount];
for (int i = 0; i < this->totalSumMeshes; i++)
{
tempBuffer[i] = gVertexBufferArray[i];
}
gVertexBufferArray = tempBuffer;
this->totalSumMeshes += FBX.meshCount;
Explanation:
My concept was to create a vertex buffer array for each mesh loaded into the project.
The meshes was loaded in from a file format i created myself.
So when i loaded in another file, i wanted to expand the existing array in size without overwriting existing stored data.
Since the ID3DBuffer is a virtual class, i needed to create the ID3DBuffer as a double pointer.
Why? When creating with double pointers, you create an array of interface pointers.
So comparing that to simple data types like int* and int**, the int* is structured like int[x] and int** like int[x][y], but because the interface** is virtual we do NOT get buffer[x][y] but we receive buffer[x] because a single pointer only points to the memory location of the object.
int* == int[x];
int** == int[x][y];
ID3DBuffer* == ID3DBuffer;
ID3DBuffer** == ID3DBuffer[x];
With that in note, when transfering the adress of the data between the two buffers, we want to make sure that the newly created temporary buffer is not a null pointer.
Why? Because otherwise the memory of the pointer would just be set to 0 and therefore we can't give it new adresses since it lacks memory locations to store the adresses in.
for (int i = 0; i < this->totalSumMeshes; i++)
{
tempBuffer[i] = gVertexBufferArray[i];
}
And the:
gVertexBufferArray = tempBuffer;
Is because we want the old array to store new array size we created.
Note:
We do NOT want to delete[] the temp array since the old and the new now hold the same adresses.
Deleting will result in doing so for both the arrays.
The deletion of the memory will be set in the end of the program or when you dont need the array anymore.
And in that case we want to use release, not delete.