• Announcements

    • khawk

      Download the Game Design and Indie Game Marketing Freebook   07/19/17

      GameDev.net and CRC Press have teamed up to bring a free ebook of content curated from top titles published by CRC Press. The freebook, Practices of Game Design & Indie Game Marketing, includes chapters from The Art of Game Design: A Book of Lenses, A Practical Guide to Indie Game Marketing, and An Architectural Approach to Level Design. The GameDev.net FreeBook is relevant to game designers, developers, and those interested in learning more about the challenges in game development. We know game development can be a tough discipline and business, so we picked several chapters from CRC Press titles that we thought would be of interest to you, the GameDev.net audience, in your journey to design, develop, and market your next game. The free ebook is available through CRC Press by clicking here. The Curated Books The Art of Game Design: A Book of Lenses, Second Edition, by Jesse Schell Presents 100+ sets of questions, or different lenses, for viewing a game’s design, encompassing diverse fields such as psychology, architecture, music, film, software engineering, theme park design, mathematics, anthropology, and more. Written by one of the world's top game designers, this book describes the deepest and most fundamental principles of game design, demonstrating how tactics used in board, card, and athletic games also work in video games. It provides practical instruction on creating world-class games that will be played again and again. View it here. A Practical Guide to Indie Game Marketing, by Joel Dreskin Marketing is an essential but too frequently overlooked or minimized component of the release plan for indie games. A Practical Guide to Indie Game Marketing provides you with the tools needed to build visibility and sell your indie games. With special focus on those developers with small budgets and limited staff and resources, this book is packed with tangible recommendations and techniques that you can put to use immediately. As a seasoned professional of the indie game arena, author Joel Dreskin gives you insight into practical, real-world experiences of marketing numerous successful games and also provides stories of the failures. View it here. An Architectural Approach to Level Design This is one of the first books to integrate architectural and spatial design theory with the field of level design. The book presents architectural techniques and theories for level designers to use in their own work. It connects architecture and level design in different ways that address the practical elements of how designers construct space and the experiential elements of how and why humans interact with this space. Throughout the text, readers learn skills for spatial layout, evoking emotion through gamespaces, and creating better levels through architectural theory. View it here. Learn more and download the ebook by clicking here. Did you know? GameDev.net and CRC Press also recently teamed up to bring GDNet+ Members up to a 20% discount on all CRC Press books. Learn more about this and other benefits here.
Sign in to follow this  
Followers 0
Conny14156

Access violation reading location question

10 posts in this topic

Edit:
I Solved it,
Instead of using a struct with XMMATRIX I now use a FLOAT4X4 Instead and just temporary send the value into the XMMATRIX to avoid this 16bit align problem .





Hi,
I was wondering that particular error could mean that my pointer points to a null and am trying to change something that doesn't have something to change right?
but what more could cause that error?

This code doesn't give any compiler error, and I checked with the debugger that "Transform" have "values" which should be changeable.</
<pre class="_prettyXprint _lang-auto _linenums:1">
TransformComponent* temp;
temp = dynamic_cast<TransformComponent*>(pHolder->ComponentList["TransformComponent"].get());
Transform = &temp->Transform;
Transform->LocalPosition = XMMatrixIdentity();
</pre>
Edited by Conny14156
0

Share this post


Link to post
Share on other sites

Access violation means you are reading from or writing to memory that has not been flagged as readable/writable, or are executing memory not flagged as executable.

This is not exclusive to NULL (address 0x00000000).

Addresses from 0x00000000 to 0x00010000 are always unreadable on Windows®.

 

So acting upon any pointer (more specifically, dereferencing any address), NULL or otherwise, which points to invalid addresses will cause access violation.

Executing code requires the address of the code to be flagged as “PAGE_EXECUTE*”—if not then it is an access violation.

 

One of the trickier cases to detect is stack overflow.  “Transform” may be just one address off the stack, and accessing it then gives access violation.

 

 

If you need more help you will need to post the actual line that is giving you this error and preferably a screenshot of what the debugger is showing you for your locals.

 

 

L. Spiro

Edited by L. Spiro
2

Share this post


Link to post
Share on other sites
If I remember correctly, dynamic_cast returns null if the expression cannot be cast to the intended type. I think you should step through this part of the code to figure out where exactly the access violation is occurring.
0

Share this post


Link to post
Share on other sites

Expending on that, the use of dynamic_cast is itself discouraged.  It tends to imply a design problem and always implies a performance problem as it comes with a ton of overhead.

I have personally never used it as there is always a better way.  To be honest, I am not sure I have actually met anyone in person who has used it either and I have never seen it in any production code I have never seen.

 

 

L. Spiro

Edited by L. Spiro
2

Share this post


Link to post
Share on other sites
Hm,I shall try to do this without using the dynamic cast and see if I can bypass this error >.< thanks for the input
fast edit if dynamic cast is should I try to avoid other casting to? Edited by Conny14156
0

Share this post


Link to post
Share on other sites

I followed you guys advice and I tested something else instead for the dynamic cast, and just used a "normal" casting well, its probably not much better but.

I tried to get what I needed from my class the same way I did with my camera class.

 

It kinda worked, I checked each line, and everything did as it should(from what I could see)

except I get the same error.

        TransformComponent* temp;
	Transformers* test;
	std::string testS;
        temp = (TransformComponent*) pHolder->ComponentList["TransformComponent"]->getMe();
	test = temp->getTransform();
	testS = temp->getTypeName(); 
	Transform->LocalPosition = XMMatrixIdentity();  <--- Doesnt work

 

 

The wierd thing is, the way I did this is exactly the same thing I did with my camera, 

I have a function that returns a pointer that points the the desired object

example, and it does indeed work, As I can see the value on my the debug value on "test"

but when I try to change something I get a access error, 

BUT

this is nearly identical to how my camera works, but with that I can change value with no problems.

Transformers* TransformComponent::getTransform()
{
	return &Transform;
}

 

 

The only big diffrent I can think of is that I get the raw pointer from a class object which reside inside a map that reside inside a vector like 

Am guessing this is a horrible way to do it as it probably wont allow me to change the inside value?


std::vector<std::shared_ptr<Entity>> vEntity;
 
void setHolder(Entity* _pHolder);
 
vEntity[0]->ComponentList["RenderComponent"]->setHolder(vEntity[0].get());
vEntity[0]->ComponentList["RenderComponent"]->Update(); 
 

 

 

 

 

 

0

Share this post


Link to post
Share on other sites

You said you confirmed that temp is valid. Have you stepped through your code and determined that Transform is valid before you try to modify it?

0

Share this post


Link to post
Share on other sites

Debug the original code and check the result of your dynamic_cast. If it returns 0, then you absolutely not replace it with a "normal" cast, because it means you probably have a pretty fundamental bug in your class hierarchy. Not using a safe dynamic_cast won't fix anything, it will simply hide the bug and turn it into a minefield of weird crashes (if you're lucky) and very obscure behavior (if you're not so lucky).

 

dynamic_cast returning 0 clearly tells you "sorry, but that object is not of the type you want". Using a dangerous brute force C cast says "I don't care, just pretend that it is". You then move on to access members that don't exist, execute random code or overwrite memory that belongs to something completely different.

 

The reason dynamic_cast is often considered "bad" is not the cast itself, but that your requirement to explicitly downcast at all hints at a problem with your design. IF you continue to downcast like that, you should at least keep the dynamic_cast until you decide to abstract things to the point where all your components can use a common interface (hint: directly reading/writing members like you do is not a good start to achieve that).

 

Basically I see three options:

 

a) downcast to a specific component and use a unique interface for each type

 

b) completely pollute the base class with tons of empty virtual functions

 

c) abstract things to the point of components handling generic messages

 

If you are only starting out with C++, it might be better not to try and implement a component based system yourself, because finding a path between "doing very ugly things" and "it's a pain to use and causes more problems than it solves" requires a good bit of experience.

0

Share this post


Link to post
Share on other sites

Is Transform->LocalPosition member aligned to 16-byte boundary? Afaik in 32-bit builds XMMatrixIdentity() returns XMMATRIX that should be aligned on 16-byte boundary - compiler in your code generates SSE store instruction that assumes it is aligned, and if it won't be aligned you'll get an exception.

0

Share this post


Link to post
Share on other sites
Yeha, I kinda expected that this will be hard >.<
But am required to do this for a few reasons.
either way :3
I dont get a error or a null with either of the typecast
It works
In the type I try to cast into have two variables I try to access one of them is a simple string, which I can change without any error whatsoever.
but the other one which is a struct that holds diffrent XMMATRIX doesnt seems to allow me to directly change them without giving me the access violation error. is there something special with just XMMATRIX?


Is Transform->LocalPosition member aligned to 16-byte boundary? Afaik in 32-bit builds XMMatrixIdentity() returns XMMATRIX that should be aligned on 16-byte boundary - compiler in your code generates SSE store instruction that assumes it is aligned, and if it won't be aligned you'll get an exception.

OH I missed yours post while sending my post >.<
Is Transform->LocalPosition member aligned to 16-byte boundary?
not sure what that mean really, gonna google it and see if I can learn something brb for another edit later Edited by Conny14156
0

Share this post


Link to post
Share on other sites

Put in your code (or inspect with debugger):

[code]printf("%p\n", &Transform->LocalPosition);[/code]

Printed address should divide with 16 without reminder.

0

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!


Register a new account

Sign in

Already have an account? Sign in here.


Sign In Now
Sign in to follow this  
Followers 0