Ver código fonte

Round 169g: FL engine DLLs of other FL builds (Transistor Bass found by shape, signature-free image hashes), project-load and export-cancel crash fixes, LYNX_NO_FL test switch

Ka1-S 1 mês atrás
pai
commit
6fa2cba0d7

+ 1 - 0
docs/FL_INTEGRATION.md

@@ -53,3 +53,4 @@ project (the file name, then with its last folders: `Samples\kick.wav`). The rep
 Read-only: no FL file or registry key is written. Encrypted content (FLEX packs, licensed data) is never opened;
 the plugin database holds no licensed content. No Image-Line file is committed (tests use synthetic fixtures).
 Test hook: `LYNX_FL_USER_DATA=<folder>` makes LYNX SHARE read a synthetic user data folder instead of FL's (used to check the database path end to end).
+Test hook: `LYNX_NO_FL=1` makes LYNX SHARE behave as on a computer without FL Studio (no installation, no user data), even where FL is installed.

+ 7 - 2
src/core/DrumSynthLive.cpp

@@ -30,6 +30,9 @@ namespace
 // samples. The engine also seeds its noise generator from them.
 
 constexpr const char* engineSha256 = "9a5f168219c702514f07f3d568a348fc1438d9ffa287310467dd7887cc74c637";
+// FL Studio 2025.1.6's build (peImageSha256Hex, round 169g): 51 bytes differ from 2026's (link time stamps, the debug
+// directory), not the WAVES resource: tests/Crash169gTests.inc renders both alike
+constexpr const char* engineImageSha256Fl25 = "1b503eb29b3a4c724dcc45e86c3fc0293dfcdba6a98595b613a666263362d818";
 
 // Without the DLL the noise starts from the engine's base constant instead of base + Σ(resource samples): the noise
 // has the same character, only the exact sample sequence differs from FL's
@@ -65,8 +68,10 @@ std::unique_ptr<Waves> loadWaves (const std::string& path)
     if (! in)
         return nullptr;
     const std::vector<std::uint8_t> b ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
-    if (b.size() < 0x1000 || sha256Hex (b.data(), b.size()) != engineSha256)
-        return nullptr; // only the decoded build
+    if (b.size() < 0x1000)
+        return nullptr;
+    if (const auto image = peImageSha256Hex (b); image != engineSha256 && image != engineImageSha256Fl25)
+        return nullptr; // only the decoded builds
     auto u32 = [&] (std::size_t off) { std::uint32_t v = 0; if (off + 4 <= b.size()) std::memcpy (&v, b.data() + off, 4); return v; };
     auto u16 = [&] (std::size_t off) { std::uint16_t v = 0; if (off + 2 <= b.size()) std::memcpy (&v, b.data() + off, 2); return v; };
     const auto pe = (std::size_t) u32 (0x3c);

+ 1 - 1
src/core/Kepler.cpp

@@ -595,7 +595,7 @@ std::shared_ptr<const Tables> loadTables (const std::string& path)
     const std::vector<std::uint8_t> b ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
     if (b.size() < 0x1000)
         return nullptr;
-    const auto hash = sha256Hex (b.data(), b.size());
+    const auto hash = peImageSha256Hex (b); // (a re-signed copy of the same build is the same image, round 169g)
     const bool exo = hash == exoEngineSha256;
     if (! exo && hash != engineSha256)
         return nullptr;

+ 103 - 0
src/core/MessageThreadOwned.h

@@ -0,0 +1,103 @@
+#pragma once
+
+// An object a worker thread uses but another thread (the message thread) must create and delete, e.g. an export job
+// whose plugins live on the message thread (ui/ExportDialog.cpp). Round 169g (crash reports): the stems and playlist-
+// track exports asked the message thread to create / delete their job and waited for it. Cancel made the message
+// thread wait in stopThread for the export thread, which waited for the message thread: after JUCE's 10 s timeout the
+// export thread was killed and the queued call then ran on its freed locals (a 10 s "not responding", then an access
+// violation in the queued lambda). Here the worker stops waiting as soon as it is asked to stop; the object lives in a
+// shared state that the queued calls keep alive, and it is still created and deleted only by the posted calls.
+
+#include <atomic>
+#include <chrono>
+#include <condition_variable>
+#include <functional>
+#include <memory>
+#include <mutex>
+
+namespace lynx
+{
+template <typename T>
+class MessageThreadOwned
+{
+public:
+    using Post = std::function<void (std::function<void()>)>; // runs a call on the owning thread, later
+
+    MessageThreadOwned (Post p, std::function<bool()> stop) : post (std::move (p)), shouldStop (std::move (stop)) {}
+    ~MessageThreadOwned() { release(); }
+    MessageThreadOwned (const MessageThreadOwned&) = delete;
+    MessageThreadOwned& operator= (const MessageThreadOwned&) = delete;
+
+    // the new object, made by `make` on the owning thread; nullptr when the worker was asked to stop first (`make`
+    // then never runs, or its object is deleted by release() on the owning thread)
+    T* create (std::function<std::unique_ptr<T>()> make)
+    {
+        release();
+        auto step = std::make_shared<Step>();
+        post ([s = state, step, make = std::move (make)] {
+            if (! step->abandoned.load())
+                s->object = make();
+            step->signal();
+        });
+        pending = true; // (from here on an object may exist: release() queues its deletion)
+        if (! wait (*step))
+            return nullptr;
+        return state->object.get();
+    }
+
+    // deletes the object on the owning thread; waits for it unless the worker is asked to stop
+    void release()
+    {
+        if (! pending)
+            return;
+        pending = false;
+        auto step = std::make_shared<Step>();
+        post ([s = state, step] {
+            s->object.reset();
+            step->signal();
+        });
+        wait (*step);
+    }
+
+private:
+    struct State
+    {
+        std::unique_ptr<T> object;
+    };
+    struct Step
+    {
+        std::mutex lock;
+        std::condition_variable cv;
+        bool done = false;
+        std::atomic<bool> abandoned { false };
+        void signal()
+        {
+            {
+                const std::lock_guard<std::mutex> g (lock);
+                done = true;
+            }
+            cv.notify_all();
+        }
+    };
+
+    bool wait (Step& step)
+    {
+        std::unique_lock<std::mutex> g (step.lock);
+        while (! step.done)
+        {
+            if (shouldStop())
+            {
+                step.abandoned = true;
+                return false;
+            }
+            step.cv.wait_for (g, std::chrono::milliseconds (20));
+        }
+        return true;
+    }
+
+    Post post;
+    std::function<bool()> shouldStop;
+    std::shared_ptr<State> state = std::make_shared<State>();
+    bool pending = false;
+};
+} // namespace lynx

+ 7 - 2
src/core/PhysicalModels.cpp

@@ -1785,6 +1785,9 @@ struct BooBassTables
 };
 
 constexpr const char* booBassSha256 = "4e10efcd9f945860911e7cdff9c4065c4f193b58ddffc8304b45add1db51705f";
+// FL Studio 2025.1.6's build (peImageSha256Hex, round 169g): 38 bytes differ from 2026's (link time stamps, the debug
+// directory), not the multisample: tests/Crash169gTests.inc renders both alike
+constexpr const char* booBassImageSha256Fl25 = "ed3affa1bf8e0fef431857a4f2d38d831512531f410ef091fa87a888574ac323";
 
 std::unique_ptr<BooBassTables> loadBooBassTables (const std::string& path)
 {
@@ -1798,8 +1801,10 @@ std::unique_ptr<BooBassTables> loadBooBassTables (const std::string& path)
     if (! in)
         return nullptr;
     const std::vector<std::uint8_t> b ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
-    if (b.size() < 0x1000 || sha256Hex (b.data(), b.size()) != booBassSha256)
-        return nullptr; // only the decoded build
+    if (b.size() < 0x1000)
+        return nullptr;
+    if (const auto image = peImageSha256Hex (b); image != booBassSha256 && image != booBassImageSha256Fl25)
+        return nullptr; // only the decoded builds
     auto rd = [&] (std::size_t off, auto& v) { if (off + sizeof (v) <= b.size()) std::memcpy (&v, b.data() + off, sizeof (v)); };
     std::uint32_t pe = 0;
     rd (0x3c, pe);

+ 23 - 0
src/core/Sha256.h

@@ -60,6 +60,29 @@ inline std::string sha256Hex (const std::uint8_t* data, std::size_t size)
     return out;
 }
 
+// SHA-256 of a Windows DLL's image without its Authenticode signature (round 169g, discussion #56): the bytes up to the
+// certificate table, with the PE checksum and the certificate directory entry zeroed. Image-Line ships the same engine
+// DLL signed in one installer and unsigned (or signed again) in another: the whole-file hash then changed although the
+// code and data LYNX reads were identical (FL Slayer's engine in FL Studio 2025 vs 2026). For an unsigned file whose
+// checksum is 0 this equals the whole-file hash, so hashes taken from such files stay valid.
+inline std::string peImageSha256Hex (const std::vector<std::uint8_t>& b)
+{
+    auto u16 = [&b] (std::size_t at) { return at + 2 <= b.size() ? (std::uint32_t) b[at] | (std::uint32_t) b[at + 1] << 8 : 0u; };
+    auto u32 = [&] (std::size_t at) { return u16 (at) | u16 (at + 2) << 16; };
+    const auto pe = (std::size_t) u32 (0x3c);
+    if (b.size() < 0x100 || pe + 24 + 0x90 > b.size() || u32 (pe) != 0x00004550u)
+        return sha256Hex (b.data(), b.size());
+    const auto opt = pe + 24;
+    const auto security = opt + (u16 (opt) == 0x20b ? 112u : 96u) + 4 * 8; // data directory 4
+    if (security + 8 > b.size())
+        return sha256Hex (b.data(), b.size());
+    const auto certAt = (std::size_t) u32 (security);
+    std::vector<std::uint8_t> image (b.begin(), b.begin() + (std::ptrdiff_t) (certAt > security + 8 && certAt <= b.size() ? certAt : b.size()));
+    std::fill (image.begin() + (std::ptrdiff_t) (opt + 64), image.begin() + (std::ptrdiff_t) (opt + 68), (std::uint8_t) 0);
+    std::fill (image.begin() + (std::ptrdiff_t) security, image.begin() + (std::ptrdiff_t) (security + 8), (std::uint8_t) 0);
+    return sha256Hex (image.data(), image.size());
+}
+
 // The same SHA-256 fed in pieces (round 168a: the media of a project package are hashed while they are read, without
 // holding a whole recording in memory).
 class Sha256Stream

+ 4 - 1
src/core/Slayer.cpp

@@ -121,6 +121,9 @@ inline float bitsF (std::uint32_t u) noexcept
 
 // ------------------------------------------------------------------------------------------------ installation data
 constexpr const char* engineSha256 = "84b64c43cc6528401e1c4e84074785e100e8453c4db4c8322a5d5f608de724a9";
+// the same engine without its signature (peImageSha256Hex, round 169g): FL Studio 2025 ships this image signed with
+// another certificate, so its whole-file hash differs while every byte LYNX reads is the same
+constexpr const char* engineImageSha256 = "f33fd40e8fd530a25715dab192c8b5cb05b319f04b14b691c210ae562c73a07d";
 
 struct DllData
 {
@@ -146,7 +149,7 @@ std::shared_ptr<const DllData> loadDll (const std::string& path)
     if (! in)
         return nullptr;
     const std::vector<std::uint8_t> b ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
-    if (b.size() < 0x1000 || sha256Hex (b.data(), b.size()) != engineSha256)
+    if (b.size() < 0x1000 || (sha256Hex (b.data(), b.size()) != engineSha256 && peImageSha256Hex (b) != engineImageSha256))
         return nullptr;
     auto rd = [&] (std::size_t off, auto& v) { if (off + sizeof (v) <= b.size()) std::memcpy (&v, b.data() + off, sizeof (v)); };
     std::uint32_t pe = 0;

+ 21 - 27
src/core/TransistorBass.cpp

@@ -61,7 +61,8 @@ float bitsF (std::uint32_t u) noexcept
 }
 
 // ------------------------------------------------------------------------------------------------ installation data (§2.3)
