diff --git a/src/drawableline.cpp b/src/drawableline.cpp index 6639a23..fd96569 100644 --- a/src/drawableline.cpp +++ b/src/drawableline.cpp @@ -112,24 +112,30 @@ namespace cloonel { LineBase scaledLine(*this); scaledLine += static_cast(parPos); scaledLine *= parScaling; + const short2 wh(static_cast(m_sdlmain->WidthHeight())); { SDL_Rect screen; screen.x = screen.y = 0; - const short2 wh(static_cast(m_sdlmain->WidthHeight())); screen.w = wh.x(); screen.h = wh.y(); ClipLine(screen, scaledLine); } - const int16_t h = static_cast(m_sdlmain->WidthHeight().y()); + if (scaledLine[0] != scaledLine[1]) { - SDL_RenderDrawLine( - m_sdlmain->GetRenderer(), - scaledLine[0].x(), - h - scaledLine[0].y(), - scaledLine[1].x(), - h - scaledLine[1].y() - ); + const bool isOnScreen = scaledLine[0] >= short2(0) and scaledLine[0] < wh and + scaledLine[1] >= short2(0) and scaledLine[1] < wh; + + if (isOnScreen) { + const int16_t h = static_cast(m_sdlmain->WidthHeight().y()); + SDL_RenderDrawLine( + m_sdlmain->GetRenderer(), + scaledLine[0].x(), + h - scaledLine[0].y(), + scaledLine[1].x(), + h - scaledLine[1].y() + ); + } } //Returns 0 on success or a negative error code on failure; call SDL_GetError() for more information. //http://www.ginkgobitter.org/sdl/?SDL_RenderDrawLine