Code::Blocks Forums

User forums => Using Code::Blocks => Topic started by: yablebab on October 19, 2006, 11:02:15 pm

Title: .exe crashes but works fine from within codeblocks
Post by: yablebab 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?
Title: Re: .exe crashes but works fine from within codeblocks
Post by: thomas 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...   :?
Title: Re: .exe crashes but works fine from within codeblocks
Post by: kidmosey 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.
Title: Re: .exe crashes but works fine from within codeblocks
Post by: yablebab 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
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?
Title: Re: .exe crashes but works fine from within codeblocks
Post by: kidmosey on October 20, 2006, 11:14:29 pm
you do it in the constructor.

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

or

Code
    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?