Code error, help pls

Helo!

        Last week i finished a tutorial about sprites and animations

with SDL.
The program compiles perfectly, but it throws an output error (Fatal signal:
Segmentation Fault (SDL Parachute Deployed). As i have seen this is a common
error message in SDL so it was a little hard to find it.

As i know (or i think i do) what the error is, i have been modifying the
code, trying to solve it. I must say that im not posting this mail as my
first solution, as i have been almost this two weeks trying to modify the
code in all ways to solve it, but as i cant repair it, i ask you for help.
Also, i didnt find a response from the autor of that tutorial, he never
replied. And I didnt found posts on forums about this.

Welll… the error (Full code at the end of the message)

I have a class called “SCspriteBase”, and a structure CSpriteFrame (public
class) wich is a class helper.
In this CSpriteBase class i will make new space for an array of
"CSpriteFrame"s.
This CSpriteFrames struct will hold all the images of a sprite animation.

struct CSpriteFrame // Class - Helper
{
SDL_Surface *frame_img; // Fram’s image
int pause;
};

class CSpriteBase
{
public:
int init(char *dir); // no class constructor. A init function instead.
CSpriteFrame *sAnim;

  int mNumframes, mBuilt, mW, mH;

};

In the “CSpriteBase::init” function i do this in some place:

sAnim = new CSpriteFrame[number];

Well, as I THINK, the error is that, as i dont have a Class constructor -
destructor, where i can say “delete [] sAnim”. Those spaces reserved in
memory will never be freed.

I tryed all… i made again the class with a constructor and destructor, and
nothing. I tryed using “delete [] sAnim” inside the class, outside,
everywhere, and nothing.
I changed the code so may times with no results… it will ALWAYS compile,
but never run…
May be im confused and it is not a error about C++ or SDL implementation on
this program, i just dont know what else to do here.
Or may be I write the constructor-destructor de bad way when i tried to.

If someone can give me a TIP at list, it will be really apretiated.

THANKS A LOT IN ADVANTAGE!

If it helps, the tutorial is this one:
http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/tut3

Here is the full code:
(NOTE: You will may be see some “disorganization” in my code… but its just
becouse i changed it lots of times trying to solve the problem.)

-------------------------------- the code -------------------------------

#include
#include <stdlib.h>
#include "SDL/SDL.h"
using namespace std;

// ------------------------- GLOBAL VARIABLES (BEFORE CLASSES)

SDL_Surface *screen, *back;

// ------------------------- NON-CLASS FUNCTIONS

SDL_Surface * ImageLoad(char *file)
{
SDL_Surface *tmp1, *tmp2;

        tmp1 = SDL_LoadBMP(file);
        tmp2 = SDL_DisplayFormat(tmp1);
        SDL_FreeSurface(tmp1);

        return tmp2;

}

int LoadBG()
{
back = ImageLoad(“data/bg.gmp”);
return 0;
}

void DrawIMG(SDL_Surface *img, int x, int y)
{
SDL_Rect dest;
dest.x = x;
dest.y = y;

 SDL_BlitSurface(img, NULL, screen, &dest);

}

void DrawBG()
{
DrawIMG(back, 0, 0);
}
// -------------------------END OF NON-CLASS FUNCTIONS

// -------------------------CLASESSES
struct CSpriteFrame // Class - Helper
{
SDL_Surface *frame_img; // A FRAME IMAGE
int pause;
};

class CSpriteBase
{
public:
int init(char *dir);
CSpriteFrame *sAnim;

  int mNumframes, mBuilt, mW, mH;

};

class CSprite
{
int mFrame;
int mX, mY, mOldX, mOldY;
int mAnimating;
int mDrawn;
float mSpeed;
long mLastupdate;
CSpriteBase *mSpriteBase;
SDL_Surface *mBackreplacement;
SDL_Surface *mScreen;

public:
// CSprite CLASS-FUNCTIONS Declaration.

   int init(CSpriteBase *base, SDL_Surface *screen); // inicializacion

del objecto.
void draw(); // Dibujar objeto en supersficie.
void ClearBG(); // Limpiar el fondo del sprite.
void UpdateBG(); // Actualizar el FONDO del sprite.

   // Currently displaying frame CONTROL

   void setFrame(int fn) { mFrame = fn; }
   int getFrame() { return mFrame; }

   // SPEED Control

   void setSpeed(float sn) { mSpeed = sn; }
   float getSpeed() { return mSpeed; }

   // ANIMATION Control

   void TogAnim() { mAnimating = !mAnimating; }
   void startAnim() { mAnimating = 1; }
   void stopAnim() { mAnimating = 0; }
   void rewind() { mFrame = 0; }

   // SCREEN Positioning of Sprites CONTROL

   void xadd(int nm) { mX+=nm; }
   void yadd(int nm) { mY+=nm; }
   void xset(int nm) { mX=nm; }
   void yset(int nm) { mY=nm; }
   void set(int nx, int ny) { mX = nx; mY = ny; }

};

// ------------------------- CLASS FUNCTIONS

// Function “init” of class CSpriteBase.
int CSpriteBase::init(char *dir)
{
char buffer[255]; // Buffer para guardar lineas del archivo de datos
char filename[50]; // Archivo de datos
char name_bmp[15]; // Archivo BMP de la frame
int pause=0,r=0,g=0,b=0;
FILE *fp;

sprintf(filename, "%s/info", dir);

if ((fp=fopen(filename, "r")) == NULL)
{
   cout <<"Error abriendo archivo de datos: %s" << filename << endl;
   return -1;
}

// Tomamos la primer linea, asi sabemos la cantidad de FRAMES de esta

animacion

fgets(buffer,255,fp);
sscanf(buffer, "FILES: %d", &mNumframes);

sAnim = new CSpriteFrame[mNumframes]; // Hacemos espacio para el sAnim

de este sprite.

mBuilt = 1;
int count = 0;

while (!feof(fp) && count < mNumframes)
{
      fgets(buffer, 255, fp);

      if (buffer[0] != '#' && buffer[0] != '\r' && buffer[0] != '\n' &&

buffer[0] != 0 && buffer[0] != ‘\0’)
{
sscanf(buffer, “%s %d %d %d %d”, name_bmp, &pause, &r, &g, &b);
// datos de la frame
sprintf(filename, “%s/%s”, dir, name_bmp);

         SDL_Surface *temporal;

         if ((temporal = SDL_LoadBMP(filename)) == NULL) // Cargamos la

frame en cuestion.
{
cout << "Error cargando frame: " << count+1 << endl <<
"archivo: "<<filename<<endl;
return -1;
}

         if (r>=0)
            SDL_SetColorKey (temporal, SDL_SRCCOLORKEY,

SDL_MapRGB(temporal->format, r,g,b) );

         sAnim[count].frame_img = SDL_DisplayFormat(temporal);
         SDL_FreeSurface(temporal);

         sAnim[count].pause = pause;

         if (!mW) mW = sAnim[count].frame_img->w;
         if (!mH) mH = sAnim[count].frame_img->h;

         count++;
      } // End If
}  // End While

fclose(fp);
return 0;

} // END of CSpriteBase::init function !

// CSprite CLASS functions

// CSprite::init()

int CSprite::init (CSpriteBase *base, SDL_Surface *screen)
{
mSpriteBase = base;

if (mSpriteBase->mBuilt)
{
   if (mSpriteBase->mNumframes > 1)
   {
      mAnimating = 1;
      mBackreplacement =

SDL_DisplayFormat(mSpriteBase->sAnim[0].frame_img);
}
mScreen = screen;
}
return 0;
} // END of CSprite::init(); FUNCTION

// Funcion UpdateBG() de la clase CSprite.

void CSprite::UpdateBG()
{
SDL_Rect srcrect;
srcrect.x = mX;
srcrect.y = mY;
srcrect.w = mSpriteBase->mW;
srcrect.h = mSpriteBase->mH;
mOldX = mX;
mOldY = mY;

 SDL_BlitSurface(mScreen, &srcrect, mBackreplacement, NULL);

} // FIN CSprite::ClearBG();

// Funcion draw() de la clase CSprite

void CSprite::draw()
{
if (mAnimating == 1)
{
if (mLastupdate + mSpriteBase->sAnim[mFrame].pause * mSpeed <
SDL_GetTicks() );
{
mFrame++;
if (mFrame > mSpriteBase->mNumframes -1)
mFrame = 0;

       mLastupdate = SDL_GetTicks();
    }
}

if (mDrawn == 0) mDrawn = 1;

SDL_Rect dest;
dest.x = mX;
dest.y = mY;
SDL_BlitSurface(mSpriteBase->sAnim[mFrame].frame_img, NULL, mScreen,

&dest);
} // FIN CSprite::draw();

// Funcion ClearBG() de la clase CSprite.
void CSprite::ClearBG()
{
if (mDrawn == 1)
{
SDL_Rect dest;
dest.x = mOldX;
dest.y = mOldY;
dest.w = mSpriteBase->mW;
dest.h = mSpriteBase->mH;
SDL_BlitSurface(mBackreplacement, NULL, mScreen, &dest);

  }

} // FIN funcion CSprite::ClearBG();

// ------------------------- POST-Class Global Variables

// Post-Class : Variables GLOBALES.
CSpriteBase vikingsbase, sunbase;
CSprite vikings1, vikings2, sun;

// Post-Class : Functions.
void MostrarEscena()
{
sun.ClearBG();
vikings1.ClearBG();
vikings2.ClearBG();

 sun.UpdateBG();
 vikings1.UpdateBG();
 vikings2.UpdateBG();

 sun.draw();
 vikings1.draw();
 vikings2.draw();

 SDL_Flip(screen);

}

// ------------------------- MAIN FUNCTION
int main(int argc, char *argv[])
{

  Uint8* keys;

  if (SDL_Init(SDL_INIT_VIDEO) < 0 )
  {
     cout << "Error iniciando video: "<< SDL_GetError() <<endl;
     return 1;
  }
  atexit(SDL_Quit);

  screen = SDL_SetVideoMode(640, 480, 16, SDL_SWSURFACE|SDL_HWPALETTE);

  if (screen == NULL)
  {
     cout << "Error inicializando pantalla primaria: "<<

SDL_GetError()<< endl;
return 1;
}

  // inicamos nuestras clases
  vikingsbase.init("data/vikings");
  sunbase.init("data/vun");

  // iniciamos nuestras clases de objetos
  sun.init(&sunbase, screen);
  sun.set(480, 50);
  sun.setSpeed(1);

  vikings1.init(&vikingsbase, screen);
  vikings1.set(150, 300);
  vikings1.setSpeed(1);

  vikings2.init(&vikingsbase, screen);
  vikings2.set(350,300);
  vikings2.setSpeed(1.5);

  SDL_ShowCursor(0);

  LoadBG();
  DrawBG();



  int done = 0;
  SDL_Event salir;

  while (done == 0)
  {
        while (SDL_PollEvent(&salir))
        {
              if (salir.type == SDL_QUIT) {done = 1;}
              if (salir.type == SDL_KEYDOWN)
              {
                 if (salir.key.keysym.sym == SDLK_ESCAPE) { done = 1; }
                 if (salir.key.keysym.sym == SDLK_SPACE)

sun.TogAnim(); }
}
}

  keys = SDL_GetKeyState(NULL);

  if ( keys[SDLK_UP] ) { vikings1.yadd(-1); }
  if ( keys[SDLK_DOWN] ) { vikings1.yadd(1); }
  if ( keys[SDLK_LEFT] ) { vikings1.xadd(-1); }
  if ( keys[SDLK_RIGHT] ) { vikings1.xadd(1); }

  MostrarEscena();

  } DONE = 1


  return 0;

}

                                               Eduardo Garcia Rajo (h)------------------------------------------------------------------

