Segfault (Segmentation fault) for no reason

Pages: 1234
This window pops up right before it crashes:
http://imgur.com/qc2ID1D
Everything used to work and all of a sudden it doesn't anymore.
The images load properly, it's initialised properly, etc
I just added an integer to one of the classes and then it got f-ed up.
Also I ran some tests and it crashes only if I do Chest(..parameters..)
If I create an instance of a chest it crashes
Last edited on
(Please learn to edit your posts instead of making new ones each time)

If you want to send me the link you sent Disch I will take a quick look, but I doubt I will find much if he didn't.

Judging by that image you sent it "is" crashing when first loading the image, did you try inserting the code I suggested just to make 100% sure the image is loading correctly?
Last edited on
What the.. now the program runs fine , but it crashes ionly in debug mode...
And sorry for making to many replies I'm really tired..
Last edited on
Okay! That screenshot tells me tons!

So this means one of 2 things:

1) Your player object has a bad pointer
or
2) Your player object itself is nonexistent and was called from init() as a bad pointer.



So next steps:

1) Get to that same window again. When the debugger snaps, go in the "Debug" menu, go to "Debugging Windows", and select "Watches". This should bring up a new window with a bunch of variable names and will tell you the contents of each variable.

2) Look at the 'imgAddr' variable and make sure it is what you expect it to be.

3) Look at the 'loadedImg' variable and make sure it is not NULL (00000)




EDIT:

James2250 is right, one of the load functions failing here is a definite culprit. From the screenshot you posted it looks like imgAddr is valid, but I can't tell about 'loadedImg', and that's really the important one.
Last edited on
Actually no I was just really , really dumb and I deleted the resources folder from projects folder, that's why it could only work in standalone mode.
Sorry for being stupid.Here's the actual error log now that I fixed that:
http://imgur.com/lR6hFHT

I think I need to get a new compiler.That's what it looks like to me..
Last edited on
So then... this IS pre-main? =x

That screenshot sure looks pre-main... since main is not in your call stack.

You've tried setting a breakpoint on the first line of your main() function? Does that breakpoint trip before the crash? Or does the crash happen before it even gets there?

Sorry to beat this horse but this is confounding.
And if I do continue over that error it then gives me this:
http://imgur.com/xLS0KDT

It fails loading for some reason , but only when I have that extra int variable in the Item class...
Im so confused.
Last edited on
Okay that code has the same culprits as before. Check loadedImg from the Watch window and make sure it is non-null.
Now that fixed and the window doesn't say anything...
Dear God have mercy on my soul.

Now it's the strchr() and ??() error again!
But if i click continue for e bunch of times it works fine.

Ok I'm stupid again:The chest image error is't fixed I just walked around it.
How do I do the watch thing you told me?
Last edited on
Are you rebuilding between these tests?

If you are, stop it. =P

Get the bug to reproduce, then do not touch your code and just work solely in the debugger. Every time you rebuild you change everything and you have to start debugging all over.

Step 1) Get the bug to reproduce.

Step 2) Put a breakpoint on the very first line of main

Step 3) Run the program to see if the breakpoint trips, or if the program crashes before that.
imgAddr is not what I expect it to be , it's some weird symblos and the the imgAddr that should be , and the surface is 0x0 NULL

