Message Board


Message Board > C/C++ > Crash when variables not declared.

February 15, 2006, 22:34
DTM
Earthling!
821 posts

Code:
class ScreenVariable {
public:
    void set(uint node, float *data, uint nFont, float x, float y);
    ~ScreenVariable()
    {
        world->kill_node(nText);
    }
    void Update()
    {
        char number[12];
        snprintf(number, 12, "%f", *data);
        world->set_text(nText, nFont, 12, 0.2, 0.0, 0.3, 1, number);
    }
private:
    float *data;
    uint nFont;
    uint nText;
    float x, y; <-- HERE
};

void ScreenVariable::set(uint node, float *data, uint nFont, float x, float y)
{
    this->data = data;
    this->nFont = nFont;
    nText = world->new_node();
    world->link_node(node, nText);
    world->translate_node(nText, x, y, -ENGINEznear-0.001);
    world->scale_node(nText, 0.03, 0.03, 10.03);
    world->ignore_camera(nText);
}


Perhaps I have just missed something simple... but the above code crashes if the line "float x, y;" as marked is commented out.

Why!? :F
____________
:o
#
February 15, 2006, 22:39
Eckolin
Quite Whiskered
388 posts

You could try renaming those variables and see if it still crashes.

[Edited on February 15, 2006 by Eckolin]
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
February 15, 2006, 23:00
DTM
Earthling!
821 posts

I can replace the "float x, y;" with "float woooo;" and it's still okay.

If I move it above "uint nText" it also crashes.

Seems like I need a float on the end for some reason... :/

*tests*

Or a bool!

Code:
    float *data;
    uint nFont;
    uint nText;
    bool woooo;
};


That doesn't crash either.

I thought this thing only happened in Fenix... O_O

[Edited on February 15, 2006 by DTM]
____________
:o
#
February 15, 2006, 23:27
Eckolin
Quite Whiskered
388 posts

Everyone knows C++ was written in Fenix and vice versa.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
February 15, 2006, 23:30
PEader
お前はもう死んでいる
1486 posts

I'd say you are overwritting memory somewhere you shoulnd't be and as long as you have something after nText it is ok since you aren't overwritting a register or going out of segement. I'd debug/step through my code if I were you.
____________
I see 57,005 people.
#
February 16, 2006, 01:10
Eckolin
Quite Whiskered
388 posts

I concur with PEader. Probably an off-by-one error then, if it only takes a bool to counteract.

[Edited on February 16, 2006 by Eckolin]
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
February 16, 2006, 09:52
PEader
お前はもう死んでいる
1486 posts

Quoting Eckolin:
I concur with PEader. Probably an off-by-one error then, if it only takes a bool to counteract.

I'd say it's also messing with the two unsigned ints.
____________
I see 57,005 people.
#
February 16, 2006, 12:33
DTM
Earthling!
821 posts

Today I remove the bool and it works :/ I changed nothing else...
Strange.
____________
:o
#
February 16, 2006, 12:50
PEader
お前はもう死んでいる
1486 posts

Quoting DTM:
Today I remove the bool and it works :/ I changed nothing else...
Strange.

Maybe you just suck at programming? It's obviously not that bit of code but somethign else you are calling.
____________
I see 57,005 people.
#
February 16, 2006, 20:51
DTM
Earthling!
821 posts

Quoting PEader:
Maybe you just suck at programming?

Nah, don't think so. It's got to be a compiler bug. :yay:
____________
:o
#
February 16, 2006, 21:37
Eckolin
Quite Whiskered
388 posts

Quote:
I'd say it's also messing with the two unsigned ints.


Only if the error is happening at float *data;

Which it probably is.
____________
Maker of Games...
Wisdom is supreme; therefore get wisdom.
Need help with coding? I probably wrote something similar.
#
February 16, 2006, 22:45
DTM
Earthling!
821 posts

How do you know these things?
____________
:o
#

Message Board > C/C++ > Crash when variables not declared.

Quick reply


You must log in or register to post.
Copyright © 2005 Booleansoup.com
Questions? Comments? Bug reports? Contact us!