Jump to content

  • Log In with Google      Sign In   
  • Create Account


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

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

#1 Prot   Members   -  Reputation: 330

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.

 



Sponsor:

#2 Prot   Members   -  Reputation: 330

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   Crossbones+   -  Reputation: 2765

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






PARTNERS