Jump to content

View more

Image of the Day

#ld38 #screenshotsaturday Mimosa Fizz action gif #2 https://t.co/TUzdppvfUL
IOTD | Top Screenshots

The latest, straight to your Inbox.

Subscribe to GameDev.net Direct to receive the latest updates and exclusive content.


Sign up now

Why does this code fail to read Blender's .obj file?

4: Adsense

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
2 replies to this topic

#1 Prot   Members   

541
Like
0Likes
Like

Posted 22 August 2014 - 06:38 AM

Hi I am trying to read a Wavefront file which was created using Blender. I put a copy of this file into the solution Explorer. When I tried to compile for the first time I got the following message:

 

fatal error LNK1107: invalid or corrupt file: cannot read at 0x...

 

 

It seemed like the compiler confused Blender's .obj files with some other format which also uses the .obj ending. The solution was to exclude the file from the build process in its properties.

fatal error LNK1107: invalid or corrupt file: cannot read at 0x...

Now the application does compile but there is no data displayed like I would expect it. Not sure if this is a code issue.

#include "stdafx.h"
#include <iostream>
#include <stdlib.h>
#include <fstream>
#include <string>
using namespace std;

void ReadPrintFile(string _fileName)
{
std::string line;
std::ifstream fileStream (_fileName); 

if (fileStream.is_open())
{
while (getline(fileStream,line))
{
cout << line << '\n';
}
fileStream.close();
}
else
{
cout << "Unable to read file";
}
}

int _tmain(int argc, _TCHAR* argv[])
{

ReadPrintFile("Drone.obj");
std::cin.get();

return 0;
}

The code does not jump into the else statement. The filestream simply seems to be empty and I am directly forwarded to the cin.get(); statement. I know that there are tons of tutorials on how to parse .OBJ in C++ but I want to understand.

 



#2 Prot   Members   

541
Like
0Likes
Like

Posted 22 August 2014 - 07:45 AM

The trick was not to copy the file into the solution explorer but into the project folder.



#3 Nik02   Members   

4299
Like
0Likes
Like

Posted 22 August 2014 - 07:42 PM

Obj is the file extension for compiled modules (such as individual c or cpp files). The linker combines these to form the executable.

Niko Suni





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.