Public Group

# Same code... different outcomes?

This topic is 4404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

As I said in a previous topic I have been working on a Sprite/Animation class. Well I've been working on it for a few days now (it is very screwy) and at first it didn't work, then it only showed one animation, then two animations; well I just changed my code to Release mode (from debug mode) and it now shows all three animations. Any thoughts on why it would suddenly work?

##### Share on other sites
I will give the reply this question (which has no info) the response it deserves.

Yes.

##### Share on other sites
*sweatdrop*

Ok yeah, I guess I didn't make myself clear. What exactly is so different between Release mode and Debug mode that would allow for code to not run in Debug mode and yet run in Release mode. I thought that Release mode was supposed to be stricter with code? Doesn't that make it a lil odd that something would work in Release mode and not in debug mode?

i guess what i'm looking for is a run-down of what the difference between the two modes is; if i know that maybe i can try to figure out why it won't work in debug mode

##### Share on other sites
Quote:
 Ok yeah, I guess I didn't make myself clear. What exactly is so different between Release mode and Debug mode that would allow for code to not run in Debug mode and yet run in Release mode. I thought that Release mode was supposed to be stricter with code? Doesn't that make it a lil odd that something would work in Release mode and not in debug mode?

No, debug mode is MORE strict than release mode; this is so that you can catch every bug possible, especially the ones that only appear sporadically, so that they don't pop up unexpectedly in release mode.

As the AP not-so-subtly stated there's not enough information to tell you what exactly has happened. All the same I'd bet a large wad of cash it's something to do with pointers or dynamic memory allocation/deallocation. Code please!

##### Share on other sites
Quote:
 Original post by -justin-Ok yeah, I guess I didn't make myself clear. What exactly is so different between Release mode and Debug mode that would allow for code to not run in Debug mode and yet run in Release mode.

It's something wrong with your code, not with Release vs. Debug mode. If you would post your code, I'm sure someone would be happy to point out any flaws. Beyond that, you should learn how to use the MSVC debugger, it's an invaluable tool.

jfl.

##### Share on other sites
Yeah, heh, you guys are always really good. Even when I give you little information to go on. I wasn't originally looking for help mainly because I hate to bother you with lots of code -_- I've been wrackin my brains about a million times and I really just think I'm gonna go and rewrite all my code.

@jfl yeah sorry, i didn't mean to sound like i was saying it was something wrong with Debug/Release mode, i know it's an error in my code but i just can't seem to find it :-/

Anywho, this topic can be closed if need be. I'll post my code in-case any1 wants to have a gander. Thanx.

Overview of code:

I have the following classes:

Entity -> Holds all the vital information (life, speed, position on screen, etc), has an AI object and a sHandler object
Player -> Inherits from Entity, handles player input, has update function etc
Level -> Adds the player, adds "scenes", draws "scenes", handles player input, holds the players in the level
Scene -> Sets up the background, holds all the entities (bad guys) in the scene, add entities, adds objects (items) etc

One reason I need to re-write this code a little is that I'm using my own dynamic memory for the Scene/Levels because I only recently looked into STL (as sad as that is). Anyway below is the code in all its horribleness. If you need more let me know :p

The problem as far as I can tell is that on the WALKING animation my RECT goes funky (I saw in the debugger that they were really messed up, my only idea is that there is a bad pointer somewhere in this -_-)

Here we go again!

