• 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
m4gnus

ofstream.write() doesn't write anything

6 posts in this topic

The topic pretty much sums it up. In my exporter i have a line which *should* write all the vertices to a file but when i remove the ofstream::write call the output file gets even larger! the pointer i pass to the function is 0x27666470(looks ok to me), my vertexsize is 56 an the vertexcount is 2222. But the file is just 68 bytes big(which is little more than 1 vertex! How can this be possible? the file opened okay(it is created) but still he doesn't want to write the vertices. My code: vertex writing code
std::cerr<<"Final Vertex Count:"<<vertCount<<std::endl; //returns 2222
				std::cerr<<"Vertex Size:"<<sizeof(complVertex)<<std::endl; //returns 56
				std::cerr<<"VertexPointer addresse:"<<pVerts<<std::endl; //returns 27666470
				ofs.write(reinterpret_cast<char*>(pVerts),sizeof(complVertex)*vertCount); //when i make this line a comment the size of the file gets 20bytes bigger( 88bytes )


all file writing code:
				//vertices:
				std::ofstream ofs(filepath.asChar(),std::ios::out | std::ios::binary);
				VertexChunkHeader.dwNumVertices=DWORD(vertCount);
				ofs.write(reinterpret_cast<char *>(&VertHeader),sizeof(VertHeader));
				ofs.write(reinterpret_cast<char *>(&VertexChunkHeader),sizeof(VertexChunkHeader));
				ofs.write(reinterpret_cast<char*>(&desc[0]),sizeof(ngVertexDesc)*numDesc);

				std::cerr<<"Final Vertex Count:"<<vertCount<<std::endl;
				std::cerr<<"Vertex Size:"<<sizeof(complVertex)<<std::endl;
				std::cerr<<"VertexPointer addresse:"<<pVerts<<std::endl;
				ofs.write(reinterpret_cast<char*>(pVerts),sizeof(complVertex)*vertCount); //<--the strange line


				//indices:
				IndexChunkHeader.dwNumIndices=indexCount;
				std::cerr<<"Final Index Count:"<<indexCount<<std::endl;
				IndHeader.dwDataSize=sizeof(IndexChunkHeader)+IndexChunkHeader.dwNumIndices*sizeof(int);
				ofs.write(reinterpret_cast<char *>(&IndHeader),sizeof(IndHeader));
				ofs.write(reinterpret_cast<char *>(&IndexChunkHeader),sizeof(IndexChunkHeader));

				ofs.write(reinterpret_cast<char*>(pIndices),sizeof(int)*indexCount);

				
				//for(int l=0;l<VertexIndices.size();l++) {
				//std::vector<short>::pointer ptr = &VertexIndices[0];
				//ofs.write(reinterpret_cast<char *>(ptr),sizeof(int)*VertexIndices.size());
				//std::vector<short>::pointer ptr2 = &UVIndices[0];
				//ofs.write(reinterpret_cast<char *>(ptr2),sizeof(int)*UVIndices.size());

		
				ofs.close();


the only reason for the file getting smaller i could think of is that the rest of the data which should be written to the file after the vertices isn't processed. So is there some way to "break" the file so that no more data can be written to it? Can somebody explain me how this is possible? regards, m4gnus [Edited by - m4gnus on June 9, 2006 6:47:19 AM]
0

Share this post


Link to post
Share on other sites
Did you forget to open the file in binary mode, such that an EOF character (Ctrl-Z, ascii 26 on Windows; Ctrl-D, ascii 4 on Unix) which happens to compose part of the binary vertex representation gets interpreted as the actual end of file?
0

Share this post


Link to post
Share on other sites
You might try checking the status of ofs after each write. It is possible that an error is ocurring that causes the ofs object to become bad. The fact that nothing gets written to the file after the attempt to write pVerts would seem to point to an error ocurring in that write call.
0

Share this post


Link to post
Share on other sites

thanks for the replies
Quote:

pVerts is 1D array complVertex structure?

yes
it's a pointer to the first element of a std::vector<complVertex>.

Quote:

Did you forget to open the file in binary mode, such that an EOF character (Ctrl-Z, ascii 26 on Windows; Ctrl-D, ascii 4 on Unix) which happens to compose part of the binary vertex representation gets interpreted as the actual end of file?

don't think so. the ofstream is opened with:
std::ofstream ofs(filepath.asChar(),std::ios::out | std::ios::binary);

Quote:

You might try checking the status of ofs after each write. It is possible that an error is ocurring that causes the ofs object to become bad. The fact that nothing gets written to the file after the attempt to write pVerts would seem to point to an error ocurring in that write call.

just checked. Yes the file get's bad. What can cause that? Maybe there something wrong with getting the pointer(it's a little more complex than just a pointer to a vector in the same scope).

I have a function which computes uv coordinates,tangents and binormals for every vertex and it's ouput is 2 pointers and 2 ints. one pointer for the vertexindices,one for the vertices itself,1 int for the indices count and 1 int for the vertices count.
To output those i need to pass a double pointer to the function like this:
createVertices(/*other parameters*/,complVertex **ppOutVerts,int **ppOutIndices,int *numVerts,int *numIndice);

and in the function i do:
(*ppOutVerts)=&vertices[0];
(*numVerts)=vertices.size();

(*ppOutIndices)=&complIndices[0];
(*numIndice)=complIndices.size();

and call it like this:
complVertex *pVerts;
int *pIndices;
int vertCount,indexCount; createVertices(/*parameters*/,&pVerts,&vertCount,&pIndices,&indexCount);

is that correct?

regards,
m4gnus
0

Share this post


Link to post
Share on other sites
Quote:
Original post by m4gnus
...
and in the function i do:
(*ppOutVerts)=&vertices[0];
(*numVerts)=vertices.size();

(*ppOutIndices)=&complIndices[0];
(*numIndice)=complIndices.size();


Are vertices and complIndices local variables to that function? If so, then when you go to output them those pointers will be invalid.
0

Share this post


Link to post
Share on other sites
Quote:

Are vertices and complIndices local variables to that function? If so, then when you go to output them those pointers will be invalid.

they are!
But how do i solve that? i want to be able to call that function more than once without problems(so moving the declaration of the vectors above the function isn't an option).
Should i declare them static?

Edit: ok declared them static now and the exporter works like a charm.
Thank you!

regards,
m4gnus

[Edited by - m4gnus on June 10, 2006 2:05:16 PM]
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