Issues compiling a sdl program on KOS

If you have any questions on programming, this is the place to ask them, whether you're a newbie or an experienced programmer. Discussion on programming in general is also welcome. We will help you with programming homework, but we will not do your work for you! Any porting requests must be made in Developmental Ideas.
Post Reply
Jae686
Insane DCEmu
Insane DCEmu
Posts: 112
https://www.artistsworkshop.eu/meble-kuchenne-na-wymiar-warszawa-gdzie-zamowic/
Joined: Sat Sep 22, 2007 9:43 pm
Location: Braga - Portugal
Has thanked: 0
Been thanked: 0

Issues compiling a sdl program on KOS

Post by Jae686 »

I'm using Chui's SDL, but i'm having issues at linking time.

this is what i get :

http://rafb.net/p/TYstE241.html

Any thoughts ?


Best Regards

Jae686

I believe the issue is related to the paths. "/opt/dc/kos-ports/SDL_image-1.2.4/IMG_bmp.c" does not match my enviroment.
my enviro.h matches my enviroment, so, is this path hardcoded in the libary ?

or the precompiled libaries are not enough ? (both the precompiled and source code of the libaries ? )
Stryfe
Psychotic DCEmu
Psychotic DCEmu
Posts: 577
Joined: Mon Aug 11, 2008 9:34 am
Location: Nowhere U.S.A.
Has thanked: 0
Been thanked: 0

Re: Issues compiling a sdl program on KOS

Post by Stryfe »

You could also try posing this question over at the Dreamcast.es forums, but registration is required.
ImageImageImageImage
Jae686
Insane DCEmu
Insane DCEmu
Posts: 112
Joined: Sat Sep 22, 2007 9:43 pm
Location: Braga - Portugal
Has thanked: 0
Been thanked: 0

Re: Issues compiling a sdl program on KOS

Post by Jae686 »

Stryfe wrote:You could also try posing this question over at the Dreamcast.es forums, but registration is required.
I sure will. They do have a pretty active scene!

thx!
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Re: Issues compiling a sdl program on KOS

Post by OneThirty8 »

You don't seem to have the KOS libs listed after SDL etc in the link order in the makefile you posted--you just stop with libfreetype, so unless I missed something, you don't actually have KOS linked into your program. Also, your link order is what is causing the errors with SDL_Image. Try changing this:

Code: Select all

$(TARGET): $(OBJS)
	kos-cc -o $(TARGET) $(OBJS) -lSDL -lSDL_129  -lSDL_image_124 -lm -ljpeg -lpng -lz -lfreetype
to

Code: Select all

$(TARGET): $(OBJS)
	kos-cc -o $(TARGET) $(OBJS) -lSDL_image_124 -lSDL_129 -ljpeg -lpng -lz -lm -lfreetype $(KOS_LIBS)
Jae686
Insane DCEmu
Insane DCEmu
Posts: 112
Joined: Sat Sep 22, 2007 9:43 pm
Location: Braga - Portugal
Has thanked: 0
Been thanked: 0

Re: Issues compiling a sdl program on KOS

Post by Jae686 »

It solved my problem, thank you!

My code now compiles, but when i run this code

Code: Select all

SDL_Surface *ruido(int size_x, int size_y, SDL_Surface *sur_ref) //Devolve uma surface com ruido de tamanho x,y com o mesmo formato da superficie dada
{
    
    printf("\n dentro da funcao ruido \n");
    fflush(stdout);

    SDL_Surface *bloco_ruido;
    bloco_ruido = SDL_CreateRGBSurface(SDL_HWSURFACE, size_x, size_y,sur_ref->format->BitsPerPixel,
                                       sur_ref->format->Rmask, sur_ref->format->Gmask, sur_ref->format->Bmask, sur_ref->format->Amask); // devolve a *surface

    
    if(bloco_ruido == NULL)
	{
    	printf("\n SDL_CreateRGBSurface falhou \n");
    	fflush(stdout);
	}

    if ( SDL_MUSTLOCK (bloco_ruido))
    {
        SDL_LockSurface(bloco_ruido);
    }


    //int bpp = bloco_ruido->format->BytesPerPixel;

    int i, j, yofs, ofs;

    // Draw to screen
    yofs = 0;
    for (i = 0; i < size_y ; i++)
    {
        for (j = 0, ofs = yofs; j < size_x; j++, ofs++)
        {

         ((unsigned int*)bloco_ruido->pixels)[ofs] = preto_branco(bloco_ruido);


        }
        yofs += bloco_ruido->pitch / 4;
    }

SDL_UnlockSurface(bloco_ruido);
return bloco_ruido;

}
I get (on lxdream) the following error