Some global elements (in gameGlobals.h)
	struct sequence	{		DWORD delay;  // how much delay this particular image in the animation has		RECT selection;  // the rectangle for selection based on what image is chosen		float width;  // width of the stand still image		float height;  // height of the stand still image		DWORD startTime;  // the time that the value started		collisionBox cbA;  // collision box for attack		collisionBox cbD;  // collision box for defense	};	enum movement	{		IDLE,		WALKING,		RUNNING,		ATTACK1,  // base attack 1		JUMP	};

sHandler.h
#ifndef sHandler_H#define sHandler_H#include <d3d9.h>#include <d3dx9core.h>#include "animation.h"#include <map>class sHandler{private:	std::map<movement, animation> ani;	std::map<movement, animation>::iterator it;    LPD3DXSPRITE sSprite;    LPDIRECT3DTEXTURE9 sTexture;	bool firstTime;  // uses reset oncepublic:	sHandler();	void addAnimation(animation a, movement t);	void update(movement t);	LPD3DXSPRITE getS();  // get the sprite object        LPDIRECT3DTEXTURE9 getT();  // get the texture        RECT getR();  // get the rectangle to the image	void setType(movement typ);	movement getType();	void findAni(movement t, std::string s);        void loadGraphics(char* filename, LPDIRECT3DDEVICE9 g_pd3dDevice);};#endif

sHandler.cpp (imp stuff)
void sHandler::addAnimation(animation a, movement t){	pair<movement, animation> p(t, a);	ani.insert(p);}void sHandler::update(movement t){	if(firstTime == true)	{		it->second.reset();		//currentAnimation = 0;		firstTime = false;	}		it->second.update();}void sHandler::findAni(movement t, std::string s){	if(ani.find(t) == ani.end())	{   ofstream output;	    output.open("errorLog.txt", ios::app);	    output << s.c_str() << endl;	    output.close();	}	else	{		it = ani.find(t);			}}animation.h#ifndef ANIMATION_H#define ANIMATION_H#include "gameGlobals.h"#include <vector>class animation{  private:    std::vector<sequence> s; // a vector of sequences    std::vector<sequence>::iterator it; // the iterator    movement type;  public:    RECT getImgRect();    void update();	void reset();    void addToSeq(sequence seq);    void setType(movement t);    movement getType();};#endif

animation.cpp (imp stuff)
#include "animation.h"#include <fstream>using namespace std;RECT animation::getImgRect(){  return it->selection;}void animation::update(){ if((GetTickCount() - it->startTime) >= it->delay)  {    if(it != s.end())    {      it++;    }    if(it == s.end())    {      reset();    }	it->startTime = GetTickCount();  }}void animation::addToSeq(sequence seq){  DWORD tNow = GetTickCount();  seq.startTime = tNow;  s.push_back(seq);}

inside my main source file i do things in this order:

masterInput();// l is a level object, updates everything in the scene; 0 is the scene numl.updateScene(0);// update the player inputl.pInput();// draw the scenel.drawScene(0, g_pd3dDevice);

this is the way i put my animations in for the player
void Player::setup(int pNum, LPDIRECT3DDEVICE9 g_pd3dDevice){  RECT imgBox;  movement movType;	if(pNum == 1) // the player is "sakura"	{		sh.loadGraphics("sakura2.png", g_pd3dDevice);  // load the graphics		/////////////////// ATTACK1 /////////////////////		animation amat;		sequence se;  // our sequence object		imgBox.top = 96;		imgBox.bottom = 192;		// first seq, first animation		imgBox.left = 0;		imgBox.right = 84;		se.delay = 100;		se.selection = imgBox;		se.width = (float)abs(imgBox.right - imgBox.left);		se.height = (float)abs(imgBox.top - imgBox.bottom);		amat.addToSeq(se);		// second seq, first animation		imgBox.left = 84;		imgBox.right = 180;		se.delay = 100;		se.selection = imgBox;		se.width = (float)abs(imgBox.right - imgBox.left);		se.height = (float)abs(imgBox.top - imgBox.bottom);		amat.addToSeq(se);		// third seq, first animation		imgBox.left = 180;		imgBox.right = 266;		se.delay = 100;		se.selection = imgBox;		se.width = (float)abs(imgBox.right - imgBox.left);		se.height = (float)abs(imgBox.top - imgBox.bottom);		amat.addToSeq(se);		// fourth seq, first animation		imgBox.left = 266;		imgBox.right = 333;		se.delay = 100;		se.selection = imgBox;		se.width = (float)abs(imgBox.right - imgBox.left);		se.height = (float)abs(imgBox.top - imgBox.bottom);		amat.addToSeq(se);		// fifth seq, first animation		imgBox.left = 333;		imgBox.right = 435;		se.delay = 100;		se.selection = imgBox;		se.width = (float)abs(imgBox.right - imgBox.left);		se.height = (float)abs(imgBox.top - imgBox.bottom);		amat.addToSeq(se);		// sixth seq, first animation		imgBox.left = 435;		imgBox.right = 562;		se.delay = 100;		se.selection = imgBox;		se.width = (float)abs(imgBox.right - imgBox.left);		se.height = (float)abs(imgBox.top - imgBox.bottom);		amat.addToSeq(se);		// add the animation		movType = ATTACK1;		amat.setType(movType);		amat.reset();		sh.addAnimation(amat, movType);		/////////////////// IDLE /////////////////////		animation amat2;		sequence se2;  // our sequence object		// now load the individual sequences		imgBox.top = 192;		imgBox.bottom = 288;		// first seq, first animation		imgBox.left = 0;		imgBox.right = 85;		se2.delay = 200;		se2.selection = imgBox;		se2.width = (float)abs(imgBox.right - imgBox.left);		se2.height = (float)abs(imgBox.top - imgBox.bottom);		amat2.addToSeq(se2);		imgBox.top = 192;		imgBox.bottom = 288;		// second seq, first animation		imgBox.left = 85;		imgBox.right = 169;		se2.delay = 200;		se2.selection = imgBox;		se2.width = (float)abs(imgBox.right - imgBox.left);		se2.height = (float)abs(imgBox.top - imgBox.bottom);		amat2.addToSeq(se2);		imgBox.top = 192;		imgBox.bottom = 288;		// third seq, first animation		imgBox.left = 169;		imgBox.right = 264;		se2.delay = 200;		se2.selection = imgBox;		se2.width = (float)abs(imgBox.right - imgBox.left);		se2.height = (float)abs(imgBox.top - imgBox.bottom);		amat2.addToSeq(se2);		// add the animation		movType = IDLE;		amat2.setType(movType);		amat2.reset();		sh.addAnimation(amat2, movType);		///////////////////////////// WALKING //////////////////////////////		animation amat3;		sequence se3;  // our sequence object		// now load the individual sequences		imgBox.top = 0;		imgBox.bottom = 96;		// first seq, second animation		imgBox.left = 0;		imgBox.right = 82;		se3.delay = 100;		se3.selection = imgBox;		se3.width = (float)abs(imgBox.right - imgBox.left);		se3.height = (float)abs(imgBox.top - imgBox.bottom);		amat3.addToSeq(se3);		// second seq, second animation		imgBox.left = 82;		imgBox.right = 161;		se3.delay = 100;		se3.selection = imgBox;		se3.width = (float)abs(imgBox.right - imgBox.left);		se3.height = (float)abs(imgBox.top - imgBox.bottom);		amat3.addToSeq(se3);		// third seq, second animation		imgBox.left = 161;		imgBox.right = 225;		se3.delay = 100;		se3.selection = imgBox;		se3.width = (float)abs(imgBox.right - imgBox.left);		se3.height = (float)abs(imgBox.top - imgBox.bottom);		amat3.addToSeq(se3);		// add the animation		movType = WALKING;		amat3.setType(movType);		amat3.reset();		sh.addAnimation(amat3, movType);	}}

##### Share on other sites
Quote:
 Yeah, heh, you guys are always really good. Even when I give you little information to go on.

You shouldnt make excuses for AnonymousPoster. Hes an intolerant prick.

##### Share on other sites
Quote:
 Original post by -justin-@jfl yeah sorry, i didn't mean to sound like i was saying it was something wrong with Debug/Release mode, i know it's an error in my code but i just can't seem to find it :-/

There's no need to apologize.

That said, I cannot really tell what's going wrong with the code you posted. Considering that you are using MSVC (a modern version, I hope -- such as 2005 EE), I think your best bet would be to step through your code in the debugger. You can learn how to use the MSVC debugger in the help system (Take a look at "Debugger Roadmap" if using 2005).

jfl.

• 35
• 12
• 10
• 9
• 9
• ### Forum Statistics

• Total Topics
631355
• Total Posts
2999522
×