ttyborg / castlesand

Automatically exported from code.google.com/p/castlesand
0 stars 0 forks source link

Using Cardinal type for pointer arithmetics causes segmentation fault on 64-bit machine #91

Open GoogleCodeExporter opened 9 years ago

GoogleCodeExporter commented 9 years ago
What steps will reproduce the problem?
1. Compile KaM on 64-bin Unix platform (tested: Linux, FreeBSD) using Lazarus 
1.0.2 (FPC 2.6.4).
2. Run.

What is the expected output? What do you see instead?
The application crashes raising segmentation fault/access violation error.

What version of the product are you using? On what operating system?
Building revision 6733 on Gentoo Linux using Lazarus 1.0.2 (FPC 2.6.4). The 
problem occurs on 64-bit system. I've also tried building on FreeBSD 10.1 
(amd64) with same result.
Works flawlessly when patches (see below).

Please provide any additional information below.
The problem occurs when doing pointer calculations on 64-bit machine using 
Cardinal type, which doesn't handle 64-bit address space properly. Changing the 
type to bit-length-aware type (NativeUInt, as it's written here: 
http://wiki.freepascal.org/Cardinal) fixes the issue.

I've attached proposed patch for this issue. It bugfixes issues that affected 
me during normal singleplayer gameplay.

I can include output from console, backtrace if you wish.

Original issue reported on code.google.com by MarcMo...@gmail.com on 9 Feb 2015 at 5:38

Attachments:

GoogleCodeExporter commented 9 years ago
The same issue happens when entering multiplayer from the main menu.
I've included backtrace and patch.

Original comment by MarcMo...@gmail.com on 9 Feb 2015 at 5:49

Attachments:

GoogleCodeExporter commented 9 years ago
Hi.

We haven't designed KaM Remake to run on 64bit platforms yet:
 - the game is still maintaining Delphi 7 compatibility, which is still the most widespread Delphi version AFAIK. Delphi 7 does not have NativeUInt type.
 - there is no actual need in doing a 64 bit version of the game, 32bit works just fine and adding 64bit will also mean maintaining more sophisticated code.
 - there are no advantages in going 64bit for the game, there are no memory allocations that need 64 bit address space.
 - there are numerous places in code that assume Pointer=Cardinal (especially savegames and multiplayer)

Said that, if you are really interested in maintaining 64 bit compatibility:
 - please look throughout the whole code to estimate the size of the refactoring required.
 - keep in mind that this is optional job and you will be doing it just for your own pleasure.
 - start off with adding "NativeUInt" type to KM_CommonTypes wrapped into IFDEF for older 32bit versions of Delphi that don't have "NativeUInt" type.

Original comment by kromster80@gmail.com on 10 Feb 2015 at 5:45