fabiensanglard / chocolate_duke3D

chocolate Duke Nukem,3D
598 stars 91 forks source link

Segmentation fault #51

Open FenzaFenz opened 7 years ago

FenzaFenz commented 7 years ago
*** Chocolate DukeNukem3D v1.0 ***

Scanning directory './' for a GRP file like 'duke3d*.grp'.
Loading duke3d.grp ...
GRP identified as: PLUTONIUM 1.4 
Commands: 
SDL display driver for the BUILD engine initializing.
  sdl_driver.c by Ryan C. Gordon (icculus@clutteredmind.org).
Compiled Aug 27 2017 against SDL version 1.2.15 ...
Linked SDL version is 1.2.15 ...
Using SDL video driver "x11".Video Driver: 'x11'.
Using Setup file: 'duke3d.cfg'
CONFIG_ReadSetup...
duke3d.cfg does not exist. Don't forget to set it up!
STUB: CONTROL_ClearAssignments (CONTROL_ClearAssignments, control.c:471)
Compiling: 'GAME.CON'.
Including: 'DEFS.CON'.
Including: 'USER.CON'.
Code Size:64832 bytes(1794 labels).
Con version: Looks like v14
Initializing SDL joystick subsystem... (export environment variable BUILD_SDLJOYSTICK=none to skip)
SDL sees 1 joystick.
Stick #0: [ST LIS3LV02DL Accelerometer]
Using Stick #0.Joystick initialized. 3 axes, 0 buttons, 0 hats, 0 balls.
Segmentation fault (core dumped)
fawtytoo commented 6 years ago

I've just compiled the latest build and it SegFaults at:

clearbufbyte (D=D@entry=0x55810fe0, c=123, c@entry=125, a=a@entry=0) at fixedPoint_math.c:20 20 *(p++) = (uint8_t )((a & m[z])>>n[z]);

darealshinji commented 6 years ago

So it fails here. If your build is 64 bit, does it also crash on a 32 bit version?

fawtytoo commented 6 years ago

The game works perfectly in 32bit. But not 64bit.

fawtytoo commented 6 years ago

I've done some tracking of the code and found this in Engine/src/unix_compat.h:28

// Horrible horrible macro: Watcom allowed memory pointer to be cast
// to a 32bits integer. The code is unfortunately stuffed with this :( !
#define FP_OFF(x) ((int32_t) (x))

Changing the type from an int32_t to a long helps the game continue but still SegFaults. This time in the function clearview in Engine/src/engine.c:8995 Variable p clearly needs to be a long type, but it still SegFaults.

fawtytoo commented 6 years ago

Hmmm. Getting a bit further. If I put a return; at the beginning of the clearview function, the game then SegFaults at dorotatesprite in Engine/src/engine.c:3784

If I put a return; at the beginning of dorotatesprite, the game actually starts playing. Sort of.

fawtytoo commented 6 years ago

One more fix: In the function clearview, changing the type for variable p to uint8_t* fixes that function. This leaves the dorotatesprite function. All I can work out is it's from line 3991 onwards in that function, but I can't see where.

EDIT: The remaining memory pointer problems all seem to be in Engine/src/draw.c (called from dorotatesprite) which is riddled with 32 bit pointers.

fawtytoo commented 6 years ago

Execution fails on Debian 9.3 64bit. It executes perfectly on Debian 9.3 32bit. Also fails on Ubuntu 17.10 64bit. But it does work on Linux Mint 18.2 64bit.

rohit-n commented 5 years ago

@phenest I just made a pull request of fixes for 64-bit. Please try my branch (https://github.com/rohit-n/chocolate_duke3D/tree/build-64bit) and let me know if you have any issues.

fhomolka commented 4 years ago

@phenest I just made a pull request of fixes for 64-bit. Please try my branch (https://github.com/rohit-n/chocolate_duke3D/tree/build-64bit) and let me know if you have any issues.

Sorry for necro-ing the issue, but will this be merged as a solution to this issue?