diff --git a/src/app/doc_exporter.cpp b/src/app/doc_exporter.cpp index 57e79bdcf..9eb62541a 100644 --- a/src/app/doc_exporter.cpp +++ b/src/app/doc_exporter.cpp @@ -1185,13 +1185,18 @@ Doc* DocExporter::createEmptyTexture(const Samples& samples, int maxColors = 256; gfx::ColorSpaceRef colorSpace; color_t transparentColor = 0; - bool ui = false; -#ifdef ENABLE_UI - if (App::instance()->isGui()) - ui = true; -#endif + + // We generate a palette for file formats that support a color + // palette inside, or if the UI/preview is available/required. + // + // As a side note, here we cannot use a possible + // ctx->isUIAvailable() (instead of App::instance()->isGui()) + // because when the sprite sheet is generated from the UI, a + // temporal non-UI context is created in a background thread. + const bool paletteRequiredByUIPreview = App::instance()->isGui(); const bool textureSupportsPalette = - format_supports_palette(m_textureFilename) || ui; + format_supports_palette(m_textureFilename) || + paletteRequiredByUIPreview; for (const auto& sample : samples) { if (token.canceled())