Visite: http://www.solucion-digital.com.ar
SOLUCION DIGITAL
Redes - Software - Servicios

Hi,

First thing to do is to temporarily disable the SDL parachute
so that you get a real exception with (hopefully) a traceback:

if (SDL_Init(SDL_INIT_VIDEO|SDL_INIT_NOPARACHUTE) < 0 )
{
cout << "Error iniciando video: "<< SDL_GetError() <<endl;
return 1;
}

You aren’t testing your return values where you need too e.g.

// inicamos nuestras clases
if ( vikingsbase.init(“data/vikings”) != 0 )
return 1;

Shouldn’t this be an ‘s’ for ‘sun’?

if ( sunbase.init(“data/vun”) != 0 )
return 1;
--------------------------^

When I run your original, the code hurtles-on-through these lines
even though they return an error (data files not found) and later
I get an exception here:

SDL_Surface * ImageLoad(char *file)
{
SDL_Surface *tmp1, *tmp2;

tmp1 = SDL_LoadBMP(file);
tmp2 = SDL_DisplayFormat(tmp1); // <-- tmp1 can be NULL
SDL_FreeSurface(tmp1);
return tmp2;
}

because ‘file’ doesn’t exist, and you don’t check tmp1 after calling
SDL_LoadBMP().

Try something like:

