From cb01268562a47e6a1c32559f58fbadd46e52d304 Mon Sep 17 00:00:00 2001 From: Aaron Franke Date: Tue, 27 Nov 2018 21:58:00 -0500 Subject: Fix many errors found by PVS-Studio Fix errors 2, 3, 4, 6, 8, 9, 11, 12, 13, 14, and 15. --- scene/resources/texture.cpp | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) (limited to 'scene/resources') diff --git a/scene/resources/texture.cpp b/scene/resources/texture.cpp index 682bfebdd2..4f4d375481 100644 --- a/scene/resources/texture.cpp +++ b/scene/resources/texture.cpp @@ -994,11 +994,11 @@ void AtlasTexture::_bind_methods() { void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_modulate, bool p_transpose, const Ref &p_normal_map) const { - Rect2 rc = region; - if (!atlas.is_valid()) return; + Rect2 rc = region; + if (rc.size.width == 0) { rc.size.width = atlas->get_width(); } @@ -1013,11 +1013,11 @@ void AtlasTexture::draw(RID p_canvas_item, const Point2 &p_pos, const Color &p_m void AtlasTexture::draw_rect(RID p_canvas_item, const Rect2 &p_rect, bool p_tile, const Color &p_modulate, bool p_transpose, const Ref &p_normal_map) const { - Rect2 rc = region; - if (!atlas.is_valid()) return; + Rect2 rc = region; + if (rc.size.width == 0) { rc.size.width = atlas->get_width(); } @@ -1048,11 +1048,11 @@ void AtlasTexture::draw_rect_region(RID p_canvas_item, const Rect2 &p_rect, cons bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, Rect2 &r_rect, Rect2 &r_src_rect) const { - Rect2 rc = region; - if (!atlas.is_valid()) return false; + Rect2 rc = region; + Rect2 src = p_src_rect; if (src.size == Size2()) { src.size = rc.size; @@ -1084,11 +1084,13 @@ bool AtlasTexture::get_rect_region(const Rect2 &p_rect, const Rect2 &p_src_rect, bool AtlasTexture::is_pixel_opaque(int p_x, int p_y) const { - if (atlas.is_valid()) { - return atlas->is_pixel_opaque(p_x + region.position.x + margin.position.x, p_x + region.position.y + margin.position.y); - } + if (!atlas.is_valid()) + return true; - return true; + int x = p_x + region.position.x + margin.position.x; + int y = p_y + region.position.y + margin.position.y; + + return atlas->is_pixel_opaque(x, y); } AtlasTexture::AtlasTexture() { -- cgit v1.2.3