c ++ Edit: Why does this code work, but not this code, even though it's the same? At least that's what I thought

Below is the full code that had problems.

  1. The commented out lines are Method 1. (This works under certain conditions).
  2. The uncommented lines are Method 2. (This works 100%).
  3. The commented out lines will work if I comment out code # 3 completely.
  4. If anyone knows why these mistakes occur, that would be fantastic!
  5. I'm also curious about the differences between the three methods mentioned above.

                    if (ContentLoader :: m_index> = 0) {
    context-> OMSetDepthStencilState (depthOffState.Get (), 0);
    
    UINT step = sizeof (VertexPositionColorTexture);
    UINT offset = 0;
    
    context-> IASetVertexBuffers (0, 1, ContentLoader :: static_interfaces_buffer.GetAddressOf (), & stride, & offset);
    context-> VSSetConstantBuffers (0, 1, d2d_const_buffer.GetAddressOf ());
    
    Float BlendFactor[4] = {1.0f, 1.0f, 1.0f, 1.0f};
    context-> OMSetBlendState (blendstate.Get (), BlendFactor, 0xFFFFFFFF);
    
    ContentWindow cw = ContentLoader :: GetCurrentWindow ();
    
    if (cw.background_shader_id> = 0)
    {
    // CODE SECITON # 1
    // context-> PSSetShaderResources (0, 1, ContentLoader :: GetTextureResource (cw.background_shader_id) .m_texture.GetAddressOf ());
    context-> PSSetShaderResources (0, 1, ContentLoader :: GetTextureComResource (cw.background_shader_id) .GetAddressOf ());
    context-> Draw (6, 0);
    }
    for (int i = 0; i < cw.state_changes; ++i)
    {
        //CODE SECITON #2
        context->PSSetShaderResources (0, 1,
    ContentLoader :: GetTextureComResource (cw.state_change_alias.)[i]) .GetAddressOf ()
    //ContentLoader::GetTextureResource(cw.state_change_alias[i]) .m_texture.GetAddressOf ()
    );
    Context-> Draw (cw.state_vertex_sizes[i], cw.state_vertex_offsets[i]);
    }
    
    // CODE SECITON # 3
    context-> IASetVertexBuffers (0, 1, ContentLoader :: dynamic_interfaces_buffer.GetAddressOf (), & stride, & offset);
    context-> PSSetShaderResources (0, 1, ContentLoader :: GetTextureComResource (3) .GetAddressOf ());
    // context-> PSSetShaderResources (0, 1, ContentLoader :: GetTextureResource (3) .m_texture.GetAddressOf ());
    context-> Draw (ContentLoader :: dynamic_interface_buffer_size, 0);}
    

In the following, the three THREE METHODS are called into question.

Method 1 Sometimes works, but depends on how often I use it.

2. Method Works all the time for every situation I've tested and is strong
30 minutes now.

3. Method Always falls to 100% when used in combination with above.

                // This does not always work, but sometimes.
TextureResource ContentLoader :: GetTextureResource (int index)
{
Return textur_resources[index];
}

// that has so far shown that all my problems are fixed and always works ...... wtf.
ComPtr ContentLoader :: GetTextureComResource (int index)
{
Return textur_resources[index].m_texture;
}

// I have tried this for testing and errors are issued immediately if the run is not even executed.
ID3D11ShaderResourceView ** ContentLoader :: GetTextureAddress (int index)
{
Return textur_resources[index].m_texture.GetAddressOf ();
}