286
Graphics / Re: Access violation reading location while drawing sprites
« on: April 27, 2021, 03:58:22 pm »
Sandbag has a window member. But init takes a window argument, then does:
window = window;
The window argument is "shadowing" the window member, meaning the member one is hidden due to duplicate name. So window = window is assigning the argument to itself, the member version isn't changed, meaning when it gets to the paint function the window member is invalid and crashes.
https://www.learncpp.com/cpp-tutorial/variable-shadowing-name-hiding/
Change either the member name or argument name and it should work.
window = window;
The window argument is "shadowing" the window member, meaning the member one is hidden due to duplicate name. So window = window is assigning the argument to itself, the member version isn't changed, meaning when it gets to the paint function the window member is invalid and crashes.
https://www.learncpp.com/cpp-tutorial/variable-shadowing-name-hiding/
Change either the member name or argument name and it should work.