Code: Select all

*** ASSERTION FAILURE ***
Assertion "(old_top == initial_top(av) && old_size == 0) || ((CHUNK_SIZE_T) (old_size) >= MINSIZE && prev_inuse(old_top))" failed at malloc.c:3594 in `sYSMALLOc'
I call the above code 4 times in a row, but it crashes at the 2nd call.
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Re: Issues compiling a sdl program on KOS

Post by OneThirty8 »

SDL_CreateRGBSurface is allocating memory every time you call your ruido function. Is it possible that you're running out of memory?
Jae686
Insane DCEmu
Insane DCEmu
Posts: 112
Joined: Sat Sep 22, 2007 9:43 pm
Location: Braga - Portugal
Has thanked: 0
Been thanked: 0

Re: Issues compiling a sdl program on KOS

Post by Jae686 »

Yup, i guess that was the problem ! I was creating 4 640*480 images, plus loading some 4 320*240 images at run time. I should only load images when required instead of loading them all at the start of the program...

Thank you!

PS. Then I use the "romdisk aproach", are the files on the bootdisk placed on ram when the code is loaded ?
Can't i have a "iso9660" filesystem?
User avatar
henzenmann
Insane DCEmu
Insane DCEmu
Posts: 186
Joined: Wed Jul 12, 2006 4:58 pm
Has thanked: 0
Been thanked: 0
Contact:

Re: Issues compiling a sdl program on KOS

Post by henzenmann »

Jae686 wrote:PS. Then I use the "romdisk aproach", are the files on the bootdisk placed on ram when the code is loaded ?
Can't i have a "iso9660" filesystem?
Yes and yes:
- The romdisk image is embedded in your executable, and therefore loaded into RAM.
- You can also use an ISO filesystem.
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Re: Issues compiling a sdl program on KOS

Post by OneThirty8 »

If using a romdisk, the files that are contained in the romdisk image are in RAM at boot time, but not the files that you just have on the CD alongside your binary. The romdisk is (typically) part of your binary. You can create romdisk images to store on the CD and mount/unmount them as needed also, but if the romdisk image is mounted, its contents are in RAM.

You can use an iso9660 filesystem--that's the kind of filesystem used on the CD-R. If you know what you are doing, it is relatively easy to modify the iso9660 code that comes with KOS to create a version that will let you use an iso or bin/cue image in a way that is similar to the romdisk image, if that is what you are asking.
P@S@f
DCEmu Newbie
DCEmu Newbie
Posts: 2
Joined: Sun Dec 02, 2012 12:19 pm
Has thanked: 0
Been thanked: 0

Re: Issues compiling a sdl program on KOS

Post by P@S@f »

Where are you found SDL_image for KOS???
OneThirty8
Damn Dirty Ape
Damn Dirty Ape
Posts: 5031
Joined: Thu Nov 07, 2002 11:11 pm
Location: Saugerties, NY
Has thanked: 0
Been thanked: 0

Re: Issues compiling a sdl program on KOS

Post by OneThirty8 »

I haven't done any DC coding in a few years but if I recall correctly, SDL_Image didn't require any special trickery to work with KOS as it relies on SDL to handle the platform-specific stuff. Basically just create a new makefile for it based on the makefile for another library in the kos-ports tree and you should be on your way. But as I said, it's been years since I used SDL_Image on the Dreamcast so I could be forgetting something.
Post Reply