Tell me more ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

I'm writing a MIDI file loader. Everything is going fine until at some track I get a failbit exception while trying to read from file. I can't figure out why, I've checked the file size and it's ok too.

Upon checking "errno" and it returns "0".

Any ideas? Thanks.

The snippet follows:

file.read(reinterpret_cast<char*>(&mHeader.id), sizeof(MidiHeader));

mTracks = new MidiTrack[mHeader.nTracks];
for (uint i = 0; i < mHeader.nTracks; ++i)
{
    // this read fails on 6th i. I've checked hexadecimal file and it's
    // ok so far. 
    file.read(reinterpret_cast<char*>(&mTracks[i].id), sizeof(uint));
    if (file.fail())
    {
        std::cerr << errno << std::endl;
        massert(false);
    }
    massert(mTracks[i].id == 0x6B72544D);

    file.read(reinterpret_cast<char*>(&mTracks[i].size), sizeof(uint));
    mTracks[i].size = swapBytes(mTracks[i].size);

    mTracks[i].data = new char[mTracks[i].size];
    file.read(mTracks[i].data, mTracks[i].size * sizeof(char));

    totalBytesRead += 8 + mTracks[i].size;
    massert(totalBytesRead <= fileSize);
}
share|improve this question
Is this gamedev related? – nathan Sep 28 '12 at 16:07
@nathan As far as I'm concerned games do have sound processing, don't they? and yes, this is for a rhythm game. They usually load guitar and vocal charts as midis. – felipedrl Sep 28 '12 at 16:25
For programming questions, see the faq. Specifically, programming questions are on topic if a game programmer would give a better answer than a general programmer. This just seems to be a file loading issue and not game specific. – Tetrad Sep 28 '12 at 20:26

Know someone who can answer? Share a link to this question via email, Google+, Twitter, or Facebook.

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Browse other questions tagged or ask your own question.