SDL_Surface * ImageLoad(char *file)
{
SDL_Surface *tmp1, *tmp2 = NULL;

tmp1 = SDL_LoadBMP(file);
if ( tmp1 )
{
tmp2 = SDL_DisplayFormat(tmp1);
SDL_FreeSurface(tmp1);
}
return tmp2;
}

and of course you should always check the return value from
this function:

int LoadBG()
{
back = ImageLoad(“data/bg.gmp”); <-- should be checking this
return 0;
}

Try something like this:

int LoadBG()
{
if ( (back = ImageLoad(“data/bg.gmp”)) == NULL )
return -1;
return 0;
}

Check the return value:


if ( LoadBG() != 0 )
{
cout << “Failed to load background.” << endl;
}

At this point it started working for me - I think your main
problem was this:

-----------------------------v
if ( sunbase.init(“data/vun”) != 0 )
if ( sunbase.init(“data/sun”) != 0 )
-----------------------------^

compounded by *** not checking return values ***.

Switch your compiler warnings on full.
I did and found this:

void CSprite::draw()
{
if (mAnimating == 1)
{
if (mLastupdate + mSpriteBase->sAnim[mFrame].pause * mSpeed <
SDL_GetTicks() ); // <— this ‘;’ shouldn’t be here
{
… // the code in here is executed every time !!!
}
}

} // FIN CSprite::draw();

