Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3213658
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 17, 20262026-05-17T14:58:12+00:00 2026-05-17T14:58:12+00:00

I’m a fairly new programmer, but I consider my google-fu quite competent and I’ve

  • 0

I’m a fairly new programmer, but I consider my google-fu quite competent and I’ve spent several hours searching.

I’ve got a simple SDL application that reads from a binary file (2 bytes as a magic number, then 5 bytes per “tile”)
it then displays each tile in the buffer, the bytes decide the x,y,id,passability and such.
So it’s just level loading really.

It runs fine on any windows computer (tested windows server 2008, 7/64 and 7/32)
but when I compile it on linux, it displays random tiles in random positions.
I’d be tempted to say it’s reading from the wrong portion in the RAM, but I implimented the magic number so it’d return an error if the first 2 bytes were out.

I’d love to figure this out myself but it’s bugging me to hell now and I can’t progress much further with it unless I can program on the move (my laptop runs linux).
I’m using G++ on linux, mingw32g++ on windows.

bool loadlevel(int level_number)
{
    int length;
    std::string filename;
    filename = "Levels/level";
    filename += level_number+48;
    filename += ".lvl";
    std::ifstream level;
    level.open(filename.c_str(),std::ios::in|std::ios::binary);
    level.seekg(0,std::ios::end);
    length = level.tellg();
    level.seekg(0,std::ios::beg);
    char buffer[length];
    level.read(buffer,length);
    if (buffer[0] == 0x49 && buffer[1] == 0x14)
    {
        char tile_buffer[BYTES_PER_TILE];
        int buffer_place = 1;
        while(buffer_place < length)
        {
            for (int i = 1;i <= BYTES_PER_TILE;i++)
            {
                tile_buffer[i] = buffer[buffer_place+1];
                buffer_place++;
            }
            apply_surface(tile_buffer[1],tile_buffer[2],tiles,screen,&clip[tile_buffer[3]]);
        }
    }
    else
    {
        // File is invalid
        return false;
    }
    level.close();
    return true;
}

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-17T14:58:13+00:00Added an answer on May 17, 2026 at 2:58 pm

    Your array handling is incorrect.
    Array indexing in C/C++ begins from 0.

    You have defined ’tile_buffer’ to be an array sized ‘BYTES_PER_TILE’.
    If BYTES_PER_TILE was 5, your array would have elements tile_buffer[0] to tile_buffer[4].

    In your inner for-loop you loop from 1 to 5 so a buffer overflow will occur.

    I don’t know if this is the cause of your problem but it certainly won’t help matters.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Seemingly simple, but I cannot find anything relevant on the web. What is the
I'm making a simple page using Google Maps API 3. My first. One marker
link Im having trouble converting the html entites into html characters, (&# 8217;) i
I have just tried to save a simple *.rtf file with some websites and
I want to count how many characters a certain string has in PHP, but
I have a jquery bug and I've been looking for hours now, I can't
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I've got a string that has curly quotes in it. I'd like to replace
I have a French site that I want to parse, but am running into
I want use html5's new tag to play a wav file (currently only supported

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.