-constexpr const char* engineSha256 = "4cc72470063a0a9f8f126102415cbb1ef2b91abb2995cd9fbdf2c8e676c6907f";
+// (FL Studio 2026's engine_x64.dll, SHA-256 4cc72470…6907f, was the build decoded in REA_rodada57; any build with the
+// same two cycle sets plays the same, see loadDll)
 
 struct Wave
 {
@@ -128,35 +129,13 @@ std::shared_ptr<const DllData> loadDll (const std::string& path)
     if (! in)
         return nullptr;
     const std::vector<std::uint8_t> b ((std::istreambuf_iterator<char> (in)), std::istreambuf_iterator<char>());
-    if (b.size() < 0x1000 || sha256Hex (b.data(), b.size()) != engineSha256)
+    if (b.size() < 0x1000 || b[0] != 'M' || b[1] != 'Z')
         return nullptr;
     auto rd = [&] (std::size_t off, auto& v) { if (off + sizeof (v) <= b.size()) std::memcpy (&v, b.data() + off, sizeof (v)); };
-    std::uint32_t pe = 0;
-    rd (0x3c, pe);
-    std::uint16_t sections = 0, optSize = 0;
-    rd (pe + 6, sections);
-    rd (pe + 20, optSize);
-    struct Section { std::uint32_t va, vs, ro, rs; };
-    std::vector<Section> secs;
-    for (std::uint32_t i = 0, o = pe + 24 + optSize; i < sections; ++i, o += 40)
-    {
-        Section s {};
-        rd (o + 8, s.vs);
-        rd (o + 12, s.va);
-        rd (o + 16, s.rs);
-        rd (o + 20, s.ro);
-        secs.push_back (s);
-    }
-    auto offset = [&] (std::uint32_t rva) -> std::size_t {
-        for (const auto& s : secs)
-            if (rva >= s.va && rva < s.va + std::min (s.vs, s.rs))
-                return (std::size_t) (s.ro + rva - s.va);
-        return b.size();
-    };
     auto t = std::make_shared<DllData>();
     // recorded cycles: count, then [size][RIFF bytes] (§2.3); each: (x − 0.63)·6.3157892, mean removed, guard point
-    auto readSet = [&] (std::uint32_t rva, int expected, std::vector<Wave>& out) {
-        auto at = offset (rva);
+    auto readSet = [&] (std::size_t at, int expected, std::vector<Wave>& out) {
+        out.clear();
         std::int32_t count = 0;
         rd (at, count);
         if (count != expected)
@@ -187,7 +166,22 @@ std::shared_ptr<const DllData> loadDll (const std::string& path)
         }
         return true;
     };
-    if (! readSet (0xFEAF0, 57, t->recorded) || ! readSet (0x15B2F0, 55, t->recorded2))
+    // round 169g (discussion #56): the two sets are found by their shape, [count][size]["RIFF"...], wherever the build put
+    // them. Only FL Studio 2026's DLL was accepted before (a whole-file hash and fixed addresses), so with any other FL
+    // version (2025's engine_x64.dll has the same 57 + 55 cycles, byte for byte, 0x400 bytes earlier) Transistor Bass
+    // could not be added and stayed silent in imported projects.
+    auto findSet = [&] (int expected, std::vector<Wave>& out) {
+        for (std::size_t at = 0; at + 16 <= b.size(); at += 4) // (the sets start 4-byte aligned)
+        {
+            std::int32_t count = 0;
+            rd (at, count);
+            if (count == expected && std::memcmp (b.data() + at + 8, "RIFF", 4) == 0 && readSet (at, expected, out))
+                return true;
+        }
+        out.clear();
+        return false;
+    };
+    if (! findSet (57, t->recorded) || ! findSet (55, t->recorded2))
         return nullptr;
     cache[path] = t;
     return t;

+ 3 - 0
src/engine/FlStudio.cpp

@@ -58,6 +58,9 @@ juce::File existingFolder (const juce::String& path)
 FlStudioInstall findFlStudio()
 {
     FlStudioInstall fl;
+    // test hook (round 169g): LYNX_NO_FL=1 = a computer without FL Studio, even where it is installed
+    if (juce::SystemStats::getEnvironmentVariable ("LYNX_NO_FL", {}).isNotEmpty())
+        return fl;
 
     // installation: where FL says it is, else the newest "FL Studio*" under Program Files\Image-Line
     // LYNX_FL_INSTALL=<folder> points at an installation anywhere (another Wine prefix, a copy, tests)

+ 27 - 26
src/ui/ExportDialog.cpp

@@ -1,5 +1,6 @@
 #include "ui/ExportDialog.h"
 
+#include "core/MessageThreadOwned.h"
 #include "core/PlaylistOps.h"
 #include "core/QuickRender.h"
 #include "core/Mastering.h"
@@ -21,6 +22,16 @@ namespace lynx
 {
 namespace
 {
+// the job of one stem / playlist track: made and deleted on the message thread, a Cancel never waits for it (round 169g)
+struct JobOnMessageThread : MessageThreadOwned<ExportJob>
+{
+    explicit JobOnMessageThread (juce::Thread& t)
+        : MessageThreadOwned<ExportJob> ([] (std::function<void()> f) { juce::MessageManager::callAsync (std::move (f)); },
+                                         [&t] { return t.threadShouldExit(); })
+    {
+    }
+};
+
 class ExportThread final : public juce::ThreadWithProgressWindow
 {
 public:
@@ -129,14 +140,14 @@ public:
             auto& item = items[i];
             setStatusMessage (item.name);
 
-            std::unique_ptr<ExportJob> job;
-            juce::WaitableEvent ready;
-            juce::MessageManager::callAsync ([&] {
-                job = std::make_unique<ExportJob> (item.song, options, item.file);
-                job->setExtraData (true);
-                ready.signal();
+            JobOnMessageThread slot (*this);
+            auto* job = slot.create ([&item, this] {
+                auto j = std::make_unique<ExportJob> (item.song, options, item.file);
+                j->setExtraData (true);
+                return j;
             });
-            ready.wait();
+            if (job == nullptr)
+                break; // (cancelled)
 
             juce::String error;
             const auto base = (double) i / (double) items.size();
@@ -151,12 +162,7 @@ public:
                 files.push_back (item.file);
             }
 
-            juce::WaitableEvent gone;
-            juce::MessageManager::callAsync ([&] {
-                job.reset();
-                gone.signal();
-            });
-            gone.wait();
+            slot.release();
         }
     }
 
@@ -1149,14 +1155,14 @@ public:
         {
             auto& item = items[i];
             setStatusMessage (item.name);
-            std::unique_ptr<ExportJob> job;
-            juce::WaitableEvent ready;
-            juce::MessageManager::callAsync ([&] {
-                job = std::make_unique<ExportJob> (item.song, options, item.file);
-                job->setExtraData (false);
-                ready.signal();
+            JobOnMessageThread slot (*this);
+            auto* job = slot.create ([&item, this] {
+                auto j = std::make_unique<ExportJob> (item.song, options, item.file);
+                j->setExtraData (false);
+                return j;
             });
-            ready.wait();
+            if (job == nullptr)
+                break; // (cancelled)
 
             juce::String error;
             const auto base = (double) i / (double) items.size();
@@ -1168,12 +1174,7 @@ public:
             else if (! threadShouldExit())
                 failed = true;
 
-            juce::WaitableEvent gone;
-            juce::MessageManager::callAsync ([&] {
-                job.reset();
-                gone.signal();
-            });
-            gone.wait();
+            slot.release();
         }
     }
 

+ 27 - 0
src/ui/ProjectLoading.cpp

@@ -186,6 +186,21 @@ private:
     }
 
     void timerCallback() override
+    {
+        // round 169g (crash reports, 5 in 3 days): a plugin that runs the message loop while it is created or prepared
+        // (Auto-Key pumps DispatchMessage in its setupIO / prepareToPlay) fired this timer again from inside
+        // preloadNextPlugin: the nested turn created the next plugin of the same queue and refreshed the panel under
+        // the outer one, which then crashed on freed strings. One turn at a time; the nested ticks are skipped.
+        if (inTurn)
+            return;
+        inTurn = true;
+        const juce::Component::SafePointer<LoadPanel> alive (this);
+        turn();
+        if (alive != nullptr) // (finish() deletes the panel)
+            inTurn = false;
+    }
+
+    void turn()
     {
         if (auto* parent = getParentComponent(); parent != nullptr && getBounds() != parent->getLocalBounds())
             setBounds (parent->getLocalBounds()); // (the main window may still be settling its size at start-up)
@@ -259,6 +274,17 @@ private:
     }
 
     void refresh()
+    {
+        if (inRefresh) // (performAnyPendingRepaintsNow can run a plugin's own messages, and onInstantiate calls this)
+            return;
+        inRefresh = true;
+        const juce::Component::SafePointer<LoadPanel> alive (this);
+        refreshNow();
+        if (alive != nullptr)
+            inRefresh = false;
+    }
+
+    void refreshNow()
     {
         const auto target = loadtrace::progress();
         shown = juce::jmax (shown, target);
@@ -302,6 +328,7 @@ private:
     bool slowWait = false;
     std::chrono::steady_clock::time_point modulesWaitStarted = std::chrono::steady_clock::now();
     int created = 0; // hosted plugins created so far
+    bool inTurn = false, inRefresh = false; // (re-entry from a plugin that pumps messages, round 169g)
     juce::String statusText;
 };
 } // namespace

+ 280 - 0
tests/Crash169gTests.inc

@@ -0,0 +1,280 @@
+// Round 169g (discussion #56 + the crash reports of 2026-10-31…11-03): FL engine DLLs of other FL Studio builds,
+// the export threads' Cancel, docs/analise/REA_rodada169g.md
+
+#include <thread>
+
+#include "core/DrumSynthLive.h"
+#include "core/MessageThreadOwned.h"
+#include "core/PhysicalModels.h"
+#include "core/Sha256.h"
+#include "core/Slayer.h"
+#include "core/TransistorBass.h"
+
+namespace crash169g
+{
+namespace fs = std::filesystem;
+
+std::vector<std::uint8_t> readAll (const fs::path& p)
+{
+    std::ifstream f (p, std::ios::binary);
+    return std::vector<std::uint8_t> ((std::istreambuf_iterator<char> (f)), std::istreambuf_iterator<char>());
+}
+
+void writeAll (const fs::path& p, const std::vector<std::uint8_t>& b)
+{
+    std::ofstream (p, std::ios::binary).write ((const char*) b.data(), (std::streamsize) b.size());
+}
+
+// FL Studio 2025.1.6's engine DLLs, taken from its installer (not part of the repository): LYNX_FL25_DLLS=<folder>,
+// default /mnt/e/lynx-work/crash169g/fl25 (3392 = Transistor Bass engine_x64, 1542 = Slayer_Engine, 310 =
+// BooBass_Eng_x64, 2741 = drumsynth_eng_x64); empty = not on this computer
+std::string fl25 (const char* name)
+{
+    const char* env = std::getenv ("LYNX_FL25_DLLS");
+    const auto p = fs::path (env != nullptr && *env != 0 ? env : "/mnt/e/lynx-work/crash169g/fl25") / name;
+    return fs::is_regular_file (p) ? p.string() : std::string();
+}
+
+std::string flGenerator (const char* folder, const char* file)
+{
+    if (realFlpDir.empty())
+        return {};
+    const auto p = fs::path (realFlpDir).parent_path() / "Plugins" / "Fruity" / "Generators" / folder / file;
+    return fs::is_regular_file (p) ? p.string() : std::string();
+}
+
+// a minimal PE32+ header: "MZ", e_lfanew, "PE\0\0", optional header magic 0x20B, checksum and certificate directory
+std::vector<std::uint8_t> fakePe (std::uint32_t checksum, std::uint32_t certAt, std::size_t size)
+{
+    std::vector<std::uint8_t> b (size, 0x11);
+    auto put32 = [&b] (std::size_t at, std::uint32_t v) { std::memcpy (b.data() + at, &v, 4); };
+    b[0] = 'M', b[1] = 'Z';
+    put32 (0x3c, 0x80);
+    put32 (0x80, 0x00004550u);
+    b[0x80 + 24] = 0x0b, b[0x80 + 25] = 0x02;
+    put32 (0x80 + 24 + 64, checksum);
+    put32 (0x80 + 24 + 112 + 32, certAt);
+    put32 (0x80 + 24 + 112 + 36, certAt != 0 ? (std::uint32_t) (size - certAt) : 0u);
+    return b;
+}
+} // namespace crash169g
+
+TEST (crash169g_pe_image_hash_ignores_the_signature)
+{
+    using namespace crash169g;
+    // unsigned, checksum 0: the whole-file hash (so the hashes LYNX already had stay valid)
+    const auto plain = fakePe (0, 0, 0x2000);
+    CHECK (lynx::peImageSha256Hex (plain) == lynx::sha256Hex (plain.data(), plain.size()));
+    // the same image signed (a checksum, a certificate table appended): the same image hash
+    auto signedCopy = fakePe (0x1234567, 0x2000, 0x2400);
+    std::fill (signedCopy.begin() + 0x2000, signedCopy.end(), (std::uint8_t) 0x99);
+    CHECK (lynx::peImageSha256Hex (signedCopy) == lynx::peImageSha256Hex (plain));
+    CHECK (lynx::sha256Hex (signedCopy.data(), signedCopy.size()) != lynx::sha256Hex (plain.data(), plain.size()));
+    // a different image: a different hash; not a PE: the plain hash
+    auto other = plain;
+    other[0x1800] ^= 1;
+    CHECK (lynx::peImageSha256Hex (other) != lynx::peImageSha256Hex (plain));
+    const std::vector<std::uint8_t> text { 'h', 'e', 'l', 'l', 'o' };
+    CHECK (lynx::peImageSha256Hex (text) == lynx::sha256Hex (text.data(), text.size()));
+}
+
+// discussion #56 ("Transistor Bass is described as implemented but I really can't get it working"): only FL Studio
+// 2026's engine_x64.dll was accepted (whole-file hash, fixed addresses); FL 2025's has the same 57 + 55 cycles at
+// other offsets. Any build with them now plays, sample for sample the same.
+TEST (crash169g_transistor_bass_plays_with_other_fl_builds)
+{
+    using namespace crash169g;
+    const auto dll26 = flGenerator ("Transistor Bass", "engine_x64.dll");
+    if (dll26.empty())
+        return; // (no FL installation)
+    CHECK (lynx::transistorBassDllUsable (dll26));
+    const auto state = tbassPresetState ("Factory programs.fst");
+    CHECK (! state.empty());
+    std::vector<lynx::tbass::RefNote> notes (2);
+    notes[0].key = 36, notes[0].release = 30000;
+    notes[1].start = 33000, notes[1].key = 43;
+    const auto reference = lynx::tbass::renderReference (state, dll26, notes, 44100.0, 66150);
+    double energy = 0.0;
+    for (const auto v : reference)
+        energy += (double) v * v;
+    CHECK (reference.size() == 2 * 66150 && energy > 1.0);
+
+    // the same DLL with its data 0x400 bytes further on (another build's layout): found by shape, same sound
+    auto bytes = readAll (dll26);
+    bytes.insert (bytes.begin() + 0x1000, 0x400, (std::uint8_t) 0);
+    const auto shifted = (fs::temp_directory_path() / "lynx-crash169g-tbass-shifted.dll").string();
+    writeAll (shifted, bytes);
+    CHECK (lynx::transistorBassDllUsable (shifted));
+    CHECK (lynx::tbass::renderReference (state, shifted, notes, 44100.0, 66150) == reference);
+    // no cycles in it (another plugin's DLL, a truncated file): not usable, as before
+    bytes.resize (0xF0000);
+    writeAll (shifted, bytes);
+    CHECK (! lynx::transistorBassDllUsable (shifted));
+    fs::remove (shifted);
+
+    // FL Studio 2025.1.6's own engine_x64.dll (when this computer has a copy)
+    if (const auto dll25 = fl25 ("3392.dll"); ! dll25.empty())
+    {
+        CHECK (lynx::transistorBassDllUsable (dll25));
+        CHECK (lynx::tbass::renderReference (state, dll25, notes, 44100.0, 66150) == reference);
+    }
+}
+
+// the user's path: Transistor Bass added from the plugin list (natives::makeChannel) on a computer whose FL is 2025
+TEST (crash169g_transistor_bass_from_the_plugin_list_with_fl_2025)
+{
+    using namespace crash169g;
+    using namespace lynx;
+    const auto dll25 = fl25 ("3392.dll");
+    if (realFlpDir.empty() || dll25.empty())
+        return;
+    const auto root = fs::temp_directory_path() / "lynx-crash169g-fl25";
+    fs::create_directories (root / "Plugins" / "Fruity" / "Generators" / "Transistor Bass");
+    fs::copy_file (dll25, root / "Plugins" / "Fruity" / "Generators" / "Transistor Bass" / "engine_x64.dll", fs::copy_options::overwrite_existing);
+    auto fl = natives142::flAccess();
+    const auto data = fl.roots.data;
+    fl.roots.factoryData = root.string();
+    const auto* engine = natives::instrumentEngine (InstrumentKind::transistorbass);
+    CHECK (engine != nullptr && natives::available (*engine, fl));
+    const auto c = natives::makeChannel (InstrumentKind::transistorbass, fl);
+    CHECK (c.has_value());
+    if (c)
+    {
+        CHECK (c->instrument == InstrumentKind::transistorbass && c->samplePath.find ("lynx-crash169g-fl25") != std::string::npos);
+        CHECK (natives142::renderChannel (*c, fl, 60) > 1.0e-3);
+    }
+    (void) data;
+    fs::remove_all (root);
+}
+
+// the other engines that read FL's DLLs, with FL 2025.1.6's builds: FL Slayer's engine is the same image signed
+// again, BooBass's and DrumSynth Live's differ in time stamps only
+TEST (crash169g_other_engine_dlls_of_fl_2025)
+{
+    using namespace crash169g;
+    using namespace lynx;
+    if (const auto slayer25 = fl25 ("1542.dll"); ! slayer25.empty())
+    {
+        CHECK (slayerDllUsable (slayer25));
+        const auto c = realFlpDir.empty() ? std::nullopt : natives::makeChannel (InstrumentKind::slayer, natives142::flAccess());
+        if (const auto slayer26 = flGenerator ("FL Slayer", "Slayer_Engine.dll"); ! slayer26.empty() && c)
+        {
+            const auto params = slayerStateParams (c->pluginState);
+            CHECK (params.size() == 29);
+            std::vector<slayer::RefNote> notes (1);
+            notes[0].release = 20000;
+            const auto a = slayer::renderReference (params, slayer26, notes, 44100.0, 44100);
+            CHECK (! a.empty() && a == slayer::renderReference (params, slayer25, notes, 44100.0, 44100));
+        }
+    }
+    if (const auto boo25 = fl25 ("310.dll"); ! boo25.empty())
+    {
+        CHECK (booBassDllUsable (boo25));
+        if (const auto boo26 = flGenerator ("BooBass", "BooBass_Eng_x64.dll"); ! boo26.empty() && ! realFlpDir.empty())
+        {
+            const auto fl = natives142::flAccess();
+            if (auto c = natives::makeChannel (InstrumentKind::boobass, fl))
+            {
+                const auto a = natives142::renderChannel (*c, fl, 40);
+                c->samplePath = boo25;
+                CHECK (a > 1.0e-3 && natives142::renderChannel (*c, fl, 40) == a);
+            }
+        }
+    }
+    if (const auto ds25 = fl25 ("2741.dll"); ! ds25.empty())
+        CHECK (drumSynthDllUsable (ds25));
+}
+
+// the export threads' Cancel (ui/ExportDialog.cpp): the worker never waits for a message thread that is itself
+// waiting for the worker; the object is still made and deleted by the posted calls only
+TEST (crash169g_message_thread_owned_cancel)
+{
+    struct Job
+    {
+        explicit Job (std::atomic<int>& l) : live (l) { ++live; }
+        ~Job() { --live; deletedOn = std::this_thread::get_id(); }
+        std::atomic<int>& live;
+        static inline std::thread::id deletedOn {};
+    };
+    std::mutex lock;
+    std::vector<std::function<void()>> queue; // the "message thread": runs only when the test says so
+    auto post = [&] (std::function<void()> f) {
+        const std::lock_guard<std::mutex> g (lock);
+        queue.push_back (std::move (f));
+    };
+    auto runQueue = [&] {
+        std::vector<std::function<void()>> now;
+        {
+            const std::lock_guard<std::mutex> g (lock);
+            now.swap (queue);
+        }
+        for (auto& f : now)
+            f();
+    };
+    std::atomic<int> live { 0 };
+    std::atomic<bool> stop { false };
+
+    // normal: created and deleted by the owning thread while the worker waits
+    {
+        std::atomic<bool> running { true };
+        std::thread owner ([&] {
+            while (running)
+            {
+                runQueue();
+                std::this_thread::sleep_for (std::chrono::milliseconds (1));
+            }
+            runQueue();
+        });
+        std::thread worker ([&] {
+            lynx::MessageThreadOwned<Job> slot (post, [&] { return stop.load(); });
+            auto* j = slot.create ([&] { return std::make_unique<Job> (live); });
+            CHECK (j != nullptr && live == 1);
+            slot.release();
+            CHECK (live == 0);
+        });
+        worker.join();
+        running = false;
+        const auto ownerId = owner.get_id();
+        owner.join();
+        CHECK (live == 0 && Job::deletedOn == ownerId);
+    }
+
+    // cancelled while the owning thread is blocked (Cancel waiting in stopThread): the worker returns at once
+    stop = false;
+    const auto started = std::chrono::steady_clock::now();
+    std::thread worker ([&] {
+        lynx::MessageThreadOwned<Job> slot (post, [&] { return stop.load(); });
+        auto* j = slot.create ([&] { return std::make_unique<Job> (live); });
+        CHECK (j == nullptr);
+    }); // (its destructor queues the deletion and does not wait either)
+    std::this_thread::sleep_for (std::chrono::milliseconds (60));
+    stop = true;
+    worker.join();
+    CHECK (std::chrono::steady_clock::now() - started < std::chrono::seconds (5));
+    CHECK (live == 0);
+    runQueue(); // the message thread free again: the creation call sees the cancel and makes nothing
+    CHECK (live == 0);
+
+    // cancelled after the object exists: deleted later by the owning thread, never by the worker
+    stop = false;
+    std::atomic<bool> made { false };
+    std::thread worker2 ([&] {
+        lynx::MessageThreadOwned<Job> slot (post, [&] { return stop.load(); });
+        std::thread helper ([&] {
+            while (! made)
+            {
+                runQueue();
+                std::this_thread::sleep_for (std::chrono::milliseconds (1));
+            }
+        });
+        auto* j = slot.create ([&] { auto p = std::make_unique<Job> (live); made = true; return p; });
+        helper.join();
+        CHECK (j != nullptr && live == 1);
+        stop = true;
+    }); // (release in the destructor: queued, not waited for)
+    worker2.join();
+    CHECK (live == 1);
+    const auto here = std::this_thread::get_id();
+    runQueue();
+    CHECK (live == 0 && Job::deletedOn == here);
+}

+ 1 - 0
tests/tests.cpp

@@ -17017,3 +17017,4 @@ TEST (fl_low_lifter_matches_fl_engine)
 #include "Mixer168hTests.inc"
 #include "Mute53fTests.inc"
 #include "Issue32cTests.inc"
+#include "Crash169gTests.inc"