From 58d4671c24254fda4d33af595f2e4b2c1dacc501 Mon Sep 17 00:00:00 2001 From: Patrik Huber Date: Mon, 11 Aug 2025 20:21:05 +0100 Subject: [PATCH] Fixes to frame_generator sample (#9050) * [Fix] frame_generator sample: open ifstream with ios::binary * [Fix] frame_generator sample: allocate storage for g_materialBuffer reserve() merely reserves memory, but does not actually change the size of the vector. * [Fix] frame_generator sample: destroy materials/renderables during cleanup Otherwise the sample crashes with a Filament error saying that the material is still associated with a renderable. --- samples/frame_generator.cpp | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/samples/frame_generator.cpp b/samples/frame_generator.cpp index 55494955e6..c8557e95dc 100644 --- a/samples/frame_generator.cpp +++ b/samples/frame_generator.cpp @@ -224,6 +224,13 @@ static int handleCommandLineArgments(int argc, char* argv[], Config* config) { } static void cleanup(Engine* engine, View*, Scene*) { + for (auto& renderable: g_meshSet->getRenderables()) { + auto instance = engine->getRenderableManager().getInstance(renderable); + if (instance) { + engine->destroy(renderable); + } + } + for (auto material : g_meshMaterialInstances) { engine->destroy(material.second); } @@ -253,9 +260,9 @@ static void readMaterial(Engine* engine) { return; } - std::ifstream in(g_materialPath.c_str(), std::ifstream::in); + std::ifstream in(g_materialPath.c_str(), std::ifstream::in | std::ios::binary); if (in.is_open()) { - g_materialBuffer.reserve(static_cast(fileSize)); + g_materialBuffer.resize(static_cast(fileSize)); if (in.read(g_materialBuffer.data(), fileSize)) { g_material = Material::Builder() .package((void*) g_materialBuffer.data(), (size_t) fileSize)