if (sf::Mouse::isButtonPressed(sf::Mouse::Left))
{
sf::Vector2i MousePosition = sf::Mouse::getPosition(window);
for (int i=0; i<24; i++)
{
for (int j=0; j<24; j++)
{
if((int)rect[i][j].getPosition().x < MousePosition.x&&
(int)rect[i][j].getPosition().y < MousePosition.y &&
(int)rect[i][j].getPosition().x + (int)rect[i][j].getGlobalBounds().width > MousePosition.x
&& (int)rect[i][j].getPosition().y + (int)rect[i][j].getGlobalBounds().height > MousePosition.y)
{
rect[i][j].setFillColor(sf::Color::Red);
break;
}
}
}
}
When I click on the some rect, I have error in this line:
if((int)rect[i][j].getPosition().x < MousePosition.x&&
(int)rect[i][j].getPosition().y < MousePosition.y &&
(int)rect[i][j].getPosition().x + (int)rect[i][j].getGlobalBounds().width > MousePosition.x
&& (int)rect[i][j].getPosition().y + (int)rect[i][j].getGlobalBounds().height > MousePosition.y)
Unhandled exception at 0x00F0F1C2 in Project2.exe: 0xC0000005: Access violation writing location 0x00180000.