• Advertisement
Sign in to follow this  

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

This topic is 1250 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

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.

 

Share this post


Link to post
Share on other sites
Advertisement

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

Share this post


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

Share this post


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

  • Advertisement