Thread: 0xc0000005 error

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date
    Mar 2003
    Posts
    105

    0xc0000005 error

    Hi there!

    I have a problem which I can't really solve. I wrote a program (quite complicated one), which generates the mentioned 0xc0000005 error, upon starting the compiled exe, and says "failed to initialize properly".
    The weird thing is, that this happened after I began having trouble with the exit(0) command. Whenever I close my program not using the X button, I used this command to solve the problem. But this time (I don't know why) this command does NOT stop the program from running even though all the forms were destroyed.
    Can you help me with that? Did you have any problems like this in the past?
    I use Borland C++ Builder 5.0, and havent run into anything like this before.

    Thx guyz!
    Attila

  2. #2
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    THe error code itself means "you accessed memory you had no right to use", which covers a multitude of sins, usually involving pointers that are abused or arrays that aren't big enough, but other things too.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  3. #3
    Algorithm Dissector iMalc's Avatar
    Join Date
    Dec 2005
    Location
    New Zealand
    Posts
    6,318
    Quote Originally Posted by Hankyaku View Post
    I wrote a program (quite complicated one), which generates the mentioned 0xc0000005 error, upon starting the compiled exe, and says "failed to initialize properly".
    0xC0000005 is an access violation which is probably the most common bug symptom of all. It could be anything.

    Run the program in your debugger and tell the debugger to break upon an exception, or at least upon this type of exception.
    My homepage
    Advice: Take only as directed - If symptoms persist, please see your debugger

    Linus Torvalds: "But it clearly is the only right way. The fact that everybody else does it some other way only means that they are wrong"

  4. #4
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Thx, I suspected the same, and checked the arrays I'm using. They look okay. I avoid using pointers, so that shouldn't be a problem.

    And can you help me in determining why the exit(0); command does not work? Application->Free() however works (no matter how illegal it is).
    There surely is some memory issue, somehow Free is not called automatically. Have you run into anything like this?

    Thx again.

  5. #5
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    Most likely, exit(0) doesn't work because you've overwritten some other data that is needed for exit() to do it's job - nothing else.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  6. #6
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Quote Originally Posted by Hankyaku View Post
    Thx, I suspected the same, and checked the arrays I'm using. They look okay. I avoid using pointers, so that shouldn't be a problem.
    If you avoid using pointers, the most likely problem is falling off the end of an array. It is also possible you're doing something with I/O (eg fscanf() being supplied an int when it expects a double due to %f format specifier) that overwrites something you don't intend.
    Quote Originally Posted by Hankyaku View Post
    And can you help me in determining why the exit(0); command does not work? Application->Free() however works (no matter how illegal it is).
    There surely is some memory issue, somehow Free is not called automatically. Have you run into anything like this?
    Like matsp said, possibly a side effect of your other problem: your misbehaving code is tromping some memory that exit() needs to function.

  7. #7
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Thanks guys, I'll check that. I'm using a TeeChart in the software, that may cause some trouble. I'll begin //-ing my code and see what happens. Hell of a job at many forms and few thousand lines.

  8. #8
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    You may find that an easier way to comment out large chunks of code is to use
    Code:
    #if 0 
    // Many lines of code here. 
    #endif
    When you want to re-enable the code, all you need to do is change the zero to a non-zero value (e.g. 1).

    I quite often use:
    Code:
    #if 1
    // Do simple stuff
    #else
    // Do the REAL stuff
    #endif
    inside functions to remove parts of the code that I find suspicious of causing a problem. That's useful for example when the function is expected to return a value, and you need to fake success (or failuer) in the function - e.g. a form function may be replaced by a function that says "User clicked OK" and data left unchanged...

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

  9. #9
    Deathray Engineer MacGyver's Avatar
    Join Date
    Mar 2007
    Posts
    3,210
    Well, you know what the problem is: You're trashing memory somewhere.

    When you do that, the error isn't necessarily easy to find out. It depends upon what stupid thing you're doing to cause the problem and just when things come together to make the system barf because of it.

  10. #10
    Registered User
    Join Date
    Mar 2003
    Posts
    105

    Problem maybe solved... weird though.

    Hi!

    It seems that I've solved this issue. But I don't understand how it works. So please, if anybody of you can come up with any guess, please don't hesitate to share!!!

    It happened like this. I ran the compiled exe files on my pendrive in different directories, and I found that at a location it work, while it didn't work at the other one. I began filtering the system files (and abandoned the guess that XLSReadWrite does cause any trouble), and found that once I removed vcl50.bpl, and left vclx50.bpl in the directory of the exe, it worked! But as soon as I copied it back, it gave the initialization error.

    Now how weird is that? I'll run further test to check if this really was the problem, or my program called anything in this bpl I'll miss later on. But if you have any guesses, please share! (I don't really know much about this file at all...)

    Cheers!
    Han

  11. #11
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    vcl50.bpl is a library that contains basic GUI controls and vclx50.bpl contains some more rarely used controls (Checklst, Colorgrd, Ddeman, Filectrl, Mplayer, Outline, Tabnotbk, Tab) for an application built using C++ Builder 5. If required, they are usually statically linked in (and the associated error message at run time if you have problems with version of those, or if they don't exist, will be to the effect of a required library not found, not a pointer related error).

    I'd guess you actually have (at least) problems.

    1) In BCB, look at Project/Options. Under the linker tab, if you uncheck "Use Dynamic RTL" your executable will be statically linked and not require those libraries. It will create a larger executable though.

    2) I would still strongly suspect the real cause of your problem is still a pointer molestation or array overrun. The sensitivity to libraries is more likely a side-effect: by moving dynamic libraries around you will be changing minor things related to final memory layout when your executable is finally loaded, so the memory that is being tromped subtly changes and therefore the symptom changes.

  12. #12
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    Thanx for the info.
    The situation is sooo interesting. I say this because this error showed up only recently. Those applications I made earlier began producing this error messages recently.
    I didn't make any real modifications to them concerning pointer usage. Actually I don't even use pointers. I use arrays, but at an array index overflow I immediately get an exception. So that's why I was shocked.

  13. #13
    Registered User
    Join Date
    Jun 2005
    Posts
    6,815
    Array index overflow does not automatically give exceptions; such things, in practice, only happen in a specific set of circumstances.

    Probably all that's happened is that you made some small change in your program recently (eg addition of some new variables, or something, and operations on them). That would change the memory layout of your program. So the real culprit is having a different effect from what it did originally (i.e. becoming visible when it wasn't before).

    It is also possible you changed some data file used by your program, and that is affecting some critical data in a way you didn't anticipate. This is quite common if the process of reading your data involves allocation and deallocation of memory (eg clearing a dynamically allocated list and then growing it again to store new data).

  14. #14
    Registered User
    Join Date
    Mar 2003
    Posts
    105
    These are interesting.
    I mean of course I did insert new variables, and assigned some functions as well. But I use static arrays, and this makes such overflows (as far as I know) impossible, as if I try to write to them I'd run into exceptions upon programming, not only upon execution (since nothing changes, but in one case I compile&run&debug, and in the other I just run the exe).
    Is there anything in C builder which would make these kind of errors traceable during development? Is there a way I can monitor the memory usage of my program? I didn't really need to use advanced C builder features until now...

  15. #15
    Kernel hacker
    Join Date
    Jul 2007
    Location
    Farncombe, Surrey, England
    Posts
    15,677
    I wouldn't trust the compiler to always [or even often] detect out-of-bounds array accesses. The C language doesn't do that very well, and whilst the latest MS products do have some extensions to make an attempt, it's quite possible that you can get these things wrong and still execute for quite some time.

    --
    Mats
    Compilers can produce warnings - make the compiler programmers happy: Use them!
    Please don't PM me for help - and no, I don't do help over instant messengers.

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Getting an error with OpenGL: collect2: ld returned 1 exit status
    By Lorgon Jortle in forum C++ Programming
    Replies: 6
    Last Post: 05-08-2009, 08:18 PM
  2. An error is driving me nuts!
    By ulillillia in forum C Programming
    Replies: 5
    Last Post: 04-04-2009, 09:15 PM
  3. Making C DLL using MSVC++ 2005
    By chico1st in forum C Programming
    Replies: 26
    Last Post: 05-28-2008, 01:17 PM
  4. Connecting to a mysql server and querying problem
    By Diod in forum C++ Programming
    Replies: 8
    Last Post: 02-13-2006, 10:33 AM
  5. Couple C questions :)
    By Divx in forum C Programming
    Replies: 5
    Last Post: 01-28-2003, 01:10 AM