Can't store closest hit result in a pointer

Cant add much more than already said by others.
You should take a read about Stack vs Heap and how each case works.
You are having Stack related issues and you need to move values to the Heap to preserve them in a new memory space (that should be later released for memory leak prevention)
Stack vs Heap Memory Allocation - GeeksforGeeks

Here is a lecture that can help you on understanding how this works and how to take advantage or fix issues like this.

2 Likes