Crashes in Debug(random) but not release

Posted on 2005-04-12
Last Modified: 2013-11-20
eVC++ 4.0 Pocket PC using MFC, and IAnywhere

I have an issue when running in debug mode, the program will "crash" with
either the "data misalignment" or "access violation" errors.  When I run it
in release, everthing seems fine.  The other odd thing is that the place it
crashes in debug mode seems random.  Sometimes if I  execute a particular
line with
"F10", it will throw the exception.  The next time, if I hit "F5" past the
same line, or "F11" and step through it won't crash at all, or it will crash
in a different place.  If I change a piece of source code, recompile, and
run again, it will crash in a
different spot.  It seems like the executable file or maybe a library that I
am linking in is corrupt or misaligned when generating a debug build.  Is
this possible?  Has anyone seen anything similar?  Thanks.

Timothy Dean
Question by:kevinbenedict
    LVL 3

    Accepted Solution

    Check your struct member allignment. Is it set to default (8 Bytes)?

    Also, check for any #pragma's in your code.
    Something like
    #pragma pack 1
    or whatever?
    If you have this, remember to call #pragma pack without any numbers to reset the allignment.
    Check all of your libs that you're linking against. Make sure their allignment is set to 8 and that there are no packs.

    I have seen this behaviour before if the #pragma pack was invoked without it being released.

    Hope this helps,

    LVL 49

    Assisted Solution

    I agree with mactep13 and add generic advise:.
    o  Carefully compare all of your build settings -- Release to Debug.
    o  Do a complete clean and rebuild to eliminate some potential sources of problems.
    o  Since it is intermittant, also look for external causes -- such as timeouts caused by
        network traffic, disk full errors, and so forth

    One major *standard* difference between a Debug build and a Release build is that TRACE and ASSERTs are active in the former.  Also, in Debug builds, there is extra padding for the variables (it is often the removal of that padding that casue the opposite problem:  failures in Release build... I mention it for completeness only).

    -- Dan


    Author Comment

    My alignment is set to 8, and since I am using 3rd party libraries, I don't know how to check their libraries.  I didn't find any #pragma pack statements.  One thing to note is that I am using eVC++ on a PocketPC and debugging directly on the device.  

    Another thing I noticed at one point when calling a function with a
    parameter passed by value.  The parameter is passed as a contant string (ex:
    functionCall("SomeText")).  When looking at the constructor of the parameter
    object that takes the string, an invalid pointer arrives at the copy
    constructor.  Thats something I have no control over, right?  It is like the
    string table is corrupt at that point.

    I may try creating a new project with all new build settings to see if that works.  Thanks for the input.  Let me know if you have any other thoughts.


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    How to run any project with ease

    Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
    - Combine task lists, docs, spreadsheets, and chat in one
    - View and edit from mobile/offline
    - Cut down on emails

    Suggested Solutions

    Title # Comments Views Activity
    Running shell command from Access 3 59
    bigDiff challenge 17 57
    centeredAverage challenge 8 88
    isEverywhere  challenge 19 48
    This is to be the first in a series of articles demonstrating the development of a complete windows based application using the MFC classes.  I’ll try to keep each article focused on one (or a couple) of the tasks that one may meet.   Introductio…
    Introduction: Dynamic window placements and drawing on a form, simple usage of windows registry as a storage place for information. Continuing from the first article about sudoku.  There we have designed the application and put a lot of user int…
    This video will show you how to get GIT to work in Eclipse.   It will walk you through how to install the EGit plugin in eclipse and how to checkout an existing repository.
    This video discusses moving either the default database or any database to a new volume.

    759 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now