Hey folks!
I'm planning to write game engine in the future with C++. For now, I'm just studying this area. But I came across problem with live coding in editor. Reopening the editor and loading all game assets at every time code changed is a big problem. There are some solution for this problem. For example:
- Using scripting language
- Compiling to .DLL and dynamically loading
I wanted to choose first approach in the beginning. Even I successfully embedded 3 languages (lua, c#, js) into hello world c++ program. Each one have it's pros and cons. For example:
- Lua is very small (under 200kb) and very fast (with LuaJIT), but has less features.
- C# has lot's of features (generics, classes, lambas etc), but it's size is very large for mobile games. (~11MB with Mono-C# on android build)
- JS is simple and powerful language. But it's slow without JIT. For speed, you must use JIT based engines like V8. But iOS don't support JIT. I tried Duktape, but it's slow.
But I wanted to give a chance to second approach. Because it's very fast and small. But C++ is a dangerous language. You can crash whole editor with small bug. And memory must be carefully managed. TLDR; My questions are:
- How can I hook into malloc of dynamically loaded library? With this way, I can free all memory allocated by dll before unloading it.
- How can I handle exceptions? Especially CPU signals, e.g.. division by zero, access violation (segfault). I tried Windows' Structured Exception Handlers but I failed.
- Is it possible to run dll inside virtual address space? With this way, programmer can't mistakenly alter editor's memory. Or don't give access to dll to write outside of it's space. This is something like checking range of pointer.
Thanks.