Take the 2-minute tour ×
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(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

closed as off-topic by Josh Petrie Jan 2 '14 at 18:00

This question appears to be off-topic. The users who voted to close gave this specific reason:

  • "Programming questions that aren't specific to game development are off-topic here, but can be asked on Stack Overflow. A good rule of thumb is to ask yourself "would a professional game developer give me a better/different/more specific answer to this question than other programmers?"" – Josh Petrie
If this question can be reworded to fit the rules in the help center, please edit the 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

Browse other questions tagged or ask your own question.