Thread: Code crashing on runtime

  1. #1
    Registered User
    Join Date
    Nov 2012
    Posts
    7

    Code crashing on runtime

    Can someone take a look at why my code is crashing as soon as .exe come up but compiles fine?

    It is a program used to read all the height and depth info on earth from tbase.bin, and then convert it to display some info. Basicly, all depth and height info are stored as binary, and then in a 2d array that portrays a map of Earth. From it, you can get a bunch of info
    Attached Files Attached Files

  2. #2
    Registered User C_ntua's Avatar
    Join Date
    Jun 2008
    Posts
    1,853
    Did you try to use a debugger?

  3. #3
    Registered User
    Join Date
    Nov 2012
    Posts
    7
    yes i compiled and used a debugger. It didnt work
    It crashed when the .exe came up

  4. #4
    and the hat of int overfl Salem's Avatar
    Join Date
    Aug 2001
    Location
    The edge of the known universe
    Posts
    39,659
    > static const int rowNum = 2160;
    > static const int colNum = 4320;
    > double AVERAGE_LAT_DIST;
    > short array[rowNum][colNum];
    Did you do the maths to find out how big this array really is?

    I did - it's 18,662,400 bytes, if a short is 2 bytes on your machine.


    > EarthCalc trialone(5);
    This tries to create that massive array on the program stack.

    Given that on most operating systems, the default stack size is between 1MB and 8MB, you're blowing that away with the very first thing you do.

    Make your EarthCalc constructor allocate this array dynamically.
    If you dance barefoot on the broken glass of undefined behaviour, you've got to expect the occasional cut.
    If at first you don't succeed, try writing your phone number on the exam paper.

  5. #5
    Registered User
    Join Date
    Nov 2012
    Posts
    7
    Quote Originally Posted by Salem View Post
    > static const int rowNum = 2160;
    > static const int colNum = 4320;
    > double AVERAGE_LAT_DIST;
    > short array[rowNum][colNum];
    Did you do the maths to find out how big this array really is?

    I did - it's 18,662,400 bytes, if a short is 2 bytes on your machine.


    > EarthCalc trialone(5);
    This tries to create that massive array on the program stack.

    Given that on most operating systems, the default stack size is between 1MB and 8MB, you're blowing that away with the very first thing you do.

    Make your EarthCalc constructor allocate this array dynamically.
    oh ok, so I am assuming i should make a pointer and reference to that array instead? I did that calculation already and know its 18MB, i just never knew that the stack size is only 1MB to 8 MB lol

    but thanks, Ill give it a shot and post back results

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Can someone see why this is crashing at runtime?
    By Vic Webster Jnr in forum C++ Programming
    Replies: 5
    Last Post: 11-07-2012, 04:50 PM
  2. Compiled code crashing
    By cMacD in forum C Programming
    Replies: 7
    Last Post: 11-10-2011, 06:04 PM
  3. C code crashing question.
    By goflswl00 in forum C Programming
    Replies: 7
    Last Post: 05-31-2010, 08:44 PM
  4. crashing code
    By lambs4 in forum C Programming
    Replies: 2
    Last Post: 06-09-2003, 10:09 AM
  5. oops ! code crashing.. :(
    By Luigi in forum C++ Programming
    Replies: 9
    Last Post: 12-20-2002, 11:38 PM