with a breakpoint on the first line (line 0 , #include) i get this:
http://imgur.com/aVreRLS

without it I dont get it
Last edited on
GREAT!!!

That's fantastic!!!!!

Okay, now go up a level on the call stack and use the watch to see all the params you're passing to that function. The param for imgAddr is going to be wrong, so look at the code and see where you're getting that string.

Just keep using the call stack to walk backwards in the code until you can spot where that string is getting incorrectly set. And that will tell you where the problem is.
dude , the imgAddr I give it is good, it only happens if I add that extra int in Item.h

Without it it works fine
Last edited on
If i have this in Item.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#ifndef ITEMS_H_INCLUDED
#define ITEMS_H_INCLUDED
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <stdarg.h>

#define BUFF_NONE 0
#define BUFF_HEALTH 1
#define BUFF_IMMORTAL 2
#define BUFF_WATERWALKING 3
#define BUFF_DEFENCE 4

class Item
{
private:
    float X;
    float Y;
    int W;
    int H;
    int OX;
    int OY;
    const char* imgAddr;
    const char* Name;
    int TYPE;
    int damage;
    int attackSpeed;
    int armor;
    int buffId;
    int buffStr;
    SDL_Surface* surface;

public:
    Item();
    Item(int x,int y,int w,int h,const char* name,const char* img_addr);
    Item(int x,int y,int w,int h,const char* name,const char* img_addr,int flags);

    void draw(SDL_Surface* window);
    void drawName(SDL_Surface* window,int x,int y);
    void move_to(int,int);
    void flag(int flag);
    void Move(char axis,float speed);
    void setWeapon(int Damage,int AttackSpeed);
    void setHelmet(int Armor);
    void setChestplate(int Armor);
    void setLeggins(int Armor);
    void setBoots(int Armor);
    void setAccessory(int buff_id,int buff_strength);
    void setConsumable(int buff_id,int buff_strength);
    void setArmor(int Armor);
    void setDamage(int Damage);
    void randomBuff();
    void use();
    void destroy();

    int getX();
    int getY();
    int getH();
    int getW();
    int getOX();
    int getOY();
    int getItemType();
    int getDamage();
    int getAttackSpeed();
    int getArmor();
    int getBuffID();
    int getBuffStr();
    bool contains(int ,int);
    const char* getImgAddr();
    const char* getName();
};

#endif // ITEM_H_INCLUDED 

IT works just fine with absolutelly no error.

If I have this in Item.h:
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
#ifndef ITEMS_H_INCLUDED
#define ITEMS_H_INCLUDED
#include <SDL/SDL.h>
#include <SDL/SDL_ttf.h>
#include <stdarg.h>

#define BUFF_NONE 0
#define BUFF_HEALTH 1
#define BUFF_IMMORTAL 2
#define BUFF_WATERWALKING 3
#define BUFF_DEFENCE 4

class Item
{
private:
    float X;
    float Y;
    int W;
    int H;
    int OX;
    int OY;
    const char* imgAddr;
    const char* Name;
    int TYPE;
    int damage;
    int attackSpeed;
    int armor;
    int buffId;
    int buffStr;
    int EXTRA_INT_NAME;  ///Extra int added
    SDL_Surface* surface;

public:
    Item();
    Item(int x,int y,int w,int h,const char* name,const char* img_addr);
    Item(int x,int y,int w,int h,const char* name,const char* img_addr,int flags);

    void draw(SDL_Surface* window);
    void drawName(SDL_Surface* window,int x,int y);
    void move_to(int,int);
    void flag(int flag);
    void Move(char axis,float speed);
    void setWeapon(int Damage,int AttackSpeed);
    void setHelmet(int Armor);
    void setChestplate(int Armor);
    void setLeggins(int Armor);
    void setBoots(int Armor);
    void setAccessory(int buff_id,int buff_strength);
    void setConsumable(int buff_id,int buff_strength);
    void setArmor(int Armor);
    void setDamage(int Damage);
    void randomBuff();
    void use();
    void destroy();

    int getX();
    int getY();
    int getH();
    int getW();
    int getOX();
    int getOY();
    int getItemType();
    int getDamage();
    int getAttackSpeed();
    int getArmor();
    int getBuffID();
    int getBuffStr();
    bool contains(int ,int);
    const char* getImgAddr();
    const char* getName();
};

#endif // ITEM_H_INCLUDED 


It gives me the imgAddr error and the strchr() error

Any ideas?
Last edited on
Also just noticed it says "__static_initialization_and_destruction_0 (__initialize_p=1, __priority=65535)" in main on line 104.
Adding/removing lines of code to see what works is virtually useless. That tells me nothing, and is misleading you into thinking the problem is something other than what it really is. It is not the right way to diagnose this problem.

Based on the screenshot you added with that edit (which I just saw now), it looks like the problem might be in mapA's constructor. I thought I scoured all your ctors but I must have missed something apparently...

But it's strange that that's where it's snapping, because that line clearly has nothing wrong with it. If the problem was with initialization, it should snap on the actual initialization line.



Remote debugging is hard, especially when I can't really see what's happening.



EDIT: I wonder if we can do some kind of chat where you can share your screen with me realtime. I'm going to look to see if I can find a program for that.
Last edited on
What's a static initialization and destruction?
Do you have Skype?You can share screens like that.
Or team viewer, that way you can remotely access my computer if I allow it.
Last edited on
Pages: 1234