There are some other crappy bits of C/C++ coding in there, but I
guess you will tidy these up later.

You appear to have been on a wild goose chase after a red herring!

Better luck with the rest of it,

cheers,
John.> ----- Original Message -----

From: quaker@advancedsl.com.ar (eDU)
To:
Sent: Saturday, May 31, 2003 9:01 PM
Subject: [SDL] Code error, help pls

Helo!

        Last week i finished a tutorial about sprites and animations

with SDL.
The program compiles perfectly, but it throws an output error (Fatal
signal:
Segmentation Fault (SDL Parachute Deployed). As i have seen this is a
common
error message in SDL so it was a little hard to find it.

As i know (or i think i do) what the error is, i have been modifying the
code, trying to solve it. I must say that im not posting this mail as my
first solution, as i have been almost this two weeks trying to modify the
code in all ways to solve it, but as i cant repair it, i ask you for help.
Also, i didnt find a response from the autor of that tutorial, he never
replied. And I didnt found posts on forums about this.

Welll… the error (Full code at the end of the message)

I have a class called “SCspriteBase”, and a structure CSpriteFrame (public
class) wich is a class helper.
In this CSpriteBase class i will make new space for an array of
"CSpriteFrame"s.
This CSpriteFrames struct will hold all the images of a sprite animation.

struct CSpriteFrame // Class - Helper
{
SDL_Surface *frame_img; // Fram’s image
int pause;
};

class CSpriteBase
{
public:
int init(char *dir); // no class constructor. A init function
instead.
CSpriteFrame *sAnim;

  int mNumframes, mBuilt, mW, mH;

};

In the “CSpriteBase::init” function i do this in some place:

sAnim = new CSpriteFrame[number];

Well, as I THINK, the error is that, as i dont have a Class constructor -
destructor, where i can say “delete [] sAnim”. Those spaces reserved in
memory will never be freed.

I tryed all… i made again the class with a constructor and destructor,
and
nothing. I tryed using “delete [] sAnim” inside the class, outside,
everywhere, and nothing.
I changed the code so may times with no results… it will ALWAYS compile,
but never run…
May be im confused and it is not a error about C++ or SDL implementation
on
this program, i just dont know what else to do here.
Or may be I write the constructor-destructor de bad way when i tried to.

If someone can give me a TIP at list, it will be really apretiated.

THANKS A LOT IN ADVANTAGE!

If it helps, the tutorial is this one:
http://cone3d.gamedev.net/cgi-bin/index.pl?page=tutorials/gfxsdl/tut3

Here is the full code:
(NOTE: You will may be see some “disorganization” in my code… but its
just
becouse i changed it lots of times trying to solve the problem.)

-------------------------------- the code ------------------------------
[snipped]

                                               Eduardo Garcia Rajo (h)

Visite: http://www.solucion-digital.com.ar
SOLUCION DIGITAL
Redes - Software - Servicios


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

Jhon thanks you very much for your help :slight_smile:

I used “vun” instead of “sun”, becouse if i use “char_directory/sun” the
compiler “thinks” that …/sun is a “…/s…” and wont compile.

I will rewrite those parts you told me. I really thought that the error was
about the array of frames, and not deleteing it.

THANKS you again!!

                                                       Eduardo Garcia

Rajo (h)------------------------------------------------------------------
Visite: http://www.solucion-digital.com.ar
SOLUCION DIGITAL
Redes - Software - Servicios

----- Original Message -----
From: john@johnnypops.demon.co.uk (John Popplewell)
To:
Sent: Sunday, June 01, 2003 12:56 AM
Subject: Re: [SDL] Code error, help pls

hey eDU,

/sun should be fine, \sun is what might give you troubles. You can try
\sun if you want cause \ turns into \ inside a string so that you dont
have problems like you are experiencing.

-Atrix> ----- Original Message -----

From: quaker@advancedsl.com.ar (eDU)
To:
Sent: Sunday, June 01, 2003 9:32 AM
Subject: RE: [SDL] Code error, help pls

Jhon thanks you very much for your help :slight_smile:

I used “vun” instead of “sun”, becouse if i use “char_directory/sun” the
compiler “thinks” that …/sun is a “…/s…” and wont compile.

I will rewrite those parts you told me. I really thought that the error
was
about the array of frames, and not deleteing it.

THANKS you again!!

                                                       Eduardo Garcia

Rajo (h)

Visite: http://www.solucion-digital.com.ar
SOLUCION DIGITAL
Redes - Software - Servicios

----- Original Message -----
From: John Popplewell
To:
Sent: Sunday, June 01, 2003 12:56 AM
Subject: Re: [SDL] Code error, help pls


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I will rewrite those parts you told me. I really thought that the error was
about the array of frames, and not deleteing it.

Not freeing allocated memory will not cause a segmentation fault. You get
a segmentation fault when you write to memory you don’t own (or a NULL
pointer).

John’s review of your code was very detailed, but I just wanted to throw
this in there: The sooner you learn to use the debugger, the easier the
job becomes.

Get the “GDB” manual, learn how to interpret a “backtrace” when the
program crashes with a Segmentation Fault. Frequently, this is all you
need to diagnose a problem within seconds. Following that, learn how to
examine data with the debugger, which will help with the rest of the
crashes.

Other development tools, like Visual C on Windows, look different, but
follow the same principles when debugging.

Being an effective debugger is more important than being a competent
programmer, trust me. Pick up this skill as quickly as you can.

–ryan.

Hehe… printf() can be pretty ‘effective’ ;^)

