executable crashing at runtime

S

seaders69

I'm developing a large enough application which is using quite a few
custom libraries, but I'm running into a few strange errors, and
crashes, at runtime.

I've got quite a few class structures in place and am also reading in
configuration input from a file. So, in one particular class, I've
two maps, one an <int, int> template, the other <char, int> and it
also contains a vector <int>, all of them are static, which they need
to be, for the purpose of the application.

Now, if I compile my code and run it, with nothing in the main block,
just

/** all relevant files included */

int main() {
return 0;
}

it crashes at the return 0. Now, after some investigation, I found
out that if I commented out where the map <char, int> was being
initialised, in it's cpp file, the application would run fine.

I'm using MinGW, with the Eclipse CDT IDE and remember running into
some problem like this before, but remember if / how I got around it.
Also, if I turn on optimisation, either at the 2, or 3 level, the
program works fine then, too. I assume that it's a memory allocation
issue, or similar, but I really am stumped. I don't even know what I
should be googling / reading up on, to figure out what's wrong.

Thanks for any help.
 
V

Vladimir Jovic

I'm developing a large enough application which is using quite a few
custom libraries, but I'm running into a few strange errors, and
crashes, at runtime.

I've got quite a few class structures in place and am also reading in
configuration input from a file. So, in one particular class, I've
two maps, one an <int, int> template, the other <char, int> and it
also contains a vector <int>, all of them are static, which they need
to be, for the purpose of the application.

Now, if I compile my code and run it, with nothing in the main block,
just

/** all relevant files included */

int main() {
return 0;
}

it crashes at the return 0. Now, after some investigation, I found
out that if I commented out where the map <char, int> was being
initialised, in it's cpp file, the application would run fine.

I'm using MinGW, with the Eclipse CDT IDE and remember running into
some problem like this before, but remember if / how I got around it.
Also, if I turn on optimisation, either at the 2, or 3 level, the
program works fine then, too. I assume that it's a memory allocation
issue, or similar, but I really am stumped. I don't even know what I
should be googling / reading up on, to figure out what's wrong.

Thanks for any help.

This might help:
http://www.parashift.com/c++-faq-lite/ctors.html#faq-10.12

Try running your program in some memory checking program (like valgrind,
tool=memcheck) and see if it helps.
 
S

seaders69

Ok, I've changed around a whole load of my code, so now there's
literally only 5-6 methods that are static, which definitely won't get
called until everything else is loaded, so the problem you described
is not relevant any more.

What is happening and very strange, imo, is that as soon as I try to
initialise the same map, which is now a member variable within one of
my classes, the application crashes. The map, as I said, is of <char,
int> type and in my constructor I've tried both of

my_map['x'] = 0;
and
my_map.insert(make_pair('x', 0));

and it crashes, during runtime, from both. I'm really stumped at the
this behaviour as I can't see any reason for it to die here.
 
A

Alf P. Steinbach

* (e-mail address removed):
Ok, I've changed around a whole load of my code, so now there's
literally only 5-6 methods that are static, which definitely won't get
called until everything else is loaded, so the problem you described
is not relevant any more.

What is happening and very strange, imo, is that as soon as I try to
initialise the same map, which is now a member variable within one of
my classes, the application crashes. The map, as I said, is of <char,
int> type and in my constructor I've tried both of

my_map['x'] = 0;
and
my_map.insert(make_pair('x', 0));

and it crashes, during runtime, from both. I'm really stumped at the
this behaviour as I can't see any reason for it to die here.

Reproduce the problem in a *minimal* but complete program and post it here.


Cheers & hth.,

- Alf

PS: The FAQ has some good advice about how to post a question about Code That
Does Not Work.
 
S

seaders69

* (e-mail address removed):




