Click here to Skip to main content
15,884,298 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
C++
#include<iostream>
#include<glut.h>
#include "Hero.h"
#include"RGBA.h"

AnimatedSprite *hero;
AnimatedSprite *bg,*fg;
int currentAnim;
float L=0,R=480;

void display()
{ 
   hero = new AnimatedSprite("alladin2.bmp",56,90,0,0,2001);
   hero -> colorKey(255,0,255);

   bg = new AnimatedSprite("BlueBkg2.bmp",760,480,L,R,2002);
   bg -> colorKey(255,255,255);

   glEnable(GL_ALPHA_TEST);
   glAlphaFunc(GL_EQUAL,GL_ONE);
   currentAnim=hero->currentAnimState;
   hero->drawSprite();
}

void UpdateSpriteAnimation(void)
{
   int currentAnim=hero->currentAnimState;
   hero->anim[currentAnim].currentFrames = (hero->anim[currentAnim].currentFrames++);
   if(hero->currentAnimState == hero->ANIM_WALK_LEFT)
   {
      if(hero->x >= L && hero->x <= R-10)
         hero->x -= 1.0;

      bg->anim[0].u -= 0.005;
      fg->anim[0].u -= 0.002;
   }

   if(hero->currentAnimState == hero->ANIM_WALK_RIGHT)
   {
      if(hero->x < R)
         hero->x += 1.0;

      bg->anim[0].u -= 0.005;
      fg->anim[0].u -= 0.002;
   }
}

void myTimer (int tt)
{
   UpdateSpriteAnimation();
   glutPostRedisplay();
   glutTimerFunc(hero->FRAME_DELAY_SPRITE,myTimer,0);
}

void main(int argc, char **argv)
{
   glutInit(&argc,argv);
   glutInitDisplayMode(GLUT_SINGLE | GLUT_RGBA | GLUT_DEPTH);
   glutInitWindowSize(640, 480);
   glutInitWindowPosition(10, 10);
   glutCreateWindow("Sprites Sheet");
  
   glutDisplayFunc(display);
   glutDisplayFunc(UpdateSpriteAnimation);

   // glutIdleFunc(display);
   glutTimerFunc(500,myTimer,1);
   glutMainLoop();
}


The break error occured
Unhandled exception at 0x00F76513 0xC0000005:
please help out
Posted
Updated 31-Aug-14 2:55am
v2
Comments
OriginalGriff 31-Aug-14 8:27am    
Where?
It might be rather relevant, don't you think?
Have you tried using the debugger?
Member 11048368 31-Aug-14 8:30am    
It occured at the start of updatespriteanimation function definition....Yes i try debugger but the isse is not resloved
[no name] 31-Aug-14 8:40am    
Looks like you have a bad pointer.

1 solution

"It occured at the start of updatespriteanimation function definition....Yes i try debugger but the isse is not resloved"

This isn't something we can solve for you: it needs the code running with your environment.
So if it occurs at the start of the function, then you need to use the debugger to look at what holds an invalid value.

I'd start by assuming it's hero - and that the problem is possibly that the timer function is being called before the display function: but without seeing your code running there is no way to be sure.

So check: use the debugger and look at what values you have. What is sensible? What isn't? what was holding the invalid value the error talks about?
Without knowing that, nobody can fix this without guessing - and that isn't good. And the only person who can find out - is you...
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900