Skip to content

Fix psd load error on windows#425

Closed
fabiencastan wants to merge 1 commit into
AcademySoftwareFoundation:masterfrom
fabiencastan:master
Closed

Fix psd load error on windows#425
fabiencastan wants to merge 1 commit into
AcademySoftwareFoundation:masterfrom
fabiencastan:master

Conversation

@fabiencastan
Copy link
Copy Markdown
Contributor

On windows, ifstream::open does not guarantee to be at the beginning of
the file.

On windows, ifstream::open does not garantee to be at the beginning of
the file.
@lgritz
Copy link
Copy Markdown
Collaborator

lgritz commented Aug 23, 2012

Really? What are the circumstances in which something else happens?

@lgritz
Copy link
Copy Markdown
Collaborator

lgritz commented Aug 23, 2012

LGTM, by the way, I'm just curious about what's really going on here.

Also, do you need this backported to any release branches, or only the master?

@fabiencastan
Copy link
Copy Markdown
Contributor Author

Really? What are the circumstances in which something else happens?

No idea ! Just systematically reads values from anywhere when I load a psd on windows...

Also, do you need this backported to any release branches, or only the master?

Only master.
Thanks

@c42f
Copy link
Copy Markdown
Contributor

c42f commented Aug 23, 2012

Yikes, this one makes me uncomfortable. The behaviour that

std::ifstream file("blah")

reads from the beginning seems like very basic and important standard behaviour. Reading section 27.9.1.4 of the C++ standard http://www.open-std.org/jtc1/sc22/wg21/docs/papers/2012/n3376.pdf says that the underlying filebuf is opened as if by calling fopen() with mode "rb".

I too wonder what's really going on here...

@lgritz
Copy link
Copy Markdown
Collaborator

lgritz commented Aug 24, 2012

I'm uncomfortable with the weirdness of this, I'm worried we're just masking another problem.

Do you have a specific PSD file that can reproduce the problem? (Can you send it to me? Or does it have this problem for all PSD files?)

I think you should try this: instead of seeking, try instead checking and printing the current file position :

streampos pos = m_file.tellg();
if (pos != 0)
    std::cerr << "Weird, current position is " << pos << "\n";

Let us know what it prints. And if it never prints anything at all, then perhaps this is not the problem.

@fabiencastan
Copy link
Copy Markdown
Contributor Author

It's not specific to one psd file.

See the streampos before and after the manual seekg to 0.
http://static.inky.ws/image/2800/image.jpg

@fabiencastan
Copy link
Copy Markdown
Contributor Author

Does that answer your question?

@lgritz
Copy link
Copy Markdown
Collaborator

lgritz commented Sep 21, 2012

Sorry, the image appears to have no size for me. Can you just cut and paste the text?

@fabiencastan
Copy link
Copy Markdown
Contributor Author

Can't use your code directly as std::streampos is an implementation defined class.

//////////////////////////////////////////////////////
// ... m_file.open...
std::streampos pos1 = m_file.tellg();
m_file.seekg( 0, std::ios::beg );
std::streampos pos2 = m_file.tellg();
// ... load_header...
//////////////////////////////////////////////////////

Debug values:

pos1._Stz == 0
pos1._Myoff == -1
pos1._Fpos == 0
pos1._Mystate == 0

pos2._Stz == 0
pos2._Myoff == 0
pos2._Fpos == 0
pos2._Mystate == 0

@lgritz
Copy link
Copy Markdown
Collaborator

lgritz commented Sep 4, 2013

This patch is no longer necessary, since we have added the seek() to Filesystem::open, it happens automatically on Windows. Closing.

@lgritz lgritz closed this Sep 4, 2013
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants