Bay 12 Games Forum

Please login or register.

Login with username, password and session length
Advanced search  
Pages: [1] 2

Author Topic: Segfault thread  (Read 1884 times)

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Segfault thread
« on: September 11, 2009, 12:53:53 pm »

I love LCS. Every single aspect of it. Except the segfaults. I run Debian Linux, I compiled the game from source, and it won't load saved games because of segfault. Any cure for these segfaults (apart from "one session playthrough"), is the cause known?

EDIT: To clarify, I had them with the older version as well so it's not something in the new version.
FURTHER EDIT: For those who are potentially willing to find the issue in the source, it occurs in "The Liberal Elite" screen.
« Last Edit: September 11, 2009, 12:59:13 pm by Kay12 »
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: Segfault thread
« Reply #1 on: September 11, 2009, 01:52:14 pm »

What computer processor do you have?
Logged

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: Segfault thread
« Reply #2 on: September 11, 2009, 02:00:41 pm »

Intel Celeron something.
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: Segfault thread
« Reply #3 on: September 11, 2009, 02:09:26 pm »

Doesn't sound like it's a hardware compatibility issue at all. I'd really like to crash the game and do a stack trace to see where exactly in the loading function it's getting hung up. I'm baffled that it would do this for Linux and not for Windows builds.
Logged

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: Segfault thread
« Reply #4 on: September 11, 2009, 02:27:45 pm »

There is no visible stacktrace, I'm afraid, apart from the text "Muistialueen ylitys" which is Finnish for segmentation fault, and the game closes and returns to console after that. As an interesting side note, one can still play from different user accounts, until they are segfaulted too. Also if I recall correctly when this happened in the older version 3.19.4 it crashed on the Elite Liberals screen for some accounts and on the very first startup screen for the others, but I couldn't reproduce it right now. I'll be very grateful if a fix is found. If there's some log file that would be useful, just tell me and I'll send it to you.
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Ari Rahikkala

  • Bay Watcher
    • View Profile
Re: Segfault thread
« Reply #5 on: September 11, 2009, 05:55:49 pm »

I take it you're on a 64-bit Linux box. The save/load code gets tripped up by ints being 32 bits wide while longs are 64 bits. (on 32-bit Linux and any Windows they're both 32 bits so the bug doesn't manifest)

Here's a quick attempt at a fix that shouldn't break save compatibility for Windows users:

Code: [Select]
Index: src/title/saveload.cpp                       
===================================================================
--- src/title/saveload.cpp      (revision 337)                     
+++ src/title/saveload.cpp      (working copy)                     
@@ -233,7 +233,7 @@                                               
                                                                   
             if(squad[sq]->squad[pos]!=NULL)                       
             {                                                     
-               numbytes=fwrite(&squad[sq]->squad[pos]->id,sizeof(long),1,h);
+               numbytes=fwrite(&squad[sq]->squad[pos]->id,sizeof(int),1,h);
             }                                                               
          }                                                                 
                                                                             
@@ -250,7 +250,7 @@                                                         
       numbytes=fwrite(&dummy_c,sizeof(char),1,h);                           
       if(activesquad!=NULL)
       {
-         numbytes=fwrite(&activesquad->id,sizeof(long),1,h);
+         numbytes=fwrite(&activesquad->id,sizeof(int),1,h);
       }

       //DATES
@@ -526,10 +526,11 @@
             squad[sq]->squad[pos]=NULL;
             if(dummy_c)
             {
-               fread(&dummy_l,sizeof(long),1,h);
+               int dummy_i;
+               fread(&dummy_i,sizeof(int),1,h);
                for(int pl=0;pl<pool.size();pl++)
                {
-                  if(pool[pl]->id==dummy_l)
+                  if(pool[pl]->id==dummy_i)
                   {
                      squad[sq]->squad[pos]=pool[pl];
                   }
@@ -550,10 +551,11 @@
       fread(&dummy_c,sizeof(char),1,h);
       if(dummy_c)
       {
-         fread(&dummy_l,sizeof(long),1,h);
+        int dummy_l;
+         fread(&dummy_i,sizeof(int),1,h);
          for(int sq=0;sq<squad.size();sq++)
          {
-            if(squad[sq]->id==dummy_l)
+            if(squad[sq]->id==dummy_i)
             {
                activesquad=squad[sq];
                break;
Logged

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: Segfault thread
« Reply #6 on: September 12, 2009, 01:43:34 am »

Thank you, I'll check the code and attempt recompilation.

Or perhaps it's just better to wait until Jon can check it and import it in the code. My computer skills are good but limited to very strange areas ^^.
« Last Edit: September 12, 2009, 03:15:34 am by Kay12 »
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: Segfault thread
« Reply #7 on: September 12, 2009, 03:49:48 am »

Ari, feel free to commit those changes -- you should have access using your Sourceforge username and password now. Thanks for realizing it was a 32 bit/64 bit issue; this isn't the first time that happened, but I keep forgetting about it. I probably created this problem myself by converting one of the longs to an int in includes.h, but not in saveload.cpp. I've been trying to push all the incidences of long to int due to the ambiguity with long here.
Logged

Ari Rahikkala

  • Bay Watcher
    • View Profile
Re: Segfault thread
« Reply #8 on: September 12, 2009, 05:05:18 am »

Committed. Kay12, please update from svn and check if the game works now.

If it still crashes, please follow http://www.network-theory.co.uk/articles/gccdebug.html to get a backtrace of the crash and post it here - or if you feel at home in gdb you can run the game from it and just follow http://dirac.org/linux/gdb/07-Debugging_Ncurses_Programs.php to keep the debugger and game from fighting over one terminal.

If you've already compiled the code earlier you can recompile it for debugging with:

Code: [Select]
make clean
CXXFLAGS="-O0 -g" ./configure
make
Logged

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: Segfault thread
« Reply #9 on: September 12, 2009, 05:50:42 am »

It won't compile. I did everything like I did earlier, but something's failing in make. Here's the printed code from what most likely contains clue to the cause.

title/saveload.cpp: In function ‘void save()’:
title/saveload.cpp:36: warning: deprecated conversion from string constant to ‘char*’
title/saveload.cpp: In function ‘void autosave()’:
title/saveload.cpp:44: warning: deprecated conversion from string constant to ‘char*’
title/saveload.cpp: In function ‘void savegame(char*)’:
title/saveload.cpp:57: warning: deprecated conversion from string constant to ‘char*’
title/saveload.cpp: In function ‘char load()’:
title/saveload.cpp:334: warning: deprecated conversion from string constant to ‘char*’
title/saveload.cpp:334: warning: deprecated conversion from string constant to ‘char*’
title/saveload.cpp:555: error: ‘dummy_i’ was not declared in this scope
title/saveload.cpp: In function ‘void reset()’:
title/saveload.cpp:653: warning: deprecated conversion from string constant to ‘char*’

EDIT: I browsed the source and here's the broken code block. Perhaps it's a typo l vs i in the declaration "int dummy_l"?
FURTHER EDIT: Confirmed, I tested by modifying the source myself.

Code: [Select]
if(dummy_c)
{
 int dummy_l;
 fread(&dummy_i,sizeof(int),1,h);
 for(int sq=0;sq<squad.size();sq++)
 {
  if(squad[sq]->id==dummy_i)
  {
   activesquad=squad[sq];
   break;
  }
 }
}
« Last Edit: September 12, 2009, 06:12:26 am by Kay12 »
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Ari Rahikkala

  • Bay Watcher
    • View Profile
Re: Segfault thread
« Reply #10 on: September 12, 2009, 06:25:08 am »

Well, that's a good start for me, typoing in my first commit  :D

Easily fixed just as you pointed out and committed though, how's it working now?
« Last Edit: September 12, 2009, 09:15:33 am by Ari Rahikkala »
Logged

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: Segfault thread
« Reply #11 on: September 12, 2009, 06:27:44 am »

Not too well. Freezes on startup in what seems to be an infinite loop. The only text printed is the sitmaps.txt missing thing if not treated, otherwise blank. Intense processor hogging. I'm checking the fixes you made for potential causes, but it has to be something general because I don't know C++ or whatever this is.

Quote
Well, that's a good start for me, typoing on my first commit

Well, my first commitment was fixing someone else's typo :D.
« Last Edit: September 12, 2009, 06:51:00 am by Kay12 »
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Ari Rahikkala

  • Bay Watcher
    • View Profile
Re: Segfault thread
« Reply #12 on: September 12, 2009, 07:44:13 am »

The only thing I actually tested was starting a new game (having removed ~/.lcs/save.dat first), immediately exiting, and coming back to check if the basemode screen still looks OK. That works for me with the current code... are you doing anything in-game before saving? There could be other bugs in saveload.cpp that I'm not hitting because I haven't got any data to save.

If not, I think you're going to have to run the game in gdb as per the link a couple of posts back... press ctrl-c on the gdb window once the game's into the infinite loop and get a backtrace (preferably with the command "backtrace full") so we can see what might be up...
Logged

Kay12

  • Bay Watcher
  • Fighting for Elite Liberal values since 2009!
    • View Profile
Re: Segfault thread
« Reply #13 on: September 12, 2009, 08:03:11 am »

Hooray it works now, I forgot o remove the save file. Thanks guys!
Logged
Try Liberal Crime Squad, an excellent Liberal Crime adventure game by Toady One and the open source community!
LCS in SourceForge - LCS Wiki - Forum thread for 4.04

Jonathan S. Fox

  • Bay Watcher
    • View Profile
    • http://www.jonathansfox.com/
Re: Segfault thread
« Reply #14 on: September 12, 2009, 12:27:20 pm »

Awesome. Thank you Ari Rahikkala, that was not a bug I was likely to figure out myself, at least not in a reasonable time frame.
Logged
Pages: [1] 2