Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Read Access Violation in Window::RegisterCallbacks() #13

Closed
safi-huss opened this issue Jun 2, 2020 · 3 comments
Closed

Read Access Violation in Window::RegisterCallbacks() #13

safi-huss opened this issue Jun 2, 2020 · 3 comments

Comments

@safi-huss
Copy link

safi-huss commented Jun 2, 2020

Hi,

I am getting a read access violation when I reach this line;

`void Window::RegisterCallbacks(std::shared_ptr arg_pGame)
{
m_pGame = arg_pGame; //Read Access violation here

return;

}
`
I am new to this, but my hunch is that since we are passing it "shared_from_this", it may not be move assignable. I could be completely wrong too.

How would I fix it?

@jpvanoosten
Copy link
Owner

It looks like you've made some changes to the code. For example, std::shared_ptr is a template class but you are not specifying any template arguments in the code example. It should be std::shared_ptr<Game> as can be seen here DX12Lib/src/Window.cpp#L188.

Also, when using shared_from_this, your class must publicly inherit from std::enable_shared_from_this<T> (where T is the derived class) as can be seen here: DX12Lib/inc/Game.h#L42.

@safi-huss
Copy link
Author

safi-huss commented Jun 2, 2020

It looks like you've made some changes to the code. For example, std::shared_ptr is a template class but you are not specifying any template arguments in the code example. It should be std::shared_ptr as can be seen here DX12Lib/src/Window.cpp#L188.

Sorry, I guess that was my mistake when trying to copy-paste the code and trying to get the code snippet to work. My code does have the template assigned.

`void Window::RegisterCallbacks(std::shared_ptr<Game arg_pGame)
{
m_pGame = arg_pGame;

return;

}
`
EDIT: I had to remove the ending angle brace for some reason, the code snippet tool omits that. The same is so in my original post.

Same goes for the class declarations as follows:

class Game : public std::enable_shared_from_this<Game> {

I tried changing the weak_ptr m_pGame to shared_ptr m_pGame, and commenting out the locks. but still, I get a similar error for Read Access violation.

Some of the ComPtr Objects are uninitialized at this point. Is that to be expected or have I bungled the code?

@safi-huss
Copy link
Author

I believe I made a grave error in the code. Apparently, my window initialization was incorrect and I was using invalid handles to the Window to initialize the rest of the code.

Thank you so much for bearing my ineptitude. And a million thanks for writing these tutorials!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants