PDA

View Full Version : GP2X/FPC Issues



KidPaddle
12-09-2007, 05:30 AM
Hello Paul,

for using static open2x - Libraries on GP2X i need to recompile all units with softfloat support. Has you find out, how to compile the units and the compiler with softfloat support?

regards
Thomas

paul_nicholls
16-09-2007, 10:52 PM
Hello Paul,

for using static open2x - Libraries on GP2X i need to recompile all units with softfloat support. Has you find out, how to compile the units and the compiler with softfloat support?

regards
Thomas

Hi Thomas,
hmm...I am not sure how to do the softfloat support, I will try and find out for you.

cheers,
Paul.

KidPaddle
17-09-2007, 01:38 PM
Hi Paul,

thanks for helping. I had setup an envrioment with open2x libraries and i got a gp2x execution file. But starting on gp2x it crashed in function Mix_OpenAudio, i got always an accession voilation.

I have checked different libraries pack, open2 or default devkitgp2x, but i got always the same exception.

Cheers,
Thomas

paul_nicholls
18-09-2007, 10:16 PM
I have heard of, but never used open2x...only the standard gp2x firmware + devkitGP2X.

cheers,
Paul.

KidPaddle
22-09-2007, 06:54 AM
I have installed your environment from your site http://fpc4gp2x.eonclash.com/ and compile your gp2x_tutorial successfully.

It runs under gp2x well. So added the unit SDL_Mixer and insert following lines:



const
cFrequenz = MIX_DEFAULT_FREQUENCY;
cAudioFormat = AUDIO_S16;
cChannels = MIX_DEFAULT_CHANNELS;
cChunksize = 128;

After calling of SDL_Init, i add those lines:


if &#40;Mix_OpenAudio&#40;cFrequenz, cAudioFormat, cChannels, cChunksize&#41; < 0&#41;
then begin
WriteLn&#40;Format&#40;'Couldn''t set %d Hz audio\n- Reason&#58; %s', &#91;cFrequenz, SDL_GetError&#40;&#41;&#93;&#41;&#41;;
end;


And, what happen? Yes, it crashed on gp2x in function Mix_OpenAudio.

Any idea what i can do?

cheers,
Thomas

WILL
22-09-2007, 08:16 AM
Hi KidPaddle, welcome to PGD! :)

You're posts were somewhat off-topic in the other thread so I split them off into this new one.

I hope that you are able to resolve your GP2X issues! Console development is a very new and exciting area of game programming in this community of late. :D

paul_nicholls
22-09-2007, 08:36 AM
Will: thanks for moving this to a new thread :-)

KidPaddle: I have also had issues with SDL_Mixer on the GP2X and have not resolved them myself yet, sorry :(

It is something I have been meaning to do...I have gotten a different version of the devkitGP2X + SDL libs to see if that helps but I haven't had time to test it.

Also I am planning on building the crosscompiler from the new 2.2.0 freepascal sources to see if that helps as well.

cheers,
Paul

KidPaddle
22-09-2007, 08:54 AM
@WILL

Thanks for splitting the thread.

@Paul
Ok, thanks for response.

Cheers,
Thomas

WILL
22-09-2007, 09:14 AM
You guys should touch base with Dom(savage) about the SDL side of things. He is pretty good at allowing support for most platforms that are really only partially available on developing compilers. ie. GBA and NDS

He might be able to provide some extra insight for you.

KidPaddle
26-09-2007, 04:42 PM
I figure out, that there is a problem in pthread - library.

[code]
(gdb) backtrace
#0 0x00092f34 in __pthread_initialize_manager ()
#1 0x00093384 in pthread_create ()
#2 0x000623ac in SDL_SYS_CreateThread (thread=0x277b48, args=0x277e68) at SDL_systhread.c:99
#3 0x00061e34 in SDL_CreateThread (fn=0x1ee990 <SDL_Threads>, data=<value>) at SDL_thread.c:257
#4 0x0005406c in SDL_OpenAudio (desired=0xbffffd10, obtained=0x1eedb4) at SDL_audio.c:500
#5 0x0007d744 in Mix_OpenAudio (frequency=513860, format=28164, nchannels=2321944, chunksize=<value>)
at mixer.c:291
#6 0x000089d8 in main () at fpc4gp2x.dpr:96

What are the next steps? I don't know.

Cheers,
Thomas

paul_nicholls
26-09-2007, 11:22 PM
Hi KidPaddle,
I am interested in using gdb to debug my GP2X programs using freepascal, can you tell me how to do this?

cheers,
Paul.

KidPaddle
27-09-2007, 04:01 PM
I have download the debugger for gp2x from this site:

http://archive.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,14,1655

Put both, debugger and program, into same directory and connect to gp2x with telnet, switch to program directory and call:

./dbg program.gpe

That alls, nothing special. Only you have to remove "-s" option from linker, cause it strip all debug symbols.

Cheers
Thomas

paul_nicholls
27-09-2007, 10:35 PM
Thanks for the info KidPaddle! :-)