-bill!
(who obviously doesn’t play with GDB enough; recommend any good tutorials?)On Sun, Jun 01, 2003 at 05:34:59PM -0400, Ryan C. Gordon wrote:

Being an effective debugger is more important than being a competent
programmer, trust me. Pick up this skill as quickly as you can.

Yes - especially when you have a bug that thrashes the stack before
you get a segfault. :slight_smile:

//David Olofson - Programmer, Composer, Open Source Advocate

.- The Return of Audiality! --------------------------------.
| Free/Open Source Audio Engine for use in Games or Studio. |
| RT and off-line synth. Scripting. Sample accurate timing. |
`-----------------------------------> http://audiality.org -’
http://olofson.nethttp://www.reologica.se —On Monday 02 June 2003 00.26, Bill Kendrick wrote:

On Sun, Jun 01, 2003 at 05:34:59PM -0400, Ryan C. Gordon wrote:

Being an effective debugger is more important than being a
competent programmer, trust me. Pick up this skill as quickly as
you can.

Hehe… printf() can be pretty ‘effective’ ;^)

ahhh… what an idiot i didnt think about that :open_mouth:

I remember that i used that for printing with printf something like
" Helo \ Wold" :slight_smile:

Thanks Attrix !
Eduardo Garcia Rajo (h)------------------------------------------------------------------
Visite: http://www.solucion-digital.com.ar
SOLUCION DIGITAL
Redes - Software - Servicios

----- Original Message -----
From: atrix2@cox.net (atrix2)
To:
Sent: Sunday, June 01, 2003 1:47 PM
Subject: Re: [SDL] Code error, help pls

Ryan THANKS for your reply.

I have been told already to debug my programs, but i never had the time to
learn as my emotion of makeing someting run is bigger (a common newbie
problem :slight_smile:

But well, you are VERY right there. I have found some information about GDB,
it also came with the IDE i downloaded (DevCPP) so im studying it :wink:

Thanks !

                                                   Eduardo Garcia Rajo

(h)------------------------------------------------------------------
Visite: http://www.solucion-digital.com.ar
SOLUCION DIGITAL
Redes - Software - Servicios

----- Original Message -----
From: icculus@icculus.org (Ryan C. Gordon)
To:
Sent: Sunday, June 01, 2003 6:34 PM
Subject: RE: [SDL] Code error, help pls

I will rewrite those parts you told me. I really thought that the error
was

about the array of frames, and not deleteing it.

Not freeing allocated memory will not cause a segmentation fault. You get
a segmentation fault when you write to memory you don’t own (or a NULL
pointer).

John’s review of your code was very detailed, but I just wanted to throw
this in there: The sooner you learn to use the debugger, the easier the
job becomes.

Get the “GDB” manual, learn how to interpret a “backtrace” when the
program crashes with a Segmentation Fault. Frequently, this is all you
need to diagnose a problem within seconds. Following that, learn how to
examine data with the debugger, which will help with the rest of the
crashes.

Other development tools, like Visual C on Windows, look different, but
follow the same principles when debugging.

Being an effective debugger is more important than being a competent
programmer, trust me. Pick up this skill as quickly as you can.

–ryan.


SDL mailing list
SDL at libsdl.org
http://www.libsdl.org/mailman/listinfo/sdl

I recently discovered that the source code for Duke Nukem 3D has been
released and ported to Linux using SDL, where it reportedly works
very well. I’m trying to port it to FreeBSD, but it’s unplayably slow
on my 1.3Ghz system with plenty of free RAM. Other SDL games such as
prboom, heretic, and gltron run very fast.

I’ve tried profiling the code with gprof, and it doesn’t show anything
unusual. Most of the CPU time was spent in a routine that copies the
graphics line-by-line to the screen, so I changed that routine to only
run the loop once, instead of 600 times (for a 800x600 screen).
Profiling showed that routine’s time dropping to nothing, yet the game
ran just as slowly, so the bottleneck doesn’t appear to be in the game
code.

When I do my profiling, gprof only tells me about the routines in the
game code. Is it possible to profile the SDL routines that are being
used as well? Any other suggestions? There seems to be a specific
problem with the combination of FreeBSD, SDL, and this game, but I’m
lost as to what it could be.

Thanks,–
Aaron
@Aaron_Baugher

When I do my profiling, gprof only tells me about the routines in the
game code. Is it possible to profile the SDL routines that are being
used as well? Any other suggestions? There seems to be a specific
problem with the combination of FreeBSD, SDL, and this game, but I’m
lost as to what it could be.

  1. Lower your resolution. Blitting (say) 1024x768 to the screen every
    frame is expensive, even on high-end hardware. This is done in the
    duke3d.cfg file.

  2. Set your color depth to 8 bits (just to try it). Converting the game
    from 8 bits to whatever your screen is using is expensive, too.

  3. export the environment variable BUILD_SDLDEBUG=filename.txt and run the
    game, and see if anything interesting is spit out. (“filename.txt” can be
    "-" for stdout).

  4. Make sure you’ve got the MIT SHM extension for X11. Without this,
    regular GUI stuff will run fine, but games like duke3d will not.

  5. Try running on a different target (is there an fbcon equivalent for
    FreeBSD)?

With the exception of #3, this is all general good SDL advice, but this
will probably become off-topic quickly.

–ryan.

“Ryan C. Gordon” writes:

  1. Lower your resolution. Blitting (say) 1024x768 to the screen
    every frame is expensive, even on high-end hardware. This is done in
    the duke3d.cfg file.

I tried dropping it down to 640x480 and 320x240. No improvement.

  1. Set your color depth to 8 bits (just to try it). Converting the
    game from 8 bits to whatever your screen is using is expensive, too.

Tried this one too. Seemed to speed things up slightly, but not much.

  1. export the environment variable BUILD_SDLDEBUG=filename.txt and
    run the game, and see if anything interesting is spit
    out. (“filename.txt” can be “-” for stdout).
  1. Make sure you’ve got the MIT SHM extension for X11. Without this,
    regular GUI stuff will run fine, but games like duke3d will not.
  1. Try running on a different target (is there an fbcon equivalent
    for FreeBSD)?

With the exception of #3, this is all general good SDL advice, but
this will probably become off-topic quickly.

Thanks, I’ll check out all those.–
Aaron
@Aaron_Baugher

It works on RedHat7.2 except for sound. The sound is really ratty, seems like
the channels are being overdriven. Anyone know how to fix this?

JOn Monday 02 June 2003 05:17 am, you wrote:

I recently discovered that the source code for Duke Nukem 3D has been
released and ported to Linux using SDL, where it reportedly works
very well.

j_post <j_post at pacbell.net> writes:> On Monday 02 June 2003 05:17 am, you wrote:

I recently discovered that the source code for Duke Nukem 3D has
been released and ported to Linux using SDL, where it reportedly
works very well.

It works on RedHat7.2 except for sound. The sound is really ratty,
seems like the channels are being overdriven. Anyone know how to fix
this?

I fixed my sound by editing DUKE3D.CFG like this, which I got from the
3drealms forum:

[Sound Setup]
FXDevice = 6
MusicDevice = 6
FXVolume = 220
MusicVolume = 136
NumVoices = 8
NumChannels = 2
NumBits = 16
MixRate = 11025

I don’t think those settings actually match my sound card, but they
match whatever SDL needs to get.


Aaron
@Aaron_Baugher

Yep, that did it. Thanks very much.
JOn Tuesday 03 June 2003 04:20 am, Aaron wrote:

I fixed my sound by editing DUKE3D.CFG like this, which I got from the
3drealms forum:

[Sound Setup]
FXDevice = 6
MusicDevice = 6
FXVolume = 220
MusicVolume = 136
NumVoices = 8
NumChannels = 2
NumBits = 16
MixRate = 11025

I don’t think those settings actually match my sound card, but they
match whatever SDL needs to get.

It works on RedHat7.2 except for sound. The sound is really ratty, seems like
the channels are being overdriven. Anyone know how to fix this?

“Overdriven”?

Make sure you aren’t using esd or arts.

–ryan.

Yeah, haven’t you ever heard an overdriven amplifier? Turns sine waves into
square waves; sounds terrible. Anyway, see Aaron Baugher’s reply: editing the
duke3d.cfg file set things right.

JOn Tuesday 03 June 2003 07:21 am, Ryan wrote:

“Overdriven”?

“Ryan C. Gordon” writes:

  1. export the environment variable BUILD_SDLDEBUG=filename.txt and
    run the game, and see if anything interesting is spit
    out. (“filename.txt” can be “-” for stdout).

Since the output’s fairly short, I’ll paste it here. See anything
that doesn’t look right? It’s doing software rendering, but I assume
that the other games like prboom and heretic are using that as well.--------------------------------------------------------------------
BUILDSDL: SDL display driver for the BUILD engine initializing.
BUILDSDL: sdl_driver.c by Ryan C. Gordon
BUILDSDL: Compiled May 30 2003 against SDL version 1.2.5 …
BUILDSDL: Linked SDL version is 1.2.5 …
BUILDSDL: Using BUILD renderer “RENDERER_SOFTWARE”.
BUILDSDL: Using SDL video driver “x11”.
BUILDSDL: Initializing SDL joystick subsystem…
BUILDSDL: (export environment variable BUILD_SDLJOYSTICK=none to skip)
BUILDSDL: SDL sees 0 joysticks.
BUILDSDL: Adding standard resolution (320x200).
BUILDSDL: Adding standard resolution (320x240).
BUILDSDL: Adding standard resolution (640x350).
BUILDSDL: Adding standard resolution (640x480).
BUILDSDL: Adding standard resolution (800x600).
BUILDSDL: Adding standard resolution (1024x768).
BUILDSDL: Highest physical resolution is (1280x1024).
BUILDSDL: Adding physical resolution (1280x1024).
BUILDSDL: Adding physical resolution (800x600).
BUILDSDL: Adding physical resolution (640x480).
BUILDSDL: Adding physical resolution (320x240).
BUILDSDL: Setting resolution ceiling to (1600x1200).
BUILDSDL: Removing resolution #9, 320x240 [duplicate].
BUILDSDL: Removing resolution #8, 640x480 [duplicate].
BUILDSDL: Removing resolution #7, 800x600 [duplicate].
BUILDSDL: Final sorted modelist: (320x200) (320x240) (640x350) (640x480)
(800x600) (1024x768) (1280x1024)
BUILDSDL: screen surface is (800x600x8bpp).
BUILDSDL: New vidmode flags: SDL_HWPALETTE SDL_FULLSCREEN
BUILDSDL: hardware surface available: {false}
BUILDSDL: window manager available: {true}
BUILDSDL: accelerated hardware->hardware blits: {false}
BUILDSDL: accelerated hardware->hardware colorkey blits: {false}
BUILDSDL: accelerated hardware->hardware alpha blits: {false}
BUILDSDL: accelerated software->hardware blits: {false}
BUILDSDL: accelerated software->hardware colorkey blits: {false}
BUILDSDL: accelerated software->hardware alpha blits: {false}
BUILDSDL: accelerated color fills: {false}
BUILDSDL: video memory: (0)

  1. Make sure you’ve got the MIT SHM extension for X11. Without this,
    regular GUI stuff will run fine, but games like duke3d will not.

Check. It’s not in the FreeBSD kernel by default, but I compiled it
in for something else.

  1. Try running on a different target (is there an fbcon equivalent
    for FreeBSD)?

No fbcon, but there’s something called ‘libvgl’ that looks similar.
Don’t know anything about it, but I’ll check that out if nothing else
pans out.

Thanks,

Aaron
@Aaron_Baugher