diff --git a/SDL2pp/Point.cc b/SDL2pp/Point.cc index d36f005..36cf6ae 100644 --- a/SDL2pp/Point.cc +++ b/SDL2pp/Point.cc @@ -51,11 +51,11 @@ bool Point::operator!=(const Point& other) const { } SDL_Point* Point::Get() { - return &point_; + return valid_ ? &point_ : nullptr; } const SDL_Point* Point::Get() const { - return &point_; + return valid_ ? &point_ : nullptr; } bool Point::IsNull() const { diff --git a/SDL2pp/Rect.cc b/SDL2pp/Rect.cc index b04a7d1..8abc42c 100644 --- a/SDL2pp/Rect.cc +++ b/SDL2pp/Rect.cc @@ -54,11 +54,11 @@ bool Rect::operator!=(const Rect& other) const { } SDL_Rect* Rect::Get() { - return &rect_; + return valid_ ? &rect_ : nullptr; } const SDL_Rect* Rect::Get() const { - return &rect_; + return valid_ ? &rect_ : nullptr; } Rect Rect::FromCenter(int cx, int cy, int w, int h) { diff --git a/tests/test_pointrect.cc b/tests/test_pointrect.cc index ebfd627..34a251e 100644 --- a/tests/test_pointrect.cc +++ b/tests/test_pointrect.cc @@ -33,6 +33,7 @@ BEGIN_TEST() EXPECT_TRUE(p != Point(1,2)); EXPECT_TRUE(p == Point::Null()); EXPECT_TRUE(p.IsNull()); + EXPECT_TRUE(p.Get() == nullptr); } { @@ -114,6 +115,7 @@ BEGIN_TEST() EXPECT_TRUE(r != Rect(1,2,3,4)); EXPECT_TRUE(r == Rect::Null()); EXPECT_TRUE(r.IsNull()); + EXPECT_TRUE(r.Get() == nullptr); } {