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

Author Topic: thrown exception to draw?  (Read 2008 times)

0 Members and 1 Guest are viewing this topic.

help me

  • Newbie
  • *
  • Posts: 2
    • View Profile
thrown exception to draw?
« on: June 25, 2020, 09:32:10 pm »
I was planning to make a control multiple sprites game and I know it is risky but I'm risking anyways. So I made the player class in the game.cpp an array and all goes well until an exception is thrown:

Exception thrown at 0x7922CF29 (sfml-graphics-d-2.dll) in sim.exe: 0xC0000005: Access violation reading location 0x00000008.

to

target.draw(this->sprite);

in

void Plane::render(RenderTarget& target)
{
   //target.draw(this->sprite);
}

and if I put the array out of the equation it works as normal. What to do??
and btw if I comment the one that got thrown exception it sort of worked, it ran but it was thrown exception sim.exe has triggered a break point

ps. idk how to insert image I'm 100% new I'm so sorry

Hapax

  • Hero Member
  • *****
  • Posts: 3379
  • My number of posts is shown in hexadecimal.
    • View Profile
    • Links
Re: thrown exception to draw?
« Reply #1 on: June 26, 2020, 08:41:11 pm »
It's triggering a breakpoint? Did you set one?

More information about this would be helpful.
Are you storing a texture with in that class?
If the array is the problem, what sort of array are you using? Do you mean a C array, an std::array or maybe std::vector?

One thing to note is that some containers (for example, vector) can relocate when re-sized. If your texture is contained within the class and it relocates that instance, the sprite's pointer to the texture is invalid and can cause these sorts of problems.

That was a speculation based on commonly-seen mistakes.
Selba Ward -SFML drawables
Cheese Map -Drawable Layered Tile Map
Kairos -Timing Library
Grambol
 *Hapaxia Links*

Nexus

  • SFML Team
  • Hero Member
  • *****
  • Posts: 6287
  • Thor Developer
    • View Profile
    • Bromeon
Re: thrown exception to draw?
« Reply #2 on: June 27, 2020, 01:09:42 pm »
Based on the address, it looks like you're dereferencing a null pointer.

Also read this post and follow the instructions.
Zloxx II: action platformer
Thor Library: particle systems, animations, dot products, ...
SFML Game Development:

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11033
    • View Profile
    • development blog
    • Email
Re: thrown exception to draw?
« Reply #3 on: June 27, 2020, 01:21:01 pm »
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/