Jump to content
  • Advertisement
Sign in to follow this  
SamiHuutoniemi

Read/Write binary

This topic is 2139 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

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.

Share this post


Link to post
Share on other sites
Advertisement
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 &.

Share this post


Link to post
Share on other sites
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!