BTW, I have built myself a new crosscompiler using the new freepascal 2.2.0 sources, etc. and have had less issues. After more testing I will upload the new cross-compiler to the fpc4gp2x site.

I have also 'updated' my devkitGP2X sdl libraries from here (http://archive.gp2x.de/cgi-bin/cfiles.cgi?0,0,0,0,19,1875). This includes SDL_mixer 1.2.6 compiled to use libmad and tremor which don't use floating point at all which is much better.

I need to try some sdl mixer stuff to see if that works now :-)

I will keep you posted.

PS according to Eugene Proshkin who helped me get stated with the GP2X programming, you don't need softfloat when building the cross-compiler.

cheers,
Paul.

paul_nicholls
28-09-2007, 03:53 AM
Attention linker "experts":

I have tried compiling a pascal program using the freepascal 2.2.0 cross-compiler I made and using some updated SDL libraries, including an updated SDL_Mixer that uses libmad and trembor? for no floating-point usage.

At the linking stage I get these errors:


C&#58;\devkitGP2X\lib\\libSDL_mixer.a&#40;mp3_mad.o&#41;&#58; In function `mad_openFileRW'&#58;
mp3_mad.c&#58;&#40;.text+0x1c&#41;&#58; undefined reference to `mad_stream_init'
mp3_mad.c&#58;&#40;.text+0x24&#41;&#58; undefined reference to `mad_frame_init'
mp3_mad.c&#58;&#40;.text+0x30&#41;&#58; undefined reference to `mad_synth_init'
mp3_mad.c&#58;&#40;.text+0xa0&#41;&#58; undefined reference to `mad_timer_zero'
C&#58;\devkitGP2X\lib\\libSDL_mixer.a&#40;mp3_mad.o&#41;&#58; In function `mad_closeFile'&#58;
mp3_mad.c&#58;&#40;.text+0xc4&#41;&#58; undefined reference to `mad_stream_finish'
mp3_mad.c&#58;&#40;.text+0xcc&#41;&#58; undefined reference to `mad_frame_finish'
C&#58;\devkitGP2X\lib\\libSDL_mixer.a&#40;mp3_mad.o&#41;&#58; In function `read_next_frame'&#58;
mp3_mad.c&#58;&#40;.text+0x150&#41;&#58; undefined reference to `mad_frame_decode'
mp3_mad.c&#58;&#40;.text+0x17c&#41;&#58; undefined reference to `mad_stream_errorstr'
mp3_mad.c&#58;&#40;.text+0x24c&#41;&#58; undefined reference to `mad_stream_buffer'
mp3_mad.c&#58;&#40;.text+0x260&#41;&#58; undefined reference to `mad_frame_decode'
mp3_mad.c&#58;&#40;.text+0x28c&#41;&#58; undefined reference to `mad_timer_add'
mp3_mad.c&#58;&#40;.text+0x2f8&#41;&#58; undefined reference to `mad_stream_buffer'
C&#58;\devkitGP2X\lib\\libSDL_mixer.a&#40;mp3_mad.o&#41;&#58; In function `mad_seek'&#58;
mp3_mad.c&#58;&#40;.text+0x384&#41;&#58; undefined reference to `mad_timer_set'
mp3_mad.c&#58;&#40;.text+0x390&#41;&#58; undefined reference to `mad_timer_compare'
mp3_mad.c&#58;&#40;.text+0x3f4&#41;&#58; undefined reference to `mad_timer_compare'
mp3_mad.c&#58;&#40;.text+0x444&#41;&#58; undefined reference to `mad_timer_zero'
C&#58;\devkitGP2X\lib\\libSDL_mixer.a&#40;mp3_mad.o&#41;&#58; In function `mad_getSamples'&#58;
mp3_mad.c&#58;&#40;.text+0x5a8&#41;&#58; undefined reference to `mad_synth_frame'
C&#58;\devkitGP2X\lib\\libSDL_mixer.a&#40;mp3_mad.o&#41;&#58; In function `mad_openFile'&#58;
mp3_mad.c&#58;&#40;.text+0x820&#41;&#58; undefined reference to `mad_stream_init'
mp3_mad.c&#58;&#40;.text+0x828&#41;&#58; undefined reference to `mad_frame_init'
mp3_mad.c&#58;&#40;.text+0x834&#41;&#58; undefined reference to `mad_synth_init'
mp3_mad.c&#58;&#40;.text+0x8a8&#41;&#58; undefined reference to `mad_timer_zero'

Does this mean I have something in the wrong order in the linking process?

My linking line in the batch file:


arm-linux-ld.exe -static --no-warn-mismatch --reduce-memory-overheads --gc-sections -s -L. -o%1.gpe link.res -lpng -lm -lstdc++ -lgcc_eh -lpthread -lvorbisidec -lmikmod -lpng12 -lz -lSDL -ljpeg -lfreetype -lc -lgcc

cheers,
Paul.

KidPaddle
28-09-2007, 07:55 AM
Hi Paul,

Great news! :D

@libmad
There is a missing library libmad, so add -lmad to your linking line.

@SoftFloat
The default DevKit is compiled with hard float, the linker accept this. But Open2x DevKit is compiled with soft float, in this case, i need soft float units. Soft Float is much faster, cause no raised exception, by using floating point opcode, has to be catched by the system, which needs a lot of cpu cycles.

Cheers,
Thomas

Sorry for my bad language, hope you understand what i'm meaning.

paul_nicholls
28-09-2007, 10:48 AM
[quote="KidPaddle"]Hi Paul,

Great news! :D

@libmad
There is a missing library libmad, so add -lmad to your ]

@libmad
Thanks, at least it now compiles! :)
It does crash though (need to debug) :(

@softfloat
ok, that makes sense.

Your english is very good BTW :)

cheers,
Paul.

paul_nicholls
28-09-2007, 11:53 AM
Hi KidPaddle, I finally got the gdb working. It gives me this result


Program received signal SIGSEGV, Segmentation fault.
0x0006e70c in __pthread_initialize_manager &#40;&#41; at ../MPEGerror.h&#58;34
34 ../MPEGerror.h&#58; No such file or directory.
in ../MPEGerror.h

Does this mean anything to you? :-)
cheers,
Paul

KidPaddle
28-09-2007, 02:41 PM
Hi Paul,

it coud be, that i have seen this error in my life before, but ... i'm not sure. :wink:

Cheers,
Thomas

KidPaddle
30-09-2007, 02:51 PM
Ok, it has nothing to do with sdl_mixer. It happens, when a timer must be initialized.


program sdlfpc;
&#123;$IFNDEF FPC&#125;
&#123;$APPTYPE CONSOLE&#125;
&#123;$ENDIF&#125;

uses SDL;

begin
WriteLn&#40;'Init Timer'&#41;;
if &#40;SDL_Init&#40;SDL_INIT_TIMER&#41; < 0&#41; then begin
WriteLn&#40;SDL_GetError&#40;&#41;&#41;;
end;

WriteLn&#40;'SDL_INIT_TIMER Done'&#41;;
SDL_QUIT;
end.


This code crashed too.

Cheers,
Thomas

KidPaddle
30-09-2007, 03:19 PM
Ok, next step on the "try and error" way.


uses SDL;

var
thread&#58; PSDL_Thread;
returnValue&#58; Integer;

function thread_func&#40;&#41;&#58; Integer;
begin
// do threading here
WriteLn&#40;'Start Thread'&#41;;
SDL_Delay&#40;5000&#41;;
WriteLn&#40;'End Thread'&#41;;

result &#58;= 1; // thread leaves and return this value
end;

