Skip to content

Commit

Permalink
Log warnings when SVG or Lottie files cannot be rendered, see #687
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Nov 3, 2024
1 parent 88dee46 commit 90e0903
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 0 deletions.
3 changes: 3 additions & 0 deletions Source/Lottie/ElementLottie.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -239,7 +239,10 @@ void ElementLottie::UpdateTexture()
}

if (!texture_interface.GenerateTexture({p_data, total_bytes}, render_dimensions))
{
Log::Message(Rml::Log::Type::LT_WARNING, "Could not generate texture for lottie animation: %s", GetAttribute<String>("src", "").c_str());
return false;
}
return true;
};

Expand Down
6 changes: 6 additions & 0 deletions Source/SVG/ElementSVG.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -187,7 +187,10 @@ void ElementSVG::UpdateTexture()
RMLUI_ASSERT(svg_document);
lunasvg::Bitmap bitmap = svg_document->renderToBitmap(render_dimensions.x, render_dimensions.y);
if (!bitmap.valid() || !bitmap.data())
{
Log::Message(Rml::Log::Type::LT_WARNING, "Could not render SVG to bitmap: %s", GetAttribute<String>("src", "").c_str());
return false;
}

// Swap red and blue channels, assuming LunaSVG v2.3.2 or newer, to convert to RmlUi's expected RGBA-ordering.
const size_t bitmap_byte_size = bitmap.width() * bitmap.height() * 4;
Expand All @@ -196,7 +199,10 @@ void ElementSVG::UpdateTexture()
std::swap(bitmap_data[i], bitmap_data[i + 2]);

if (!texture_interface.GenerateTexture({reinterpret_cast<const Rml::byte*>(bitmap.data()), bitmap_byte_size}, render_dimensions))
{
Log::Message(Rml::Log::Type::LT_WARNING, "Could not generate texture for SVG: %s", GetAttribute<String>("src", "").c_str());
return false;
}
return true;
};

Expand Down

0 comments on commit 90e0903

Please sign in to comment.