Ok, I've changed around a whole load of my code, so now there's
literally only 5-6 methods that are static, which definitely won't get
called until everything else is loaded, so the problem you described
is not relevant any more.
What is happening and very strange, imo, is that as soon as I try to
initialise the same map, which is now a member variable within one of
my classes, the application crashes.  The map, as I said, is of <char,
int> type and in my constructor I've tried both of
my_map['x'] = 0;
and
my_map.insert(make_pair('x', 0));
and it crashes, during runtime, from both.  I'm really stumped at the
this behaviour as I can't see any reason for it to die here.

Reproduce the problem in a *minimal* but complete program and post it here.

Cheers & hth.,

- Alf

PS: The FAQ has some good advice about how to post a question about Code That
Does Not Work.

--
Due to hosting requirements I need visits to <url:http://alfps.izfree.com/>.
No ads, and there is some C++ stuff! :) Just going there is good. Linking
to it is even better! Thanks in advance!- Hide quoted text -

- Show quoted text -

Ok, so I've finally gotten this down to as minimalist as possible and
3 files. Tighten it any more and the problem disappears.

*** main.cpp ***

#include <Aw.h>
#include <string>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

class aw_funcs {
public:
aw_funcs() {
cout << "initialising map begin" << endl;
obj_move_amounts.insert(make_pair('x', 0));
cout << "initialising map 1" << endl;
obj_move_amounts.insert(make_pair('y', 0));
cout << "initialising map 2" << endl;
obj_move_amounts.insert(make_pair('z', 0));
cout << "initialising map end" << endl;
}
private:
map<int, int> hud_sessions;
map<char, int> obj_move_amounts;
vector<int> obj_ids;
int sequence[3][3];
};

#include "custom.h"

int main(int argc, char* argv[]) {
aw_funcs awf;
}


It's active worlds sdk work that I'm doing, so that's what the <Aw.h>
file is, it can be downloaded and perused from here,
http://objects.activeworlds.com/downloads/awsdk77.zip

custom.h

#ifndef CUSTOM_H_
#define CUSTOM_H_

#include <string>
#include <map>
#include <vector>

void _set_coords(std::vector<std::string>, std::map<char, int>&
amounts);

#endif /* CUSTOM_H_ */

custom.cpp

#include "custom.h"

using namespace std;

void _set_coords(vector<string>, map<char, int>& amounts) {
// amounts['x'] = 0;
amounts.insert(make_pair('x', 0));
}


So, within that code, the things that make it not crash, is within
_set_coords, have the map not do anything to it's members. Or,
comment out <Aw.h>. Now, I need to have that included, so that's not
an option, but also, for how I'm using the program, I need the
_set_coords function as well. Also, if I get rid of custom.h and
custom.cpp, and bring the _set_coords function into the main.cpp file,
it also doesn't crash, but again, this isn't really an option.

Can anyone point me to where this is going wrong, I really am stumped.
 
A

Alf P. Steinbach

* (e-mail address removed):
Ok, so I've finally gotten this down to as minimalist as possible and
3 files. Tighten it any more and the problem disappears.

*** main.cpp ***

#include <Aw.h>
#include <string>
#include <iostream>
#include <map>
#include <vector>

using namespace std;

class aw_funcs {
public:
aw_funcs() {
cout << "initialising map begin" << endl;
obj_move_amounts.insert(make_pair('x', 0));
cout << "initialising map 1" << endl;
obj_move_amounts.insert(make_pair('y', 0));
cout << "initialising map 2" << endl;
obj_move_amounts.insert(make_pair('z', 0));
cout << "initialising map end" << endl;
}
private:
map<int, int> hud_sessions;
map<char, int> obj_move_amounts;
vector<int> obj_ids;
int sequence[3][3];
};

#include "custom.h"

int main(int argc, char* argv[]) {
aw_funcs awf;
}


It's active worlds sdk work that I'm doing, so that's what the <Aw.h>
file is, it can be downloaded and perused from here,
http://objects.activeworlds.com/downloads/awsdk77.zip

custom.h

