project-navigation
Personal tools

Author Topic: Mac PPC - endianess issues  (Read 6848 times)

alexis

  • Guest
Mac PPC - endianess issues
« on: October 16, 2007, 10:36:19 pm »
I'm on a mac ppc.
In CL_ActorMouseTrace (in cl_actor.c) there is an endianess problem (search "FIXME: The next three lines are not endian safe" comment.)
After the CM_TestLineDM(pA, pB, pC) call, pC[2] is 0 when the bug occurs.
As far as I understand the code, I think that CM_TestLineDM is OK, but in TestLineDist_r, in the following code:
   if (node & (1 << 31)) {
      r = node & ~(1 << 31);
      if (r)
         VectorCopy(start, tr_end);
      return r;            /* leaf node */
   }
--> "if(r)" is never true when the bug occurs. This may be caused by a bad initialization of nodes.
Have a look to CMod_LoadNodes, I think that:
VectorAdd(in->mins, shift, out->mins);
VectorAdd(in->maxs, shift, out->maxs);
must be replaced by:
out->mins[0]=LittleFloat(in->mins[0])+shift[0];
out->mins[1]=LittleFloat(in->mins[1])+shift[1];
out->mins[2]=LittleFloat(in->mins[2])+shift[2];
out->maxs[0]=LittleFloat(in->maxs[0])+shift[0];
out->maxs[1]=LittleFloat(in->maxs[1])+shift[1];
out->maxs[2]=LittleFloat(in->maxs[2])+shift[2];

I'm not sure if 'shift' should be swapped too, and if the test
if (in->planenum == -1)
should be
if (LittleLong(in->planenum) == -1)

I think that all "in->" variables should be swapped, shouldn't they?

I haven't the time to test further, and I'm not sure what I said is right, please have a look. Hope this helps.

BTW: shouldn't "byte.c" be defined with #define statements set by ./config?
I mean: isn't it time-consuming to call ***NoSwap functions (that do nothing) on little endian machines?
Seen in Apple's OSByteOrder.h:
#if      defined(__BIG_ENDIAN__)
#define OSSwapHostToLittleInt16(x) OSSwapInt16(x)
#else
#define OSSwapHostToLittleInt16(x) ((uint16_t)(x))
#endif

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Mac PPC - endianess issues
« Reply #1 on: October 17, 2007, 07:53:20 am »
i've applied your ideas to current trunk - it would be cool if you could test them. Thanks for your help.

https://sourceforge.net/tracker/?func=detail&atid=805242&aid=1748650&group_id=157793

and you are right about the endian checks, too - it's just that noone did the conversion yet ;)

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Mac PPC - endianess issues
« Reply #2 on: October 17, 2007, 08:13:00 am »
Btw. do you have any problems in the menus - like hovering a button will let it disappear or something like that? i suspect the alignment of menuNode_t or Com_SetValue is broken for ppc (either alignment or endianness)

schoberth

  • Guest
Re: Mac PPC - endianess issues
« Reply #3 on: October 17, 2007, 10:39:25 pm »
A lot of issues have been fixed with the last revision (revision 12530).
But one Killer is still left. All works fine when starting a campaign until the point, the first ufo lands and i try to enter the map "oriental big". I send the dropship to the ufo landing site and the map begins loading. After that, the map is shown for about 5 Seconds and i am Thrown back to the Geoscape. The Console Output says the following about this :
Map: +orientaln
Starting the game...
Tom has joined team 0
(player 0) It's team 1's round
Tom has taken control over team 1.
S_Music_Start: Could not load music: 'music/van_geoscape.ogg' (Failed loading libvorbisfile.dylib: dlopen(libvorbisfile.dylib, 2): image not found)
Grid_CheckForbidden: unknown forbidden-size: 0
********************
ERROR: Grid_CheckForbidden: unknown forbidden-size: 0
********************

The Music does'nt work either, but i don't think that it is the killer here.

[EDIT] The crash occurs when clicking with the cursor onto a Player character. The map remains loaded until i try to click on one of my Team Members, then i got kicked back to Geoscape.
« Last Edit: October 18, 2007, 12:21:21 am by schoberth »

alexis

  • Guest
Re: Mac PPC - endianess issues
« Reply #4 on: October 17, 2007, 11:09:26 pm »
It works! Cursor doesn't disappear any more, and characters don't see thru walls any more.

I still have a problem with Grid_CheckForbidden. On loading a map, I got the following error:
Grid_CheckForbidden: unknown forbidden-size: 0
I have patched it by replacing
      forbidden_size = *(p + 1);
      switch (*forbidden_size) {
with
      switch (1)
for the moment.

I had the bug you describe (disappearing menus) some times ago in 2.2, but it works now.

Now I have a problem with libvorbisfile.dylib, I got the following error in the console:
S_Music_Start: Could not load music: 'music/ufo2.ogg' (Failed loading libvorbisfile.dylib: dlopen(libvorbisfile.dylib, 2): image not found)
I don't know where libvorbisfile.dylib is supposed to be?

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Mac PPC - endianess issues
« Reply #5 on: October 18, 2007, 08:35:09 am »
it's dynamically loaded by sdl_mixer - maybe in the same dir?

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Mac PPC - endianess issues
« Reply #6 on: October 18, 2007, 08:54:20 am »
the "fix" for Grid_CheckForbidden will break the 2x2 unit support (like UGVs) - there must be some endian bug in the code. Can someone please try the following:

Code: [Select]
Index: src/common/cmodel.c
===================================================================
--- src/common/cmodel.c (Revision 12524)
+++ src/common/cmodel.c (Arbeitskopie)
@@ -2462,7 +2462,7 @@
                }
 
                forbidden_size = *(p + 1);
