[Solved]How to prevent this crash?
-
In my code, at a certain line I have this condition:
@if(imageData->myImage==NULL)
{
...
}
@However, my code crashes at the "if" line for a certain reason. It gives "read access violation" error. When I debug the code, I see in the locals and expressions that the value of the "imageData->myImage" is Memory access error. Could you please how I can put an if condition where I check if the memory is reachable for this variable or not?
What I want to do is:@if(imageData->myImage== "Condition for memory access error")
{
...
}
@Thanks.
-
Hi and welcome to DevNet.
Did you check that imageData is a valid pointer ?
-
Your myImage is probably declared as private, hence it's not accesible. Either make it public, or use a getter to get the pointer. Then the pointer == NULL will work (make sure you explicitly set it to null in the constructor or somewhere. Pointers, just like variables in c++, are not automatically initialised to 0).
-
[quote author="SGaist" date="1363868284"]Hi and welcome to DevNet.
Did you check that imageData is a valid pointer ?[/quote]
How can I check it?
[quote author="sierdzio" date="1363868421"]Your myImage is probably declared as private, hence it's not accesible. Either make it public, or use a getter to get the pointer. Then the pointer == NULL will work (make sure you explicitly set it to null in the constructor or somewhere. Pointers, just like variables in c++, are not automatically initialised to 0).[/quote]
It's not declared as private. The code runs perfect for some time & passes million times over this line but it crashes there fore some reason.
-
Ah, ok. Then check for validity of imageData before using it:
@
if (imageData && imageData->myImage==NULL) {
...
}
@ -
As sierdzio said: check for imageData == NULL before doing imageData->myImage == NULL
-
Edit your initial post and add "[Solved]". I've already tagged it for you.
-
You're welcome
Simply edit the thread title and add [Solved]
-
Hehe, yes it would seem so :)