Jump to content

  • Log In with Google      Sign In   
  • Create Account


Read/Write binary


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
3 replies to this topic

#1 SamiHuutoniemi   Members   -  Reputation: 259

Like
0Likes
Like

Posted 06 December 2012 - 07:22 AM

Hello!

Instead of reading a model from a huge obj-file (21 mb) I made a simple binary format which i wrote data to. But when I try to read it I get problems. It happens when I want to read an array of vertices. I get an access violation on the read line.

[source lang="cpp"]vertices = new TextureVertex[numVertices];buffer.read((char*) &vertices, sizeof(TextureVertex) * numVertices);[/source]
The value of numVertices is 10920, and the data IS in the stream I read from.

Is it possible that the memory that is allocated to vertices is not sequential? If it isnt, how do I force it to be? Is it something else?

(The data is read from an object which also has a "TextureVertex* vertices" of the same length.

Sponsor:

#2 wqking   Members   -  Reputation: 756

Like
5Likes
Like

Posted 06 December 2012 - 07:27 AM


vertices = new TextureVertex[numVertices];
buffer.read((char*) vertices, sizeof(TextureVertex) * numVertices);

No &, because vertics is already the address.

http://www.cpgf.org/
cpgf library -- free C++ open source library for reflection, serialization, script binding, callbacks, and meta data for OpenGL Box2D, SFML and Irrlicht.
v1.5.5 was released. Now supports tween and timeline for ease animation.


#3 Brother Bob   Moderators   -  Reputation: 7787

Like
4Likes
Like

Posted 06 December 2012 - 07:32 AM

vertices is the pointer to the buffer returned by new, but &vertices is a pointer to the value of the vertices pointer. You want to read into the buffer, not overwrite the pointer value returned by new, so drop the &.

#4 SamiHuutoniemi   Members   -  Reputation: 259

Like
2Likes
Like

Posted 06 December 2012 - 07:32 AM

Never mind.

I solved it. Sinces vertices was already a pointer, I shouldnt have used "vertices" instead of "&vertices".

/Facedesk

EDIT: I see you solved it too! Thanks for the help. Sometimes one just feels really stupid. And I blame my copy/paste! :D

Edited by SamiHuutoniemi, 06 December 2012 - 07:33 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS