Handmade Network»Forums
Max
16 posts
Question about the stack and dlls.

Hi, this might be a silly question, but I have had some confusion on how the stack works in C. From what I understand, the stack is usually 1 Megabyte if I compile using cl. I had originally thought that if I somehow used more than 1 Megabyte, I would get a compiler error saying I needed to set the stack larger or refactor my code (I am not sure if this is true). I have realized that this probably is not possible if I have split up my code into dlls as the compiler would not know how much memory on the stack functions from a dll would need. Is this true? And is running out of stack-space a common error or does this mean I am missing something major?

The reason I am asking this question is I have started running into an Unhandled exception / Stack overflow with ig7icd64.dll when I call the opengl function glLinkProgram on certain shaders. This error only appears on my laptop which have an older graphics card (Intel(R) HD Graphics 4000). It also only started showing up after I had reached a certain amount of code. I have been able to run the program with no problem on 2 other machines, and when I increased the stack size by a little the error seems to go away altogether. I am not sure if I should be worried or if older machines might just need a little larger of a stack.

Mārtiņš Možeiko
2559 posts / 2 projects
Question about the stack and dlls.
Edited by Mārtiņš Možeiko on

Yes, dll's don't control how big will be stack. Main executable has explicit size in its headers that OS allocates for you - which you can override with linker argument. Other threads by default will use same size, but it can be explicitly specified in CreateThread argument.

Running out of stack is error with recursive functions or when you put too large of structures/arrays on stack.

But with OpenGL there can be different errors why this kind of error happens. One is bugs in GL implementation - it is well known that opengl on Windows especially on older/integrated cards is implemented very poorly and often gives you all kinds of bugs - like too much stack size when it shouldn't (because larger allocations should be done on heap, not on stack). Other is bad usage of GL api that triggers bugs. In this case you should carefully verify that it is not your code that is at fault. Easiest way is to enable debug context and run with debug callback enabled to log all errors. Alternatively use RenderDoc.

If you have option - consider using D3D11 on Windows that is way more stable than GL.

Less preferable, but also a good option is to use Angle wrapper - it gives you GLESv2/v3 api that is implemented using D3D11/D3D12/Vulkan. The translation layer will be very transparent to you.

Max
16 posts
Question about the stack and dlls.
Replying to mmozeiko (#29141)

Thanks for the response! That info about dlls interact with the stack is good to know. I have read some about how of the opengl might be buggy on some drivers. I will look through my opengl code but I think it should be fine as it is currently pretty simple.

I was planning on adding D3D11 rendering in the future, but that probably won't be for a little while.

Thanks for the help!