Author Topic: Only runs in debug mode  (Read 9734 times)

Offline purpleyouko

  • Single posting newcomer
  • *
  • Posts: 3
Only runs in debug mode
« on: May 23, 2012, 05:01:21 pm »
i have a strange problem with a project.

It compiles fine but when I run it from the executable it crashes in a very strange place.
First it fails to alocate memory for some of my variables then after trying (and failing) to load data from about 4 different functions it finally crashes completely

this is the code in which it fails to allocate the memory.
Code
Log( MSG_INFO, "Loading Sell Data" );
    //Log(MSG_WARNING,"STB rowcount: %i",STB_SELL.rowcount );
    for(unsigned int i=0;i<STB_SELL.rowcount;i++)
    {
        //Log( MSG_INFO, "Sell Data row %i",i );
        CCSellData* newsell = new (nothrow) CCSellData;
        if(newsell == NULL)
        {
            Log(MSG_WARNING, "\nError Allocing memory: sell" );
            return false;
        }
The commented Log commands (when uncommented) show that STB_SELL.rowcount is around 500 so it's not that which is causing the issue.
When i run the EXE it just spits out the MSG_WARNING and returns false.
It apparently isn't creating "newsell"
The CCSellData structure is perfectly OK. It hasn't been changed for years and has always worked till a rebuild last week.

It goes on to do the same thing in 3 other loading subroutines before finally giving up on this one.
Code
Log( MSG_INFO, "Loading Jem Data         " );
    for(unsigned int i=0;i<STB_ITEM[10].rowcount;i++)
    {
        CJemData* thisjem = new (nothrow) CJemData;
        if(thisjem == NULL)
        {
            Log(MSG_WARNING, "\nError allocing memory: jemitem" );
            continue;
        }
this time all it does is print out "Loading Jem Data" then it just crashes completely with a message that the program terminated in an unusual way. (is there a usual way to crash i wonder?)

The really strange thing is that when I run the project directly from the debugger in CodeBlocks it runs flawlessly.
This error only occurs in the executable.
Another strange thing is that changing something totally unrelated in another part of the project then rebuilding the whole thing sometimes (about 1 build in 10) results in a working exe but it always works from the debugger.

Any suggestions?

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Only runs in debug mode
« Reply #1 on: May 23, 2012, 05:20:16 pm »
Read the rules of the forum and then ask your question in an appropriate forum/mailing list.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline purpleyouko

  • Single posting newcomer
  • *
  • Posts: 3
Re: Only runs in debug mode
« Reply #2 on: May 23, 2012, 06:11:19 pm »
Read the rules of the forum and then ask your question in an appropriate forum/mailing list.
Thanks for the advice.

I have read the rules quite thoroughly.
I always do when posting to a new board since I never like to annoy anyone by posting in the wrong place. I own several boards myself and moderate many others so I know how annoying it can be.

First I used the search function to attempt to find any mention of this issue. It came up with nothing useful which isn't really surprising. The search functions on most forums either turn up nothing or 20 million posts. That's just the nature of busy forums and something we have to live with.

As to asking my question in an appropriate forum, I was under the impression that this one was the one to use when the subject doesn't quite fit anywhere else.
The only other possibility might be the "Help" forum. I carefully weighed up whether to post there or here and based on other threads and their content, this one seemed to be the most appropriate. 
I could have posted in both but that is usually frowned upon so I chose here.

Offline oBFusCATed

  • Developer
  • Lives here!
  • *****
  • Posts: 13413
    • Travis build status
Re: Only runs in debug mode
« Reply #3 on: May 23, 2012, 06:31:44 pm »
I have read the rules quite thoroughly.
Yeah, right I believe you...

http://forums.codeblocks.org/index.php/topic,9996.0.html
Quote
1. This is NOT a general programming board. "How do I write a program that....", "Can anybody teach me how to", "I have this homework",  "My program doesn't run and I don't have the slightest idea of why because I'm a C++ newcomer", "What is a compiler", "What does gcc do" is the kind of questions that is FORBIDDEN to ask.
(most of the time I ignore long posts)
[strangers don't send me private messages, I'll ignore them; post a topic in the forum, but first read the rules!]

Offline purpleyouko

  • Single posting newcomer
  • *
  • Posts: 3
Re: Only runs in debug mode
« Reply #4 on: May 23, 2012, 07:09:37 pm »
I have read the rules quite thoroughly.
Yeah, right I believe you...

http://forums.codeblocks.org/index.php/topic,9996.0.html
Quote
1. This is NOT a general programming board. "How do I write a program that....", "Can anybody teach me how to", "I have this homework",  "My program doesn't run and I don't have the slightest idea of why because I'm a C++ newcomer", "What is a compiler", "What does gcc do" is the kind of questions that is FORBIDDEN to ask.

Except that is really not the question I'm asking is it?
My program runs quite nicely... in debug mode.
And it has been running just fine as as exe since 2005 when I first wrote it. It randomly stopped working last week.
I've been programming C++ since 1993 and other languages for 20 years prior to that.
I'm not really what you might describe as a newcomer at C++ or any other computer language.

Offline stahta01

  • Lives here!
  • ****
  • Posts: 7591
    • My Best Post
Re: Only runs in debug mode
« Reply #5 on: May 23, 2012, 07:20:11 pm »
Everyone on this forum likely believes your problem is NOT related to the Code::Blocks IDE.

That makes it NOT a valid topic.

NOTE: If you still believe the problem is related to the Code::Blocks IDE state why you believe that.

ALSO, State the needed information to help you. http://wiki.codeblocks.org/index.php?title=FAQ-Issues_and_Workarounds#Q:_I_posted_on_the_forums_that_Code::Blocks_was_not_working.2C_but_no_one_could_help_me.3F

Normal reason a program works in debug and not in release is variables not being initialized.
In your case, the likely cause is a virus program or other protective program.

NOTE: The fact it works in Code::Blocks; but, not from the command line means that it IS NOT a Code::Blocks issue!

Tim S.
« Last Edit: May 23, 2012, 07:24:44 pm by stahta01 »
C Programmer working to learn more about C++ and Git.
On Windows 7 64 bit and Windows 10 64 bit.
--
When in doubt, read the CB WiKi FAQ. http://wiki.codeblocks.org