 
     cudaStreamDestroy(mainStream);
     cudaErrorCheck(nullptr);
-    cudaFree(rgbGPU);
+    cudaFree(bgrGPU);
     cudaErrorCheck(nullptr);
     cudaFree(yuyvGPU);
     cudaErrorCheck(nullptr);

            vrBounds.validDevCount > 0 ? vrBounds.trackerBounds : foregroundBounds,
            vulkanHeadless.getCudaTexture());

        if (vulkanHeadless.isValid)
        {
            dim3 bs(32, 32, 1);
            draw_foreground<<<salient::distribute(dim3(color_W, color_H, 1), bs), bs, 0, mainStream>>>(downsample_ratio, color_W, color_H, rgbGPU, realSalient.probabilities, yuyvGPU, *vulkanHeadless.getCudaTexture());
        }
        else
        {
            draw_foreground<<<salient::distribute(color_N, BLOCK_SIZE), BLOCK_SIZE, 0, mainStream>>>(color_N, rgbGPU, realSalient.probabilities, yuyvGPU);
        }

        cudaErrorCheck(mainStream);

        cudaMemcpyAsync(foreground.data, rgbGPU, sizeof(uint8_t) * color_W * color_H * 3, cudaMemcpyDeviceToHost, mainStream);
        cudaErrorCheck(mainStream);

        // before using the results coming from GPU, we need to wait the GPU stream to finish.

    cudaErrorCheck(nullptr);

    // transformed RGB image with foreground mask applied
    uint8_t *bgrGPU = nullptr;
    cudaMalloc((void **)&bgrGPU, sizeof(uint8_t) * color_W * color_H * 3);
    cudaErrorCheck(nullptr);

    // how to access color data at every pixel position.
