Hello Sanat,

I was not able to understand this behavior:

When I had a vec3Array and I queried it using
vec3 = vec3Array->at(0) I would get an exception. Why does it give that 
exception ?

Check the C++ standard, osg::Vec3Array::at() eventually calls std::vector::at() which throws an exception when you try to access something that's past the end of the vector (i.e. not a valid index).

You would have seen this if you'd tried to debug the program. When debugging, when you get an exception, you can get the stack trace of where the exception was thrown and thus learn why you got an exception yourself.

I needed to use (*Vec3Array)[i] to get each Vec3.
But then at i = 14113, I got an Unhandled exception:
at 0x00402207 in OSG_examples.exe: 0xC0000005: Access violation reading 
location 0x00ba9000.
And size has a value much higher = 4176061468

when I query the vec3Array for size I get a very large number and much large than 
Vec3Array->numElements()
size = 4176061468       
numElements =   7772    
Which of these represents the number of vertices in the model ?

I strongly suspect you're acting on a variable that you've casted to Vec3Array without first checking whether it was really a Vec3Array.

As I said above, at() checks if the index you pass is valid or not. operator[] does not check, so you can do it even if it's not a valid index... Also the size you get is a value that I would question, seems to me that it's an invalid size as no one would ever make a model for real-time use that has 4 billion vertices. Again, you have your data, so this is something you could have checked by loading the same model in osgviewer, pressing 's' 4 times and looking at the number of vertices, I bet it's lower than 4 billion.

The number of vertices in the model is array->size(). And array->at() should always work if the index you pass is under array->size(). So if that's not the case, then you're using an area of memory that isn't the type you think it is, and you better check things better before you cast.

Again, please look at previous discussions, someone else was doing very unsafe things lately... You're not doing yourself a favor by casting things without checking and then wondering why you get errors...

Hope this helps,

J-S
--
______________________________________________________
Jean-Sebastien Guay    [email protected]
                               http://www.cm-labs.com/
                        http://whitestar02.webhop.org/
_______________________________________________
osg-users mailing list
[email protected]
http://lists.openscenegraph.org/listinfo.cgi/osg-users-openscenegraph.org

Reply via email to