Important Notice: Our web hosting provider recently started charging us for additional visits, which was unexpected. In response, we're seeking donations. Depending on the situation, we may explore different monetization options for our Community and Expert Contributors. It's crucial to provide more returns for their expertise and offer more Expert Validated Answers or AI Validated Answers. Learn more about our hosting issue here.

What to do when a _CrtIsValidHeapPointer assertion failure happens?

assertion failure happens
0
Posted

What to do when a _CrtIsValidHeapPointer assertion failure happens?

0

When doing Lua embedding, sometimes if you didn’t clean the stack correctly, it might cause a _CrtIsValidHeapPointer assertion failure. As the comment of the function _CrtIsValidHeapPointer says: “verify pointer is not only a valid pointer but also that it is from the ‘local’ heap. Pointers from another copy of the C runtime (even in the same process) will be caught.” Let’s check the details of the ‘invalid pointer’. When lua_open() return a lua_State* L, it’s with a stack of default size 45. If you make some fault not clear the return values of function, that garbage will finally pile up on the stack and crash the stack memory block. When a new op needs to increase the stack size, a realloc will happen, and the CRT will find that the old pointer is invalid and this will lead a _CrtIsValidHeapPointer failure. To fix, just carefully check your code (using lua_gettop(L) to check the stack size) and clean the unused slot on the stack. For the ‘non local heap’ one, please check and make su

Related Questions

What is your question?

*Sadly, we had to bring back ads too. Hopefully more targeted.

Experts123