Welcome, Guest. Please login or register. Did you miss your activation email?

Author Topic: exception thrown issues  (Read 1180 times)

0 Members and 1 Guest are viewing this topic.

help me

  • Newbie
  • *
  • Posts: 2
    • View Profile
exception thrown issues
« on: June 26, 2020, 09:40:21 pm »
I was creating this game that requires to control multiple sprite movement, so I created an array player class(Player* player[10];). I write all of the renders and updates and I got thrown an exception in the line:

target.draw(this->sprite);

in my render function inside the Player class

void Player::render(RenderTarget& target)
{
   target.draw(this->sprite);
}
in the game.cpp:
for (int i = 0; i <= c; i++ )//c is the amount of players
   {
      this->player->render(*this->window);
   }

this is the exception:

Unhandled exception at 0x7B81CF29 (sfml-graphics-d-2.dll) in sim.exe: 0xC0000005: Access violation reading location 0x00000008.

and it can't run.
if i comment that line only(target.draw(this->sprite);) it runs as normal but when closed it throws another exception:

sim.exe has triggered a breakpoint

before this happened I didn't make the player class an array and it ran smoothly but tbh I don't know if it will run correctly or not. it has no errors detected and it confuses me how to stop it from running after the exception is thrown(both exceptions).

ps. sorry I didn't post any image I still don't know how

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 10819
    • View Profile
    • development blog
    • Email
Re: exception thrown issues
« Reply #1 on: June 27, 2020, 10:40:03 am »
Please don't double post. Use your other thread to solve your issues. You should also spend some time researching the issue yourself. There are thousands of internet search results for your error message. ;)

for (int i = 0; i <= c; i++ )

This counts from 0 to c and if c = 10, then it goes from 0 to 10, but your array only has indexes going from 0 to 9.
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Neil

  • Newbie
  • *
  • Posts: 27
    • View Profile
Re: exception thrown issues
« Reply #2 on: July 05, 2020, 09:10:37 am »
To prevent bugs, I suggest using vectors and iterators instead of passing around raw arrays and making assumptions about their size.

 

anything