begin
returnValue &#58;= 0;
thread &#58;= SDL_CreateThread&#40;@thread_func, NIL&#41;;

SDL_WaitThread&#40;thread, returnValue&#41;;
WriteLn&#40;'Thread returns code ',returnValue&#41;;
SDL_Quit;
WriteLn&#40;'ByeBye ;&#41;'&#41;;
end.


Crashed too, there is something wrong with thread management.

Thomas

savage
30-09-2007, 04:42 PM
Where are you running this code that crashes?

You need to tell the compiler that this is a console Application otherwise the calls to *writeln* will AV. Which is what I am seeing.

The following works for me on Windows.


program Thread;

{$APPTYPE CONSOLE}

uses
sdl;

var
thread : PSDL_Thread;
returnValue : Integer;

function thread_func( aData : pointer ) : integer; cdecl;
begin
// do threading here
WriteLn( 'Start Thread' );
SDL_Delay( 5000 );
WriteLn( 'End Thread' );

result := 1; // thread leaves and return this value
end;

begin
returnValue := 0;

thread := SDL_CreateThread( @thread_func, nil );

SDL_WaitThread( thread, returnValue );
WriteLn( 'Thread returns code ', returnValue );
SDL_Quit;
WriteLn( 'ByeBye ;)' );
end.


On other platforms you may have to specifcy the *cdecl* call and the pointer parameter as well to avoid the AV.

As for timers, the following example works for me....

program SDLTimers;

{$APPTYPE CONSOLE}

uses
SysUtils,
sdl;

var
Timer1 : PSDL_TimerID;
Timer2 : PSDL_TimerID;
Param1 : Integer;
Param2 : Integer;

function CallTimer1( interval : UInt32; param : Pointer ) : UInt32; cdecl;
var
pParam : PInteger;
begin
pParam := PInteger( param );
WriteLn( 'Parameter = ' + IntToStr( pParam^ ) + ' in CallTimer1' );
Result := interval;
end;

function CallTimer2( interval : UInt32; param : Pointer ) : UInt32; cdecl;
var
pParam : PInteger;
begin
pParam := PInteger( param );
WriteLn( 'Parameter = ' + IntToStr( pParam^ ) + ' in CallTimer2' );
Result := interval;
end;

begin
if ( SDL_Init( SDL_INIT_TIMER ) <> 0 ) then
WriteLn( 'Cannot initalize SDL' );

// Adding Timers
WriteLn( 'Adding Timers +' );
Param1 := 12;
Param2 := 15;
Timer1 := SDL_AddTimer( 500, CallTimer1, @Param1 );
Timer2 := SDL_AddTimer( 1200, CallTimer2, @Param2 );

WriteLn( 'SDL_Delay 30 secs, so we can see the timers in operation' );
SDL_Delay( 30000 );

WriteLn( 'Removing Timers -' );
SDL_RemoveTimer( Timer2 );
SDL_RemoveTimer( Timer1 );

WriteLn( 'Ciao ;)' );
ReadLn;
SDL_Quit;
end.


Does it work for you?

savage
30-09-2007, 04:52 PM
Btw, I tested both of these apps with Delphi and FreePascal on Windows. Hopefully they should work exactly as advertised on other platforms.

paul_nicholls
30-09-2007, 11:14 PM
Hi Thomas
I googled for 'MPEGerror.h and found this file:

http://svn.icculus.org/*checkout*/smpeg/trunk/MPEGerror.h?rev=2

So it sounds like something else is causing this class to be used to produce the error.

