CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Page 1 of 2 12 LastLast
Results 1 to 15 of 19
  1. #1
    Join Date
    Jul 2006
    Posts
    8

    Unhandled exception: Access Violation 0xC00000005

    Hi all,
    I am getting this exception when i run a project in Visual c++ 6.0/

    Unhandled exception: Access Violation 0xC00000005

    The place of the code where this run time exception happens is

    and the img_width has a value 176 in it.

    if (input->img_width % 16 != 0)
    {
    img->auto_crop_right = 16-(input->img_width % 16);
    }
    else
    {
    img->auto_crop_right=0;
    }


    Can you tell me what is the probelm, It compiles and inks very well, but giving me a runtime exception?

    Thanks a lot

  2. #2
    Join Date
    Aug 2005
    Location
    Netherlands, The
    Posts
    2,184

    Re: Unhandled exception: Access Violation 0xC00000005

    its becuase img is not a valid object. can you show us the initialization of img?

  3. #3
    Join Date
    Aug 2005
    Location
    Netherlands, The
    Posts
    2,184

    Re: Unhandled exception: Access Violation 0xC00000005

    or input. either one of them

  4. #4
    Join Date
    Jul 2006
    Posts
    3

    Re: Unhandled exception: Access Violation 0xC00000005

    Quote Originally Posted by kannadaraj
    if (input->img_width % 16 != 0)
    {
    img->auto_crop_right = 16-(input->img_width % 16);
    }
    else
    {
    img->auto_crop_right=0;
    }
    use a breakpoint at input->img_width and check the object input as well as img. they might be invalid objects of which you are trying to get information of.

  5. #5
    Join Date
    Oct 2002
    Location
    Timisoara, Romania
    Posts
    14,360

    Re: Unhandled exception: Access Violation 0xC00000005

    See this FAQ.
    Marius Bancila
    Home Page
    My CodeGuru articles

    I do not offer technical support via PM or e-mail. Please use vbBulletin codes.

  6. #6
    Join Date
    Jul 2006
    Posts
    8

    Re: Unhandled exception: Access Violation 0xC00000005

    Hi all,

    This is the structure

    ImageParameters images, *img = &images;

    The auto_crop is somewhere in the bottom. Sorry this is a huge structure.

    //! ImageParameters
    typedef struct
    {
    int number; //!< current image number to be encoded
    int pn; //!< picture number
    int LevelIndex; //!< mapped level idc
    int current_mb_nr;
    int total_number_mb;
    int current_slice_nr;
    int type;
    int structure; //!< picture structure
    int num_ref_frames; //!< number of reference frames to be used
    int max_num_references;

    int qp; //!< quant for the current frame
    int qpsp; //!< quant for the prediction frame of SP-frame
    float framerate;
    int width; //!< Number of pels
    int width_cr; //!< Number of pels chroma
    int height; //!< Number of lines
    int height_cr; //!< Number of lines chroma
    int height_cr_frame; //!< Number of lines chroma frame
    int subblock_x; //!< current subblock horizontal
    int subblock_y; //!< current subblock vertical
    int is_intra_block;
    int is_v_block;
    int mb_y_upd;
    int mb_y_intra; //!< which GOB to intra code
    int block_c_x; //!< current block chroma vertical
    char **ipredmode; //!< intra prediction mode
    char **ipredmode8x8;

    int cod_counter;
    int ***nz_coeff;

    int mb_x; //!< current MB horizontal
    int mb_y; //!< current MB vertical
    int block_x; //!< current block horizontal
    int block_y; //!< current block vertical
    int pix_x; //!< current pixel horizontal
    int pix_y; //!< current pixel vertical
    int pix_c_x; //!< current pixel chroma horizontal
    int pix_c_y; //!< current pixel chroma vertical

    int opix_x; //!< current original picture pixel horizontal
    int opix_y; //!< current original picture pixel vertical
    int opix_c_x; //!< current original picture pixel chroma horizontal
    int opix_c_y; //!< current original picture pixel chroma vertical


    imgpel mprr[9][16][16];

    imgpel mprr_2[5][16][16]; //!< all 4 new intra prediction modes
    imgpel mprr_3[9][8][8]; //!< all 9 prediction modes for 8x8 transformation
    imgpel mprr_c[2][4][16][16]; //!< chroma intra prediction modes
    imgpel mpr[16][16]; //!< current best prediction mode
    int m7[16][16]; //!< the diff pixel values between orginal image and prediction

    int ****cofAC;
    int ***cofDC;
    int fadjust4x4[4][16][16];
    int fadjust8x8[3][16][16]; //!< Transform coefficients for 8x8 luma
    int fadjust4x4Cr[4][2][16][16];
    int fadjust8x8Cr[1][2][16][16];

    Picture *currentPicture;

    Slice *currentSlice;

    Macroblock *mb_data;
    SyntaxElement MB_SyntaxElements[MAX_SYMBOLS_PER_MB];

    int *quad;
    int *intra_block;

    int tr;
    int fld_type; //!< top or bottom field
    unsigned int fld_flag;
    unsigned int rd_pass;
    int direct_intraP_ref[4][4];
    int pstruct_next_P;
    int imgtr_next_P_frm;
    int imgtr_last_P_frm;
    int imgtr_next_P_fld;
    int imgtr_last_P_fld;

    // B pictures
    double b_interval;
    int p_interval;
    int b_frame_to_code;
    int fw_mb_mode;
    int bw_mb_mode;

    short****** pred_mv;
    short****** all_mv; //!< replaces local all_mv

    short****** bipred_mv1; //!< Biprediction MVs
    short****** bipred_mv2; //!< Biprediction MVs
    short bi_pred_me[MAXMODE];

    int LFDisableIdc;
    int LFAlphaC0Offset;
    int LFBetaOffset;

    int direct_spatial_mv_pred_flag; //!< Direct Mode type to be used (0: Temporal, 1: Spatial)

    int num_ref_idx_l0_active;
    int num_ref_idx_l1_active;

    int field_mode; //!< For MB level field/frame -- field mode on flag
    int top_field; //!< For MB level field/frame -- top field flag
    int mvscale[6][MAX_REFERENCE_PICTURES];
    int buf_cycle;
    int i16offset;

    int layer; //!< which layer this picture belonged to
    int old_layer; //!< old layer number
    int NoResidueDirect;
    int AdaptiveRounding; //!< Adaptive Rounding parameter based on JVT-N011

    int redundant_pic_cnt; // JVT-D101

    int MbaffFrameFlag; //!< indicates frame with mb aff coding


    unsigned int pic_order_cnt_type;
    // for poc mode 0, POC200301
    // unsigned int log2_max_pic_order_cnt_lsb_minus4;
    // for poc mode 1, POC200301
    unsigned int delta_pic_order_always_zero_flag;
    int offset_for_non_ref_pic;
    int offset_for_top_to_bottom_field;
    unsigned int num_ref_frames_in_pic_order_cnt_cycle;
    int offset_for_ref_frame[1]; // MAX_LENGTH_POC_CYCLE in decoder

    unsigned int pic_order_cnt_lsb;
    int delta_pic_order_cnt_bottom;

    int delta_pic_order_cnt[2];


    // POC200301
    unsigned int field_picture;
    signed int toppoc; //!< poc for this frame or field
    signed int bottompoc; //!< for completeness - poc of bottom field of a frame (always = poc+1)
    signed int framepoc; //!< min (toppoc, bottompoc)
    signed int ThisPOC; //!< current picture POC
    unsigned int frame_num; //!< frame_num for this frame

    unsigned PicWidthInMbs;
    unsigned PicHeightInMapUnits;
    unsigned FrameHeightInMbs;
    unsigned PicHeightInMbs;
    unsigned PicSizeInMbs;
    unsigned FrameSizeInMbs;

    int nal_reference_idc;

    int adaptive_ref_pic_buffering_flag;
    int no_output_of_prior_pics_flag;
    int long_term_reference_flag;

    DecRefPicMarking_t *dec_ref_pic_marking_buffer;

    int model_number;


    /*rate control*/
    int NumberofHeaderBits;
    int NumberofTextureBits;
    int NumberofBasicUnitHeaderBits;
    int NumberofBasicUnitTextureBits;
    double TotalMADBasicUnit;
    int NumberofMBTextureBits;
    int NumberofMBHeaderBits;
    int NumberofCodedBFrame;
    int NumberofCodedPFrame;
    int NumberofGOP;
    int TotalQpforPPicture;
    int NumberofPPicture;
    double *MADofMB;
    int BasicUnitQP;
    int TopFieldFlag;
    int FieldControl;
    int FieldFrame;
    int Frame_Total_Number_MB;
    int IFLAG;
    int NumberofCodedMacroBlocks;
    int BasicUnit;
    int write_macroblock;
    int bot_MB;
    int write_macroblock_frame;

    int DeblockCall;

    int last_pic_bottom_field;
    int last_has_mmco_5;
    int pre_frame_num;

    int slice_group_change_cycle;

    int pic_unit_size_on_disk;
    int bitdepth_luma;
    int bitdepth_chroma;
    int bitdepth_luma_qp_scale;
    int bitdepth_chroma_qp_scale;
    int bitdepth_lambda_scale;
    // Lagrangian Parameters
    double lambda_md[10][52]; //!< Mode decision Lambda
    double lambda_me[10][52]; //!< Motion Estimation Lambda
    int lambda_mf[10][52]; //!< Integer formatted Motion Estimation Lambda

    unsigned int dc_pred_value; //!< value for DC prediction (depends on pel bit depth)
    int max_imgpel_value; //!< max value that one picture element (pixel) can take (depends on pic_unit_bitdepth)
    int max_imgpel_value_uv;

    int num_blk8x8_uv;
    int num_cdc_coeff;
    int yuv_format;
    int lossless_qpprime_flag;
    int mb_cr_size_x;
    int mb_cr_size_y;

    int chroma_qp_offset[2]; //!< offset for qp for chroma [0-Cb, 1-Cr]

    // Residue Color Transform
    int residue_transform_flag;

    int auto_crop_right;
    int auto_crop_bottom;

    short checkref;
    int last_valid_reference;


    int bytes_in_picture;
    } ImageParameters;

    I didnot understand what needs to be done.

    Can you explain it once again.

    Thanks

    regards

  7. #7
    Join Date
    Jul 2006
    Posts
    8

    Re: Unhandled exception: Access Violation 0xC00000005

    The exception occurs when the code executes the else part.

    ie.
    else
    {
    img->auto_crop_right=0;
    }


    regards

  8. #8

    Re: Unhandled exception: Access Violation 0xC00000005

    couple of things to try.

    1) wrap it in try/catch
    try
    {
    // your code
    }
    catch(CException* e)
    {
    e->ReportError();
    e->Delete();
    }

    2) since the class is quite large in terms of storage, I wonder if you're somehow running out of stack. Is your exception happening in a function in which the object is passed in? try adding /F0x200000 (or something bigger, perhaps) to settings->c/c++->Project options.

  9. #9
    Join Date
    Aug 2004
    Location
    Bucharest, Romania... sometimes
    Posts
    1,039

    Re: Unhandled exception: Access Violation 0xC00000005

    Quote Originally Posted by SLCDJM
    couple of things to try.

    1) wrap it in try/catch
    try
    {
    // your code
    }
    catch(CException* e)
    {
    e->ReportError();
    e->Delete();
    }

    2) since the class is quite large in terms of storage, I wonder if you're somehow running out of stack. Is your exception happening in a function in which the object is passed in? try adding /F0x200000 (or something bigger, perhaps) to settings->c/c++->Project options.
    Using a try-catch might be helpful, but won't fix the bug! And shouldn't be a stack overflow since the error code for STACK_OVERFLOW is 0xC00000FD, not ACCESS_DENIED (0xC0000005)
    Bogdan Apostol
    ESRI Developer Network

    Compilers demystified - Function pointers in Visual Basic 6.0
    Enables the use of function pointers in VB6 and shows how to embed native code in a VB application.

    Customize your R2H
    The unofficial board dedicated to ASUS R2H UMPC owners.

  10. #10

    Re: Unhandled exception: Access Violation 0xC00000005

    Quote Originally Posted by Bornish
    Using a try-catch might be helpful, but won't fix the bug!
    1) The e->ReportError() may give some additional information.
    2) it's good programming practice to catch assertions wherever you can
    3) I never said it would "fix" the bug

    Quote Originally Posted by Bornish
    And shouldn't be a stack overflow since the error code for STACK_OVERFLOW is 0xC00000FD, not ACCESS_DENIED (0xC0000005)
    Yeah, and MSVC is *always* right in giving clear, concise and correct error messages...

  11. #11
    Join Date
    Mar 2003
    Location
    India {Mumbai};
    Posts
    3,871

    Re: Unhandled exception: Access Violation 0xC00000005

    CException??
    This is intended only for MFC, and TRY..CATCH..END_CATCH is needed to catch CException objects.
    Use catch(...) instead.

    Kanna, why don't you try to put ASSERT statements for 'img' object; or use step by step debuggin itself?
    Last edited by Ajay Vijay; July 23rd, 2006 at 05:13 AM.
    My latest article: Explicating the new C++ standard (C++0x)

    Do rate the posts you find useful.

  12. #12
    Join Date
    Aug 2004
    Location
    Bucharest, Romania... sometimes
    Posts
    1,039

    Re: Unhandled exception: Access Violation 0xC00000005

    Quote Originally Posted by SLCDJM
    1) The e->ReportError() may give some additional information.
    2) it's good programming practice to catch assertions wherever you can
    3) I never said it would "fix" the bug


    Yeah, and MSVC is *always* right in giving clear, concise and correct error messages...
    Re your reply:
    1. Useful info about 0xC0000005 would be:
    - type of access denied (when reading or writting?)
    - memory address with no access rights
    - callstack of the thread that generated the exception
    So, which is the additional info given by e->ReportError()?
    2. Exceptions and assertions aren't the same thing! Assertions could prove useful in debugging code. Try-catch blocks aren't catching assertions. Moreover, excessive use of try-catch blocks are not recommended... and I'd rather not use an exception handler ('cause basically are local handlers) that doesn't handle an exception, but instead reports an unhandled exception. It would suffice to install a global handler that describes and reports all exceptions of that thread. I would prefer to write code that properly handles all possible situations in a robust manner.
    3. What I meant was to "help" fix the bug, not fix it!

    ... and, Yeah,... MSVC has nothing to do with reporting 0xC0000005 instead of 0xC00000FD. If you'd know more about exception handling, you'd realize that STACK_OVERFLOW (0xC00000FD) exception is "raised" by the OS, not by your application, which means MSVC has nothing to do with it. What I mean is that threads' stacks are maintained by the OS by protecting the last committed page, and when the maximum size of the stack allowed (in that process) is reached, it will refuse to commit more and raise exception 0xC00000FD. If your application doesn't have a handler that repaires the stack (by reprotecting the last page) and resumes execution properly, or does not terminate that thread and resumes thread's execution on an unprotected stack, then you'll see a new exception, but this time it will be ACCESS_DENIED (0xC0000005) because a page which isn't committed will be hit. So, in order to see ACCESS_DENIED in a stack overflow situation, you'll first see a STACK_OVERFLOW exception that wasn't properly handled. Else, it simply is an exception that means "access denied", and is much more probable to be caused by a "bad pointer / reference" (uninitialized, deallocated, corrupted, ... ).

    // and again, just my 2 cents; please don't feel offended by my oppinion

    Best regards,
    Bogdan Apostol
    ESRI Developer Network

    Compilers demystified - Function pointers in Visual Basic 6.0
    Enables the use of function pointers in VB6 and shows how to embed native code in a VB application.

    Customize your R2H
    The unofficial board dedicated to ASUS R2H UMPC owners.

  13. #13
    Join Date
    Jul 2006
    Posts
    8

    Re: Unhandled exception: Access Violation 0xC00000005

    Dear Bornish,

    So what you are trying to imply is that in my code there has been a bad pointer or reference which might have been
    1. Not iniatilized properly
    2. Deallocated
    3. Corrupted.

    How do I solve each case.

    Thanks

    regards

  14. #14
    Join Date
    Jul 2006
    Posts
    8

    Re: Unhandled exception: Access Violation 0xC00000005

    Hi all,

    I found that I get this execption now in a different place of the code.


    int get_mem2Dshort(short ***array2D, int rows, int columns)
    {
    int i;

    if((*array2D = (short**)calloc(rows, sizeof(short*))) == NULL)
    no_mem_exit("get_mem2Dshort: array2D");
    if(((*array2D)[0] = (short* )calloc(rows*columns,sizeof(short ))) == NULL)
    no_mem_exit("get_mem2Dshort: array2D");

    for(i=1 ; i<rows ; i++)
    (*array2D)[i] = (*array2D)[i-1] + columns ;

    return rows*columns*sizeof(short);
    }

    when this part of the code is executed for the 16th time, as this function has to be called say 36 times.
    The place where i get the exception is during the execution of the first if statement.

    I would like to also tell you the overall set up of my workspace.

    I have two projects
    1. Decoder
    2. Encoder

    THis entire set up works without a problem when i run each project indivijually. What I have done is I am executing these two projects (1 and 2) simultaneously, i.e I am calling these two projects from a third project. As I mentioned there is no compilation of linking error.

    This is the same exception I am getting now in a different place, does it give some kind of clue as to why the exception is occuring.

    Thanks for all the help you can provide

    regards

  15. #15
    Join Date
    Aug 2004
    Location
    Bucharest, Romania... sometimes
    Posts
    1,039

    Re: Unhandled exception: Access Violation 0xC00000005

    If you found 0xC0000005 exception in random places of your code, it might be caused by a heap corruption (one of those things I mentioned in my previous posts). One usual reason for heap corruption is a buffer overrun. Another usual reason is unsafe casting of pointers. Can be much more reasons. They vary depending on the complexity and environment. It seems that I can only wish you luck with finding your bug, and hope you learn from it! I think we all learn best from our own mistakes.
    Regards,
    Bogdan Apostol
    ESRI Developer Network

    Compilers demystified - Function pointers in Visual Basic 6.0
    Enables the use of function pointers in VB6 and shows how to embed native code in a VB application.

    Customize your R2H
    The unofficial board dedicated to ASUS R2H UMPC owners.

Page 1 of 2 12 LastLast

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured