Author Topic: Noob 2 - The Missing Link  (Read 4364 times)

Stoop Solo (OP)

  • Posts: 11
Noob 2 - The Missing Link
« on: February 10, 2012, 05:52:13 am »
Hello again, good people. I return, cap in hand, hoping for enlightenment from those with considerably more experience than I. Which would probably be all of you.

After getting a test SDL cpp application to compile and run on dingux, I wanted to move to the next stage and try compiling a cpp program with more than one source file. As this post might allude, it is not meeting with success.

Basically, I took my test program (which worked), and split the screen fill from the main.cpp to a function in a separate source, testlink.h/testlink.cpp. The result compiles and runs in codeblocks. I then took the sources and header into the cygwin toolchain and modified the makefile.

The compiler seems to build the .o files with no problem, and seems to link them at the end, but the resulting .dge file seems to just crash on dingux. It looks like it sets the screen mode, and I briefly see the black SDL mouse pointer, so I'm assuming the problem occurs when it tries to access the function in testlink and that I haven't done the linking properly in the makefile. Please could someone enlighten me as to the terrible noob error have I committed?

Here are the sources, header and makefile I'm using for this test:

Code: [Select]
#include <SDL.h>
#include <SDL_image.h>
#include "testlink.h"
//initialize screen
SDL_Surface *screenbuffer = NULL;
//misc variables for general stuff
int swidth = 320;
int sheight = 240;
int looprun = 1;
int filloff = 0;
int main ( int argc, char* args[] )
    //initialize SDL and create a screenbuffer surface
    screenbuffer = SDL_SetVideoMode (swidth, sheight, 0, SDL_ANYFORMAT | SDL_FULLSCREEN );
                while (looprun)
        //Some stuff to fill the background.
        SDL_LockSurface (screenbuffer);
        Uint32 *pixels = (Uint32 *)screenbuffer->pixels;
        fillscreen ( pixels, swidth, sheight, filloff );
        filloff = ( filloff + 1 ) & 0xFF;

       //let's checking events with me!!
        SDL_Event event;
        if( SDL_PollEvent (&event) )
        //There was an event
                  //it was a key press. End the program loop this cycle.
                   if( event.type == SDL_KEYDOWN ) looprun = 0;

        //refresh the screen buffer.
        SDL_UpdateRect (screenbuffer, 0, 0, swidth, sheight);

        return 0;

Code: [Select]

void fillscreen ( Uint32* pixelarray, int canwidth, int canheight, int filloffset );


Code: [Select]
#include "SDL.h"
#include "testlink.h"
void fillscreen ( Uint32* pixelarray, int canwidth, int canheight, int filloffset )
        int xfill = 0;
        int yfill = 0;
        int buffersize = canwidth * canheight;
        for (int xall = 0; xall < buffersize; xall++)
            pixelarray[ xfill + yfill ] = xfill+filloffset;
            if (xfill++ == canwidth)
                   yfill = yfill + canwidth;
                   xfill = 0;

and finally, the makefile:
Code: [Select]
INCLUDES := -I${TOOLCHAINDIR}/mipsel-linux-uclibc/include/SDL
ARCH    := mipsel-linux-uclibc-
CC        := ${BINPATH}/$(ARCH)gcc
CXX      := ${BINPATH}/$(ARCH)g++
CFLAGS  := -O2 -Wall $(INCLUDES) $(shell $(BINPATH)/sdl-config --cflags)
CXXFLAGS:= -O2 -Wall $(INCLUDES) $(shell $(BINPATH)/sdl-config --cflags)
LDFLAGS := -O2 -Wall $(shell $(BINPATH)/sdl-config --libs) -lSDL_gfx -lSDL_image
                $(CXX) $(CXXFLAGS) -mips32 $(INCLUDES) -c testlink.cpp -o testlink.o
                $(CXX) $(CXXFLAGS) -mips32 $(INCLUDES) -c main.cpp -o main.o
                $(CXX) testlink.o main.o $(LDFLAGS) -o dingoolink.dge


  • Posts: 365
Re: Noob 2 - The Missing Link
« Reply #1 on: February 10, 2012, 06:00:33 pm »
I tested those files with opendingux-toolchain and find out two things in source files that made it fail (segmentation fault):

- Init only the things you need, use SDL_INIT_VIDEO if you only want use SDL for drawing. For all the SDL_INIT_* look here, and use the or command to initialize more than one.

- Set VideoMode to 16 bpp o 8bpp, and use Uint16* or Uint8* instead of Uint32*. OpenDingux (and legacy) only support 8 or 16 bits for color depth.

With those changes I got it working on OpenDingux, maybe for legacy you need something more. In GMenu2X, in the "Settings" tab is a "Log viewer", you can see the things that the last app wrote to stderr, use that for debugging.

Stoop Solo (OP)

  • Posts: 11
Re: Noob 2 - The Missing Link
« Reply #2 on: February 10, 2012, 07:32:34 pm »
Hey DiegoSLTS, Thanks a lot for looking at that.

Interesting that there was a segfault from that. When I had that exact program as one source, it ran on original Dingux, and only caused a problem when I split them. Maybe as you say OpenDingux differs from the original Dingux. Still, when I get the chance, I'll make those changes and try again. You never know, eh.

Just out of interest, did you use my makefile, or did you use different compiler parameters?

Thanks again.


  • Posts: 365
Re: Noob 2 - The Missing Link
« Reply #3 on: February 10, 2012, 08:16:15 pm »
I used yours, but edited some lines to use opendingux toolchain, and now I remember I removed -mips32 flag, but only because I compiled it on mi PC first and forgot to add it later. Maybe you don't need that while testing, and also the -O2 looks unnecesary at this point, you don't need optimizations with a test app.

Stoop Solo (OP)

  • Posts: 11
Re: Noob 2 - The Missing Link
« Reply #4 on: February 11, 2012, 12:09:28 am »
...Well would you look at that. I started by changing the video mode to 16 bit, then changed all the Uint32 to Uint16, and simply left the rest alone. Now it's working.

I admit this puzzles me greatly, because apart from the test program being split, it was exactly the same functionality-wise (all the 32-bit stuff) as my first test program, which compiled and ran. I wonder why splitting it across two sources suddenly made it reject 32 bit surfaces?

Anyhow, mystery solved. The linking was actually working. Thanks, DiegoSLTS. Guess I'd better make some 16 bit versions of my actual functions if I want to use them on the Dingoo.


Post a new topic