I did try adding SDL_INIT_TIMER to my SDL_Init() call, but it still crashes on my GP2X :(

I haven't tried running it using gdb again with the SDL_INIT_TIMER to see if it is the same error as before though...

cheers,
Paul.

KidPaddle
01-10-2007, 10:47 AM
Hi,

@savage
My sample crashed only on GP2X, on Windows it works perfectly. I will try your sample today.

@Paul
You got nearly the same stack trace, only a few higher level calls are missing, but after calling SDL_CreateThread, it crashed in function __pthread_initialize_manager ().

Thomas

KidPaddle
01-10-2007, 01:06 PM
Hi savage,

if have tested both samples from you, under windows it works perfect, on gp2x it crashed always in function __pthread_initialize_manager.

Cheers,
Thomas

savage
01-10-2007, 10:27 PM
I've posted a message about it on the main SDL mailing list, so will see what they come back with.

KidPaddle
03-10-2007, 06:43 AM
Thanks for open a post on libsdl mailing list, but i believe it has nothing to do with sdl.

I have installed the official gph sdk and compiled the thread sample. After executing on gp2x i got following debugger output:


Starting program&#58; /mnt/sd/Test/fpc/fpc4gp2x/fpcthread.gpe

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? &#40;&#41;
&#40;gdb&#41; info stack
#0 0x00000000 in ?? &#40;&#41;
#1 0x00075ecc in ptmalloc_init &#40;&#41; at malloc.c&#58;1760
#2 0x00077630 in malloc_hook_ini &#40;sz=792, caller=0x75b6c&#41; at malloc.c&#58;1856
#3 0x000774ac in __libc_malloc &#40;bytes=989568&#41; at malloc.c&#58;2797
#4 0x0004da7c in SDL_CreateThread &#40;fn=0x8118 <THREAD_FUNC>, data=0x0&#41; at SDL_thread.c&#58;228
#5 0x000081e4 in main &#40;&#41; at fpcthread.dpr&#58;26


As you can see, the gph sdk has more debug symbols insight, so we got a better error location.

I wrote a smaller sample, like this:

program fpcmalloc;
&#123;$IFNDEF FPC&#125;
&#123;$APPTYPE CONSOLE&#125;
&#123;$ENDIF&#125;

function malloc&#40;aSize &#58; Integer&#41;&#58; Pointer; cdecl; external;
procedure free&#40;aPtr &#58; Pointer&#41;; cdecl; external;

var
MemPtr &#58; Pointer;
begin
WriteLn&#40;'Alloc 792 Bytes'&#41;;
MemPtr &#58;= Malloc&#40;792&#41;;

WriteLn&#40;'Release 792 Bytes'&#41;;
Free&#40;MemPtr&#41;;

WriteLn&#40;'ByeBye'&#41;;
end.


The output under gp2x is:


Starting program&#58; /mnt/sd/Test/fpc/fpc4gp2x/fpcmalloc.gpe
Alloc 792 Bytes

Program received signal SIGSEGV, Segmentation fault.
0x00000000 in ?? &#40;&#41;
&#40;gdb&#41; info stack
#0 0x00000000 in ?? &#40;&#41;
#1 0x00034f70 in ptmalloc_init &#40;&#41; at malloc.c&#58;1756
#2 0x0003670c in malloc_hook_ini &#40;sz=792, caller=0x0&#41; at malloc.c&#58;1856
#3 0x00036588 in __libc_malloc &#40;bytes=230028&#41; at malloc.c&#58;2797
#4 0x00008168 in main &#40;&#41; at fpcmalloc.dpr&#58;13


I don't know if I'm right, but i look at ptmalloc_init ();

Cheers,
Thomas

savage
03-10-2007, 08:30 AM
So do you think the problem is in the FreePascal memory allocation?
That it is incompatible with how GP2X expects it?

KidPaddle
03-10-2007, 10:47 AM
I don't know. Using GetMem/FreeMem works, maybe there is something wrong with static linking of libc, but that is guessed.

Thomas

gigantor77
13-10-2007, 03:39 AM
Hi all!
I used the fpc4gp2x from eonclash.com and got the same problem...crash when trying to use the mixer, when statically linking. All the graphics & joystick stuff works find though...thanks Paul :-)

I noticed that the Eugene Proshkin's Blocks program is dynamically linked and the sound is working fine.

However I couldnt work out how to dynamically link from his compiler files. Has anyone been able to dynamically link using fpc4gp2x on Windows? I keep getting all sorts of linking errors.

paul_nicholls
14-10-2007, 09:54 PM
Hi gigantor77,
I haven't tried to dynamic link the SDL libs at all.
I really would like to get the SDL_Mixer working myself :-)

PS. When you said that the graphics stuff worked for you, did you try PNG files at all on the GP2X? I had trouble with PNG myself.

cheers,
Paul.

KidPaddle
31-12-2007, 07:18 AM
Has anyone new information about the problem with sdl_mixer usage?

Cheers,
Thomas