Author Topic: .exe crashes but works fine from within codeblocks  (Read 3328 times)

Offline yablebab

  • Single posting newcomer
  • *
  • Posts: 5
.exe crashes but works fine from within codeblocks
« on: October 19, 2006, 11:02:15 pm »
First, the background:
WindowsXP
Code::Blocks IDE Sep 6, 2006 build
wxWidgets 2.7
Irrlicht Graphics Engine v 1.1

I'm building a win32 app with irrlicht embedded in a wx control. When I compile for debug, and press F9 in codeblocks, it runs perfectly. But when I try and run the exe externally (just double-clicking on the .exe file) it crashes. Also, if I compile for release it won't run either way. This is a huge problem! Anyone ever heard of this happening before?

Offline thomas

  • Administrator
  • Lives here!
  • *****
  • Posts: 3979
Re: .exe crashes but works fine from within codeblocks
« Reply #1 on: October 19, 2006, 11:49:33 pm »
If you had said "press F8" then the problem would be obvious: an uninitialised pointer in your code.

But having that problem with "F9" is kind of odd. It doesn't do much but execute the program after building it. So except for the program being in a different memory region, all is the same (dread to think of faulty RAM). You don't play any complicated relocation tricks, I trust?
It is surprising even more so as compiling debug/release shouldn't make any difference at all (the only difference is symbols being added, it is still the very same code).

Sometimes, an exotic compiler option can have nasty results, too. Can you post the build commandline (at least one complete compiler and one complete linker line)?
Though I doubt it will help, maybe one can see something wrong in there...   :?
"We should forget about small efficiencies, say about 97% of the time: Premature quotation is the root of public humiliation."

Offline kidmosey

  • Multiple posting newcomer
  • *
  • Posts: 95
    • MUSITU International
Re: .exe crashes but works fine from within codeblocks
« Reply #2 on: October 20, 2006, 03:15:29 am »
Is your working directory the same as the output directory?  If you are loading from a non-existant resource file and not checking if it exists, you could get all sorts of nulls.
3 years until google knows more than god.

Offline yablebab

  • Single posting newcomer
  • *
  • Posts: 5
Re: .exe crashes but works fine from within codeblocks
« Reply #3 on: October 20, 2006, 08:11:17 pm »
So I found a couple of pointers that were uniitialized, which I thought could be causing the crash. The problem is, I have a whole bunch of pointers declared from within a class, like so:

Code: [Select]
class MyWindow: public wxWindow
{
public:
    ...
    ...
private:
    ...
    wxNotebook* ToolNB;

    wxWindow* EventAnalysisWin;
    wxWindow* DetectorWin;
    wxWindow* MultimediaWin;
    ...
};

Of course, trying to initialize any of these NULL causes an error: only static const integral data members can be initialized within a class.

Are there any ways around this?

Offline kidmosey

  • Multiple posting newcomer
  • *
  • Posts: 95
    • MUSITU International
Re: .exe crashes but works fine from within codeblocks
« Reply #4 on: October 20, 2006, 11:14:29 pm »
you do it in the constructor.

Code: [Select]
    MyWindow():
        wxWindow(),
        ToolNB(NULL),
        EventAnalysisWin(NULL),
        DetectorWin(NULL),
        MultimediaWin(NULL)
    {
    }

or

Code: [Select]
    MyWindow(): wxWindow()
    {
        ToolNB = NULL;
        EventAnalysisWin = NULL;
        DetectorWin = NULL;
        MultimediaWin = NULL;
    }

even better would be to give them default values instead of NULL.  Are you using any external resource files?
3 years until google knows more than god.