7c22ae1f02
- remove diagnostic canaries from audio hot path (crackle fix) and stuck C5 note raw-MIDI test (Vst2Instrument::init noteOff) - split native bridge into daw_vst_bridge (VSTi) + fx_vst_bridge (VST FX) - VST3: processData prepare before setActive, zero input buses, accept both .vstpreset and bridge-state blob in RenderJob presets - native_render/vst_engine: bridge-exe discovery + render_fx_chain + /fx-gui - delete old install/ engine binaries (install via sidecar+resources now) - add BUILD_LAYOUT.md, build_selfcheck, tools/ diagnostics
81 lines
3.7 KiB
Python
81 lines
3.7 KiB
Python
import io, sys
|
|
|
|
p = r"C:/Users/locpham/SonicForgeStudio/native_bridge/src/main.cpp"
|
|
data = open(p, "rb").read()
|
|
|
|
def rep(old, new, count=1):
|
|
global data
|
|
old = old.encode()
|
|
new = new.encode()
|
|
assert data.count(old) >= count, "pattern not found: %r" % old
|
|
data = data.replace(old, new, count)
|
|
|
|
# 1. includes: cstdio + dbghelp.h into the _WIN32 block
|
|
rep("#include <cstdlib>\n#include <thread>\n",
|
|
"#include <cstdlib>\n#include <cstdio>\n#include <dbghelp.h>\n#include <thread>\n")
|
|
|
|
# 2. handler + registration at main entry
|
|
handler = r"""
|
|
// --- crash minidump handler (temp diagnostics) -------------------------------
|
|
// WER LocalDumps produces NO dump for 0xC0000374 (heap corruption) — write our
|
|
// own minidump via dbghelp.dll when an unhandled exception reaches this filter.
|
|
#ifdef _WIN32
|
|
static LONG WINAPI CrashDumpHandler(EXCEPTION_POINTERS* ep) {
|
|
static LONG once = 0;
|
|
if (InterlockedCompareExchange(&once, 1, 0)) return EXCEPTION_CONTINUE_SEARCH;
|
|
PEXCEPTION_RECORD er = ep ? ep->ExceptionRecord : nullptr;
|
|
std::cerr << "[CRASH] exception code=0x" << std::hex
|
|
<< (er ? er->ExceptionCode : 0) << " addr=0x"
|
|
<< (er ? (void*)er->ExceptionAddress : nullptr) << std::dec << std::endl;
|
|
if (er) {
|
|
HMODULE hMod = nullptr;
|
|
char modPath[MAX_PATH] = {0};
|
|
if (GetModuleHandleExA(GET_MODULE_HANDLE_EX_FLAG_FROM_ADDRESS |
|
|
GET_MODULE_HANDLE_EX_FLAG_UNCHANGED_REFCOUNT,
|
|
(LPCSTR)er->ExceptionAddress, &hMod) && hMod) {
|
|
GetModuleFileNameA(hMod, modPath, MAX_PATH);
|
|
std::cerr << "[CRASH] faulting module: " << modPath << std::endl;
|
|
}
|
|
}
|
|
const char* dumpDir = "C:/Users/locpham/AppData/Local/Temp/sf_dumps";
|
|
CreateDirectoryA(dumpDir, nullptr);
|
|
char dumpPath[MAX_PATH];
|
|
snprintf(dumpPath, sizeof(dumpPath), "%s/bridge_crash_%lu.dmp", dumpDir, GetCurrentProcessId());
|
|
HMODULE hDbg = LoadLibraryA("dbghelp.dll");
|
|
if (hDbg) {
|
|
typedef BOOL(WINAPI* MiniDumpWriteDumpFn)(HANDLE, DWORD, HANDLE, MINIDUMP_TYPE,
|
|
PMINIDUMP_EXCEPTION_INFORMATION, PMINIDUMP_USER_STREAM_INFORMATION,
|
|
PMINIDUMP_CALLBACK_INFORMATION);
|
|
auto pMiniDumpWriteDump = (MiniDumpWriteDumpFn)GetProcAddress(hDbg, "MiniDumpWriteDump");
|
|
if (pMiniDumpWriteDump) {
|
|
HANDLE hFile = CreateFileA(dumpPath, GENERIC_WRITE, 0, nullptr,
|
|
CREATE_ALWAYS, FILE_ATTRIBUTE_NORMAL, nullptr);
|
|
if (hFile != INVALID_HANDLE_VALUE) {
|
|
MINIDUMP_EXCEPTION_INFORMATION mei = {};
|
|
mei.ThreadId = GetCurrentThreadId();
|
|
mei.ExceptionPointers = ep;
|
|
mei.ClientPointers = TRUE;
|
|
BOOL ok = pMiniDumpWriteDump(GetCurrentProcess(), GetCurrentProcessId(),
|
|
hFile, MiniDumpNormal, &mei, nullptr, nullptr);
|
|
CloseHandle(hFile);
|
|
std::cerr << "[CRASH] minidump " << (ok ? "written: " : "FAILED: ") << dumpPath << std::endl;
|
|
} else {
|
|
std::cerr << "[CRASH] cannot open dump file" << std::endl;
|
|
}
|
|
} else {
|
|
std::cerr << "[CRASH] MiniDumpWriteDump not found in dbghelp.dll" << std::endl;
|
|
}
|
|
} else {
|
|
std::cerr << "[CRASH] cannot load dbghelp.dll" << std::endl;
|
|
}
|
|
return EXCEPTION_CONTINUE_SEARCH; // let WER proceed, process dies normally
|
|
}
|
|
#endif
|
|
"""
|
|
|
|
rep("int main(int argc, char* argv[]) {\n",
|
|
handler + "\nint main(int argc, char* argv[]) {\n SetUnhandledExceptionFilter(CrashDumpHandler);\n")
|
|
|
|
open(p, "wb").write(data)
|
|
print("patched OK, size=", len(data))
|