-               switch (*forbidden_size) {
+               switch (LittleLong(*forbidden_size)) {
                case ACTOR_SIZE_NORMAL:
                        if (x == (*p)[0] && y == (*p)[1] && z ==(*p)[2])
                                return qtrue;

schoberth

  • Guest
Re: Mac PPC - endianess issues
« Reply #7 on: October 18, 2007, 09:09:18 am »
I tried it. No change.
Same Crash when entering the first map.

alexis

  • Guest
Re: Mac PPC - endianess issues
« Reply #8 on: October 18, 2007, 10:53:20 am »
The Grid_CheckForbidden problem comes from this line in CL_BuildForbiddenList:
fb_list[fb_length++] = ((byte*)&le->fieldSize);
fieldSize is an int an the type-casting is not respectful of endianess. On ppc, it should be:
fb_list[fb_length++] = ((byte*)&le->fieldSize)+3;
(which works).
I don't know how you can easily fix that... Maybe a #define __BIG_ENDIAN__ could help.

NB: I found the same kind of code in G_BuildForbiddenList:
fb_list[fb_length++] = (byte*)&ent->fieldSize;
« Last Edit: October 18, 2007, 10:57:47 am by alexis »

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Mac PPC - endianess issues
« Reply #9 on: October 18, 2007, 12:33:27 pm »
could you please try the latest rev and tell me whether it works now?

alexis

  • Guest
Re: Mac PPC - endianess issues
« Reply #10 on: October 18, 2007, 04:59:47 pm »
The Grid_CheckForbidden bug is fixed for me in 12540.

Offline Mattn

  • Administrator
  • PHALANX Commander
  • *****
  • Posts: 4831
  • https://github.com/mgerhardy/vengi
    • View Profile
    • Vengi Voxel Tools
Re: Mac PPC - endianess issues
« Reply #11 on: October 18, 2007, 06:26:56 pm »
that's great - thanks for the feedback. the next step would be to test the game over network with another arch like windows or little endian linux. If you have the time,please join our irc channel and try to start or join a network game. But please keep in mind, that you should use the mappack from http://mattn.ninex.info - otherwise the checksums of the maps will differ and prevents you from joining a game.

thanks again for helping to finally bring ufoai to the ppc arch.

alexis

  • Guest
Re: Mac PPC - endianess issues
« Reply #12 on: October 26, 2007, 10:37:38 pm »
I updated at rev 12666.
./config reports this error:
checking for library containing Mix_OpenAudio... no
configure: error: You must have the SDL_mixer development libraries

I have SDL_mixer installed in /opt/local (using macports).

If I suppress /Library/Frameworks/SDL* then ./config tells me:
configure: error: Could not find SDL Framework at /Library/Frameworks.

But I can finally have ./config work by updating SDL, installing the three SDL frameworks in /Library/Frameworks/ and calling:
sudo ./configure --with-openal=no --with-sdl-config=/opt/local/include/SDL/SDL_config.h
...then ufoai compiles and the bug about S_Music_Start is fixed. (music is great!)

So I guess that ./config should be fixed to search for SDL also in /opt/local/


I won't test the game over network for now. Maybe someone else can help? (schoberth?)

schoberth

  • Guest
Re: Mac PPC - endianess issues
« Reply #13 on: October 27, 2007, 12:31:12 am »
1. Please download sdl_mixer framework from www.libsdl.org and copy it to /System/Library.
2. Please open the file configure.ac with a editor and go to line 409:

change if test "$ac_cv_prog_HAVE_SDL_CONFIG" = "yes"
to if test "$ac_cv_prog_HAVE_SDL_CONFIG" = "anything"

3. run
autoconf
./configure

that should help for the moment. Elph, who patched the configure file for mac will adress this issue in one of the next revisions.

Schoberth
« Last Edit: October 27, 2007, 12:35:37 am by schoberth »

alexis

  • Guest
Re: Mac PPC - endianess issues
« Reply #14 on: November 24, 2007, 09:53:05 am »
I experimented some more crashs on mac ppc (ufoai rev 13130).

- SDL_PollEvent sometimes raise an error from Objective C (I don't remember which one, this happened when I go level down with the down arrow key). I think this is not an error from your code but from the mac implementation of SDL. I fixed this crash by defining the following handler in osx_main.m that I call instead of calling SDL_PollEvent directly:

#include <SDL/SDL_events.h>
int mySDL_PollEvent(SDL_Event *event){
   int result=0;
   NSAutoreleasePool *pool = [[NSAutoreleasePool alloc] init];
   @try{
      result=SDL_PollEvent(event);
   }@catch ( NSException *e ) {
      result=0;
   }
   [pool release];
   return result;
}


- I have a crash (bad access) when displaying Plasma blade research report. The crash happens in UP_ItemDescription:
         /* Everything that follows depends only of the ammunition, so we change od to it */
         od = &csi.ods[od->ammo_idx[up_researchedlink]];
         for (i = 0; i < min(MAX_WEAPONS_PER_OBJDEF,od->numWeapons); i++) {
-->od->numWeapons is far bigger than MAX_WEAPONS_PER_OBJDEF
NB: I fixed it by replacing od->numWeapons by min(MAX_WEAPONS_PER_OBJDEF,od->numWeapons) but there is something wrong with the variables initialization, I don't know where.