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

Author Topic: RenderTarget Pointer&Reference issue  (Read 7752 times)

0 Members and 1 Guest are viewing this topic.

Nitetesi

  • Newbie
  • *
  • Posts: 9
    • View Profile
RenderTarget Pointer&Reference issue
« on: November 20, 2021, 04:51:16 pm »
Too lazy to explain in detail

void Entity::render(sf::RenderTarget& target)
{
        target.draw(this->entity);
}
 

0xC0000005: Access violation reading location 0x0000000000000000.


Render function in Window.cpp
this->entity->render(*this->window);
 

Window.h
-------------------------
sf::RenderWindow* window;
Entity* entity;

eXpl0it3r

  • SFML Team
  • Hero Member
  • *****
  • Posts: 11034
    • View Profile
    • development blog
    • Email
Re: RenderTarget Pointer&Reference issue
« Reply #1 on: November 21, 2021, 10:20:19 pm »
You're probably reading or writing to a nullptr.

Too lazy to explain in detail ;)
Official FAQ: https://www.sfml-dev.org/faq.php
Official Discord Server: https://discord.gg/nr4X7Fh
——————————————————————
Dev Blog: https://duerrenberger.dev/blog/

Nitetesi

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: RenderTarget Pointer&Reference issue
« Reply #2 on: November 27, 2021, 07:49:27 pm »
You're probably reading or writing to a nullptr.

Too lazy to explain in detail ;)

Could you explain?

Nitetesi

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: RenderTarget Pointer&Reference issue
« Reply #3 on: November 28, 2021, 03:06:01 pm »
You're probably reading or writing to a nullptr.

Too lazy to explain in detail ;)
void Entity::render(sf::RenderTarget& target)
{
        this->setEntity();
        target.draw(this->entity);
}
Nothing looks undefined and now i am seeing that error on setEntity() function

void MainWindow::render()
{
        this->setVariables();
        this->window->clear(this->gray);
        this->window->draw(this->posText);
        this->entity->render(*this->window);
        this->window->display();
}

kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: RenderTarget Pointer&Reference issue
« Reply #4 on: November 28, 2021, 03:33:22 pm »
"Access violation reading location 0x0000000000000000" means the program is trying to read from location 0 in memory, which isn't allowed. This is typically caused by using a pointer which is null.
If you run the program in a debugger, it should stop on the actual location of the null dereference. The code you provided might not actually be where things are failing (if it is, then probably either window or entity are null).

Nitetesi

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: RenderTarget Pointer&Reference issue
« Reply #5 on: November 28, 2021, 06:15:16 pm »
"Access violation reading location 0x0000000000000000" means the program is trying to read from location 0 in memory, which isn't allowed. This is typically caused by using a pointer which is null.
If you run the program in a debugger, it should stop on the actual location of the null dereference. The code you provided might not actually be where things are failing (if it is, then probably either window or entity are null).

The address is now static
Access violation reading location 0x0000000000000108.
And i am sure that the problem is Entity



kojack

  • Sr. Member
  • ****
  • Posts: 343
  • C++/C# game dev teacher.
    • View Profile
Re: RenderTarget Pointer&Reference issue
« Reply #6 on: November 28, 2021, 08:10:38 pm »
Yep, the Entity pointer there (the "this" value) is null.
Maybe the code that set it up wasn't called, or something failed.

Values of pointers close to 0 (like 0x0000000000000108) are still from a null pointer. It's using the null as the base address of an object that doesn't exist, then offsetting from that to find member variables (resulting in the error at a near 0 value).

Nitetesi

  • Newbie
  • *
  • Posts: 9
    • View Profile
Re: RenderTarget Pointer&Reference issue
« Reply #7 on: November 29, 2021, 09:10:05 am »
Yep, the Entity pointer there (the "this" value) is null.
Maybe the code that set it up wasn't called, or something failed.

Values of pointers close to 0 (like 0x0000000000000108) are still from a null pointer. It's using the null as the base address of an object that doesn't exist, then offsetting from that to find member variables (resulting in the error at a near 0 value).

Yeah i fixed that by making a function that initializes Entity

void MainWindow::initializeEntity(Entity& entity)
{
        this->entity = &entity;
}