#ifndef CUSTOM_H_
#define CUSTOM_H_

#include <string>
#include <map>
#include <vector>

void _set_coords(std::vector<std::string>, std::map<char, int>&
amounts);

#endif /* CUSTOM_H_ */

custom.cpp

#include "custom.h"

using namespace std;

void _set_coords(vector<string>, map<char, int>& amounts) {
// amounts['x'] = 0;
amounts.insert(make_pair('x', 0));
}


So, within that code, the things that make it not crash, is within
_set_coords, have the map not do anything to it's members. Or,
comment out <Aw.h>. Now, I need to have that included, so that's not
an option, but also, for how I'm using the program, I need the
_set_coords function as well. Also, if I get rid of custom.h and
custom.cpp, and bring the _set_coords function into the main.cpp file,
it also doesn't crash, but again, this isn't really an option.

Can anyone point me to where this is going wrong, I really am stumped.

The code you've shown doesn't use any of the AW functionality, and the
_set_coords routine is not called anywhere.

It works fine both with MinGW g++ 3.4.5 (when syntax errors in [Aw.h] corrected)
and MSVC 7.1.

<output>
initialising map begin
initialising map 1
initialising map 2
initialising map end
</output>

Uh, wait a minute, let me try also with that import library and DLL (trusting
that it doesn't contain any malware).

Hm, took a while to load with g++ version, but same output as before.

Let's try the same with MSVC.

Same output and no wait on startup. Actually no wait now with g++ version
either. I guess that means it was the original DLL loading that took time.

Consulting earlier experience with totally incomprehensible mismatch between
code and effect...

Hm, well, it's not entirely inconceivable that you're running an executable
generated from earlier code. ;-)



Cheers & hth.,

- Alf
 
S

seaders69

The code you've shown doesn't use any of the AW functionality, and the
_set_coords routine is not called anywhere.

Don't I know it! It's just getting compiled and _set_coords is
getting some body in the cpp file.
It works fine both with MinGW g++ 3.4.5 (when syntax errors in [Aw.h] corrected)
and MSVC 7.1.

Yeah, the syntax errors are only warning ones, because MinGW expects
Linux style #pragma code, but because LINUX is not defined, it tries
to run the Windows style #pragma code... doesn't really effect
anything overall.
<output>
initialising map begin
initialising map 1
initialising map 2
initialising map end
</output>

Uh, wait a minute, let me try also with that import library and DLL (trusting
that it doesn't contain any malware).

Nah, it certainly doesn't contain any malware, no doubt, it's produced
by Active Worlds and download direct from their site. For your code
to run like mine, in MinGW, you actually need to ignore the .lib file
in that zip file and create your own libAw.a from the dll, using
pexports, then link to that library,
http://kahnews.net/bots/
http://kahnews.net/bots/dll2a.zip

(just checked there and took out the reference to the libAw.a file and
it made no difference, still crashing at the same point, as for the
dll, that won't matter either, because the existence of it only gets
checked for if you call aw_init(), that initialises the API, dll and
ensures all versions and whatnot are correct)
Hm, took a while to load with g++ version, but same output as before.

Let's try the same with MSVC.

Same output and no wait on startup. Actually no wait now with g++ version
either. I guess that means it was the original DLL loading that took time.

Consulting earlier experience with totally incomprehensible mismatch between
code and effect...

Hm, well, it's not entirely inconceivable that you're running an executable
generated from earlier code. ;-)

Nah, this is one thing I can confidently say, on clean compilation, I
delete everything previously compiled, .o files and .exe ones, so
there's no chance of that. If I change any of the printout from the
constructor, the updated string will be printed.
Cheers & hth.,

- Alf

This exact code and all references work perfectly in Visual Studios
2008, but I hate that program and interface and have been using and
getting on perfectly with Eclipse for a few years now :/
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,582
Members
45,065
Latest member
OrderGreenAcreCBD

Latest Threads

Top