Still no luck in reproducing the problem.
I've tried to replicate the script and the registered interface with your configuration. This is what I have:
// Test crash due to exception
// https://www.gamedev.net/forums/topic/714882-crash-in-trycatch-blocks/5458952/
// https://github.com/openplanet-nl/issues/issues/359
{
asIScriptEngine* engine = asCreateScriptEngine();
engine->SetMessageCallback(asMETHOD(CBufferedOutStream, Callback), &bout, asCALL_THISCALL);
bout.buffer = "";
engine->SetEngineProperty(asEP_ALLOW_IMPLICIT_HANDLE_TYPES, true);
engine->SetEngineProperty(asEP_PROPERTY_ACCESSOR_MODE, 2);
RegisterScriptString(engine);
engine->RegisterGlobalFunction("void trace(const string &in)", asFUNCTION(print), asCALL_GENERIC);
engine->SetDefaultNamespace("Time");
engine->RegisterGlobalFunction("int64 get_Stamp()", asFUNCTION(get_Stamp), asCALL_CDECL);
engine->SetDefaultNamespace("");
engine->RegisterObjectType("MwNodPool<T>", 1, asOBJ_VALUE | asOBJ_TEMPLATE); // 66
engine->RegisterObjectBehaviour("MwNodPool<T>", asBEHAVE_CONSTRUCT, "void MwNodPool(int&in)", asFUNCTION(Construct), asCALL_CDECL_OBJLAST);
engine->RegisterObjectBehaviour("MwNodPool<T>", asBEHAVE_DESTRUCT, "void MwNodPool()", asFUNCTION(Destruct), asCALL_CDECL_OBJLAST);
engine->RegisterObjectMethod("MwNodPool<T>", "uint get_Length() const", asFUNCTION(get_Length), asCALL_CDECL_OBJLAST);
engine->RegisterObjectType("CGameCtnEditorScriptAnchoredObject", 0, asOBJ_REF | asOBJ_NOCOUNT); // 262145 = 1 + 1<<18 = asOBJ_REF + asOBJ_NOCOUNT
engine->RegisterObjectType("CSmEditorPluginMapType", 0, asOBJ_REF | asOBJ_NOCOUNT); // 262145 = 1 + 1<<18 = asOBJ_REF + asOBJ_NOCOUNT
engine->RegisterObjectMethod("CSmEditorPluginMapType", "const MwNodPool<CGameCtnEditorScriptAnchoredObject@>&get_Items()", asFUNCTION(get_Items), asCALL_CDECL_OBJLAST);
engine->RegisterObjectType("CGameEditorPluginMapMapType", 0, asOBJ_REF | asOBJ_NOCOUNT); // 262145 = 1 + 1<<18 = asOBJ_REF + asOBJ_NOCOUNT
engine->RegisterObjectMethod("CGameEditorPluginMapMapType", "void opCast(?&out)", asFUNCTION(opCast), asCALL_CDECL_OBJLAST);
engine->RegisterObjectType("CGameCtnEditorFree", 0, asOBJ_REF | asOBJ_NOCOUNT); // 262145
engine->RegisterObjectMethod("CGameCtnEditorFree", "CGameEditorPluginMapMapType@ get_PluginMapType()", asFUNCTIONPR(get_PluginMapType, (Dummy*), Dummy*), asCALL_CDECL_OBJLAST);
engine->RegisterObjectType("CGameCtnApp", 0, asOBJ_REF | asOBJ_NOCOUNT); // 262145
engine->RegisterObjectMethod("CGameCtnApp", "CGameCtnEditorFree @get_Editor()", asFUNCTION(get_Editor), asCALL_CDECL_OBJLAST);
engine->RegisterGlobalFunction("CGameCtnApp @GetApp()", asFUNCTION(GetApp), asCALL_CDECL);
app = new Dummy();
app->next = new Dummy();
app->next->next = new Dummy();
asIScriptModule* mod = engine->GetModule("test", asGM_ALWAYS_CREATE);
mod->AddScriptSection("test",
"uint lastLog = Time::Stamp;\n"
"int count = 5;"
"void MLCoro() {\n"
" bool logNow = false; \n"
" while (--count > 0) {\n"
" logNow = false; \n"
" if (lastLog < Time::Stamp) {\n"
" lastLog = Time::Stamp; \n"
" trace('ML sec'); \n"
" logNow = true; \n"
" }\n"
" try {\n"
" auto editor = cast<CGameCtnEditorFree>(GetApp().Editor); \n"
" auto pmt = cast<CSmEditorPluginMapType>(editor.PluginMapType); \n"
" if (logNow) {\n"
" trace('Items length: ' + pmt.Items.Length); \n"
" }\n"
" }\n"
" catch {\n"
" }\n"
" }\n"
"}\n");
r = mod->Build();
if (r < 0)
TEST_FAILED;
asIScriptContext* ctx = engine->CreateContext();
ctx->Prepare(mod->GetFunctionByDecl("void MLCoro()"));
r = ctx->Execute();
if (r != asEXECUTION_FINISHED)
TEST_FAILED;
if (bout.buffer != "test (2, 15) : Info : Compiling void MLCoro()\n"
"test (6, 15) : Warning : Signed/Unsigned mismatch\n")
{
PRINTF("%s", bout.buffer.c_str());
TEST_FAILED;
}
app->Release();
app = 0;
ctx->Release();
engine->ShutDownAndRelease();
}
I've tried causing the exception at different levels as there are multiple places that can have null pointer exception.
The memory invasion corrupting the stack blocks might come from somewhere else. It may not even be caused by AngelScript.
Can you reproduce it in your engine and set debug memory breakpoints where the stack blocks get corrupted? That may be the only way we'll ever find out what is actually causing this.