![warcraft show interface errors warcraft show interface errors](http://tbcwowaddons.weebly.com/uploads/2/5/4/1/25412234/8593797_orig.png)
- #Warcraft show interface errors how to#
- #Warcraft show interface errors code#
- #Warcraft show interface errors series#
For example, we might be working with an external Lua library that has already been compiled as C, or we might want to disable C++ exception handling for performance reasons.
![warcraft show interface errors warcraft show interface errors](https://cdn.windowsreport.com/wp-content/uploads/2020/06/world-of-warcraft-11-e1594199075966.jpg)
Of course, compiling Lua as C++ might not always be practical.
#Warcraft show interface errors code#
(In Visual Studio, use option /TP in GCC, compile the code with g++ instead of gcc.) When Lua is compiled as C++, it uses try/catch instead of setjmp/longjmp for error handling. The easiest solution is to compile Lua as C++. Considering that Lua uses longjmp ubiquitously for error handling, this is not ideal □ The solution: If you think about it, this means that most C++ programs that use longjmp would have undefined behaviour. (Note: I have seen different wording for this in different places the above comes from a Stack Overflow answer). A setjmp/longjmp call pair has undefined behavior if replacing the setjmp and longjmp by catch and throw would invoke any non-trivial destructors for any automatic objects. The function signature longjmp(jmp_buf jbuf, int val) has more restricted behavior in this International Standard. On such a compiler, the destructor for vector “v” would not be called, and we would have a memory leak. The problem is that, on some compilers at least, longjmp() does not call C++ destructors as it unwinds the stack. An error code will be returned into “result”, and execution will continue, with an error message sitting on top of the Lua stack. As per the specification of lua_pcall, the stack will be unwound back to the lua_pcall statement in Foo. Lua will handle the error by doing a longjmp. Imagine that the lua_call above (in MyFunction) results in a Lua error being raised.Īt first sight this appears perfectly OK. Clearly, this is bad news if you were relying on the destructor to clean up memory or other resources. The problem in this scenario is that “longjmp” does not guarantee that destructors will be called. Your C++ code contains at least one local variable with a non-trivial destructor. This causes Lua to do a “longjmp” through your code. Something goes wrong and a Lua error is generated. Problem 1: C++ destructors may not called when doing a “longjmp” The scenario:
#Warcraft show interface errors series#
I will present this as a series of problems that can occur, and possible solutions to each. I’m writing this blog post (1) as a way of documenting the issues I found, and (2) because it might be helpful to other programmers who run into similar issues.
#Warcraft show interface errors how to#
During this process I found out that there are several “gotchas” in terms of how to correctly handle Lua errors in your C++ code. Recently I added support for Lua scripting in Knights. Also, you should break the joints of anyone sending a command who is not the admin and log them for the attempt, or add them to a ban list. It would be better to create a simple Gui with buttons that send events.
![warcraft show interface errors warcraft show interface errors](https://cdn.statically.io/img/websetnet.net/f=auto%2Cq=60/wp-content/uploads/2020/02/warcraft-III-reforged-patch-1.32.2-740x416-2.jpg)
This is a truly horrible way to do administration. Plain Lua has various ineffective mitigations in different versions, but it's always possible to construct a testcase that blows up the C stack (see the recent Lua mailing.
![warcraft show interface errors warcraft show interface errors](https://www.thewindowsclub.com/wp-content/uploads/2021/08/directx.jpg)
Due to a general design issue with the Lua coroutine API, any invocation of a coroutine always takes up C stack space, too. This is a C stack overflow and unrelated to #618. This is a technical post about how to handle Lua errors in C++ code.