Skip to content

Commit

Permalink
Renderers: Add sanity check to GenerateTexture calls
Browse files Browse the repository at this point in the history
  • Loading branch information
mikke89 committed Jan 13, 2025
1 parent d02fb09 commit 28907a1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 0 deletions.
2 changes: 2 additions & 0 deletions Backends/RmlUi_Renderer_GL2.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -309,6 +309,8 @@ Rml::TextureHandle RenderInterface_GL2::LoadTexture(Rml::Vector2i& texture_dimen

Rml::TextureHandle RenderInterface_GL2::GenerateTexture(Rml::Span<const Rml::byte> source, Rml::Vector2i source_dimensions)
{
RMLUI_ASSERT(source.data() && source.size() == source_dimensions.x * source_dimensions.y * 4);

GLuint texture_id = 0;
glGenTextures(1, &texture_id);
if (texture_id == 0)
Expand Down
2 changes: 2 additions & 0 deletions Backends/RmlUi_Renderer_GL3.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1272,6 +1272,8 @@ Rml::TextureHandle RenderInterface_GL3::LoadTexture(Rml::Vector2i& texture_dimen

Rml::TextureHandle RenderInterface_GL3::GenerateTexture(Rml::Span<const Rml::byte> source_data, Rml::Vector2i source_dimensions)
{
RMLUI_ASSERT(source_data.data() && source_data.size() == source_dimensions.x * source_dimensions.y * 4);

GLuint texture_id = 0;
glGenTextures(1, &texture_id);
if (texture_id == 0)
Expand Down
2 changes: 2 additions & 0 deletions Backends/RmlUi_Renderer_SDL.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -205,6 +205,8 @@ Rml::TextureHandle RenderInterface_SDL::LoadTexture(Rml::Vector2i& texture_dimen

Rml::TextureHandle RenderInterface_SDL::GenerateTexture(Rml::Span<const Rml::byte> source, Rml::Vector2i source_dimensions)
{
RMLUI_ASSERT(source.data() && source.size() == source_dimensions.x * source_dimensions.y * 4);

#if SDL_MAJOR_VERSION >= 3
auto CreateSurface = [&]() {
return SDL_CreateSurfaceFrom(source_dimensions.x, source_dimensions.y, SDL_PIXELFORMAT_RGBA32, (void*)source.data(), source_dimensions.x * 4);
Expand Down
1 change: 1 addition & 0 deletions Backends/RmlUi_Renderer_VK.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -485,6 +485,7 @@ Rml::TextureHandle RenderInterface_VK::LoadTexture(Rml::Vector2i& texture_dimens

Rml::TextureHandle RenderInterface_VK::GenerateTexture(Rml::Span<const Rml::byte> source_data, Rml::Vector2i source_dimensions)
{
RMLUI_ASSERT(source_data.data() && source_data.size() == source_dimensions.x * source_dimensions.y * 4);
Rml::String source_name = "generated-texture";
return CreateTexture(source_data, source_dimensions, source_name);
}
Expand Down

0 comments on commit 28907a1

Please sign in to comment.