Hi all,

I have a very weird problem.
I develop a game on Nintendo DS using DevKitPro.

I have a method that get a value in an XML file :

sscanf(xEffect.getChildNode("mpmodif").getAttribute("value"), "%d", &mpModif);

With the values I have get, I instanciate a new Effect :

Effect *test = new Effect(durationTime, probabilities, delay, target0, hpModif, mpModif, intModif, agiModif, strModif, defModif, mdefModif, aspdModif, msModif, msModifPer, atkModif, status);

But this instanciation seems not to be effective.
Indeed, I print values :

iprintf("\x1b[2;0H test : %d, %d\n", test->GetMpModif(), mpModif);

The, the result is 0,-50.

Here is the Effect constructor :

Effect::Effect(u16 durationTime, u8 probabilities, u8 delay, u8 target, int hpModif, int mpModif, int intModif, int agiModif, int strModif, int defModif, int mdefModif, int aspdModif, int msModif, int msModifPer, int atkModif, Status status) :
  Start_(0), Stop_(0), Run_(0),	durationTime_(durationTime), probabilities_(probabilities), delay_(delay), target_(target),	hpModif_(hpModif), mpModif_(mpModif), intModif_(intModif), agiModif_(agiModif), strModif_(strModif), defModif_(defModif), mdefModif_(mdefModif), aspdModif_(aspdModif), msModif_(msModif), msModifPer_(msModifPer), atkModif_(atkModif), status_(status), lastTick_(0), started_(false)
{
  [...] // No relationship with the subject
}

With this, no way it works.

I tried to initialize fields in the ctor body and to iprintf the mpModif_ value. When I do that BETWEEN the "//**********" (see below), it works fine, and I got the good values (-50, -50). Otherwise, it doesnt work. I show you :

Effect::Effect(u16 durationTime, u8 probabilities, u8 delay, u8 target, int hpModif, int mpModif, int intModif, int agiModif, int strModif, int defModif, int mdefModif, int aspdModif, int msModif, int msModifPer, int atkModif, Status status)
{
        //****************
	Start_ = 0;
	Stop_ = 0;
	Run_ = 0;
	durationTime_ = durationTime;
	probabilities_ = probabilities;
	delay_ = delay;
	target_ = target;
	hpModif_ = hpModif;
	mpModif_ = mpModif;
	intModif_ = intModif;
	agiModif_ = agiModif;
	strModif_ = strModif;
	defModif_ = defModif;
	mdefModif_ = mdefModif;
	aspdModif_ = aspdModif;
	msModif_ = msModif;
	msModifPer_ = msModifPer;
	atkModif_ = atkModif;
	//****************
	status_ = status;
	lastTick_ = 0;
	started_ = false;

        [...] // No relationship with the subject
}

Could that be a DS reference issue ? A comrade talked me about something like that but I do not lose hope to find the problem...
Thank you very much for your help I have to finish this game very soon !
I will keep looking here for the next days, please ask me details if you have any idea.

++

Recommended Answers

All 3 Replies

Show us how test->GetMpModif() is implemented.

If in debug, the member variable is fine, then my guess would be either
- the 'get' function is doing the wrong thing.
- the class instance may already have gone out of scope (check the dtor to see if it's called).

The getter is the below :

const int GetMpModif() const {return mpModif_;}

In debug, the member variable is fine SOMETIMES.
It does not seem to be a dtor problem but I think the variable affectation does not work for a strange reason... :(

Seems to me that you have an unrelated memory overrun in another part of the program.

As soon as you've set the value, and can verify that the correct value is stored, use the debugger to add a "watch" on that variable instance to detect another attempt to write to that location.

Then allow the code to run (probably slowly if watchpoints are not done in hardware) and then hopefully catch the real culprit in the act of trashing your data.

Another thing to try is to extract this particular class into a project all of it's own, just to verify that it is working correctly so long as there is nothing else going on. If this also works as expected, then that is another sign of the class being the victim of "collateral damage" from something else.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.