Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 9002461
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 16, 20262026-06-16T00:34:26+00:00 2026-06-16T00:34:26+00:00

Sprite1 *test = new Sprite1(450, 450, enemy.bmp, *screen); test->DrawJon(); SDL_Delay(1000); test->MoveJon(20,20); I am getting

  • 0
Sprite1 *test = new Sprite1(450, 450, "enemy.bmp", *screen);
    test->DrawJon();
    SDL_Delay(1000);
    test->MoveJon(20,20);

I am getting a runtime error on line #2. It says access violation at 0x0

Sprite1 is a class I have defined and DrawJon() and MoneJon() in the class. This syntax is ok with the compiler but fails in runtime.

Sprite1.cpp

#include "Sprite1.h"

Sprite1::Sprite1(int posX, int posY, std::string imagePath, SDL_Surface screen) :     PosX(posX), PosY(posY), ImagePath(imagePath), Screen(screen)
{
void DrawSprite1Jon( int x, int y, SDL_Surface *sprite, SDL_Surface *screen );
void DrawJon();
void MoveJon(int xDist, int yDist);
}

void Sprite1::DrawSprite1Jon( int x, int y, SDL_Surface *sprite, SDL_Surface *screen )
{
//Make a temporary rectangle to hold the offsets
SDL_Rect offset;

//Give the offsets to the rectangle
offset.x = x;
offset.y = y;

//Blit the surface
SDL_BlitSurface( sprite, NULL, screen, &offset );

SDL_UpdateRect(screen, 0, 0, 0, 0);
}

void Sprite1::DrawJon()
{
#pragma region Char to String Conversion

string ImagePath;
char * writable = new char[ImagePath.size() + 1];
copy(ImagePath.begin(), ImagePath.end(), writable);
writable[ImagePath.size()] = '\0';

#pragma endregion

temp = SDL_LoadBMP(writable);
sprite = SDL_DisplayFormat(temp);
SDL_FreeSurface(temp);

// free the string after using it
delete[] writable;

DrawSprite1Jon(PosX, PosY, sprite, screen);
}

Sprite1.h

#include <string>
#include <SDL.h>
#include "Functions.h"

using namespace std;

class Sprite1
{
private:
    int PosX;
    int PosY;
    int xDist;
    int yDist;
    string ImagePath;
    SDL_Surface Screen;
    SDL_Surface *temp, *sprite, *screen;

public:
    Sprite1(int PosX, int PosY, string ImagePath, SDL_Surface Screen );
    void DrawSprite1Jon( int x, int y, SDL_Surface *sprite, SDL_Surface *screen);
    void DrawJon();
    void MoveJon(int xDist, int yDist);
};

EDIT:

upon further investigation, it is this line

DrawSprite1Jon(PosX, PosY, sprite, screen);

That is failing in the DrawJon()

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-16T00:34:27+00:00Added an answer on June 16, 2026 at 12:34 am

    There were some problems with my implementation but in the end I had to build in release mode rather than debug mode.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

the following code returns the following runtime error. why? code: package { import flash.display.Sprite;
Trying to implement the new FP 10.1 Global error handler into my projects but
void spriteput(int x,int y, int stype) { char sprite1[5]=OOOO; char sprite2[5]=OOOO; char sprite3[5]=OOOO; char
I'm test SciTe editor, and Gosu for ruby game development. I decided to make
Below i have purposely made a test script: you can see it live at
I have code like this: mButton = new ButtonSprite(400 , 400, myTiledTextureRegion.getTextureRegion(0), myTiledTextureRegion.getTextureRegion(1), activity.getVertexBufferObjectManager(),
I have been developing a game in the HTML5/Javascript new canvas feature, and all
When using Javascript as follows: function Test(Example) { } Test.prototype.etc etc etc function Example()
I'm making a new game, and I want to use my own textures for
i am new to iPhone and cocos2d in general, i m reading tutorials and

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.