CleverRaven / Cataclysm-DDA

Cataclysm - Dark Days Ahead. A turn-based survival game set in a post-apocalyptic world.
http://cataclysmdda.org
Other
10.08k stars 4.1k forks source link

Seg Fault While Unloading Guns #52775

Closed LeahLuong closed 2 years ago

LeahLuong commented 2 years ago

Describe the bug

Game crashed while removing clips & ammo from guns I'd obtained in a lab magazine. My invo was rather full & I believe the crash may be related to #48765; I think the full invo was causing some shenanigans w/ how the unloads were being handled & perhaps the game tried to auto-save while this was going on. On reloading the game, I got 3 specific error messages regarding problematic item handling & the game pooped out again. This has happened twice & I can probably copy down the error messages sequentially by reloading the game again if you need more info. I've included the latest crash.log below as well as the the most recent debug.log entries. I believe the debug.log entries contain the 3 error messages I get on reloading the game. I'm seemingly unable to continue the game due to this segmentation fault.

HELP ME!!!

Steps To Reproduce

IDK how to reproduce this but I can probably post my save or something if you need more info.

Expected behavior

I expected to reload my game & continue as I usually do, perhaps losing a few stray bullets or a clip to the void as opposed to all my progress on a char who's survived almost the entire 1st summer.

Screenshots

No response

Versions and configuration

Android 0.F-2 Tiles English vanilla

Additional context

crash.log follows: VERSION: 0.F-2 Signal SIGSEGV: Segmentation fault STACK TRACE:

3: 0xb4bcb838 art::FaultManager::HandleFault(int, siginfo, void)

5: 0xa0b76c44 item_contents::has_pocket_type(item_pocket::pocket_type) const

6: 0xa076067e unload_activity_actor::unload(Character&, item_location&)

7: 0xa0f8d2f2 player_activity::do_turn(player&)

8: 0xa0a24988 game::process_activity()

9: 0xa0a23464 game::do_turn()

10: 0xa0c923b4 SDL_main

11: 0xa1ed4e2a Java_org_libsdl_app_SDLActivity_nativeRunMain

debug.log follows: 21:14:24.405 INFO : Cataclysm DDA version 0.F-2 21:14:24.406 INFO : [main] C locale set to C 21:14:24.406 INFO : [main] C++ locale set to 21:14:24.406 INFO : SDL version used during compile is 2.0.12 21:14:24.406 INFO : SDL version used during linking and in runtime is 2.0.12 21:14:24.796 INFO : [options] C locale set to C 21:14:24.796 INFO : [options] C++ locale set to en_US.UTF-8 21:14:24.796 INFO : Read Android system language: 'en_US' 21:14:24.796 INFO : Setting language to: 'en' 21:14:24.797 INFO : Language is set to: 'en' 21:14:26.126 INFO : USE_COLOR_MODULATED_TEXTURES is set to 0 21:14:26.314 INFO : Read Android system language: 'en_US' 21:14:26.314 INFO : Setting language to: 'en' 21:14:26.314 INFO : Language is set to: 'en' 21:14:28.260 WARNING : opendir [/storage/emulated/0/Android/data/com.cleverraven.cataclysmdda/files/mods/] failed with "No such file or directory". 21:15:11.209 WARNING : opendir [/storage/emulated/0/Android/data/com.cleverraven.cataclysmdda/files/save/Irving/mods] failed with "No such file or directory". 21:15:47.290 INFO : Loaded tileset: neodays 21:16:08.862 ERROR : (error message will follow backtrace)#01: 0xa0962aa4 DebugLog(DebugLevel, DebugClass)

02: 0xa0962650 realDebugmsg(char const, char const, char const*, std::ndk1::basic_string<char, std::__ndk1::char_traits, std::ndk1::allocator > const&)

03: 0xa07daa20 void realDebugmsg(char const, char const, char const, char const, int&&)

04: 0xa0bb1d26 item_location::impl::item_on_person::ensure_who_unpacked() const

05: 0xa0bb1ca6 item_location::impl::item_on_person::valid() const

06: 0xa0bafc5e item_location::deserialize(JsonIn&)

07: 0xa076d82a _ZN6JsonIn4readI13item_locationEEDTcmcldtfp_11deserializedefpTELb1EERT_b

08: 0xa0760c96 unload_activity_actor::deserialize(JsonIn&)

09: 0xa07674b6 deserialize(cata::clone_ptr&, JsonIn&)

10: 0xa103df40 _ZN6JsonIn4readIN4cata9clone_ptrI14activity_actorEEEEDTcmcl11deserializefp_defpTELb1EERT_b

11: 0xa1022a80 player_activity::deserialize(JsonIn&)

12: 0xa104053a _ZN6JsonIn4readI15player_activityEEDTcmcldtfp_11deserializedefpTELb1EERT_b

13: 0xa10249d2 Character::load(JsonObject const&)

14: 0xa1029fcc player::load(JsonObject const&)

15: 0xa102affc avatar::load(JsonObject const&)

16: 0xa102afb0 avatar::deserialize(JsonIn&)

17: 0xa101fa98 _ZN6JsonIn4readI6avatarEEDTcmcldtfp_11deserializedefpTELb1EERT_b

18: 0xa1019162 game::unserialize(std::__ndk1::basic_istream<char, std::__ndk1::char_traits >&)

19: 0xa0863d4c read_from_file(std::ndk1::basic_string<char, std::__ndk1::char_traits, std::ndk1::allocator > const&, std::ndk1::function<void (std::ndk1::basic_istream<char, std::__ndk1::char_traits >&)> const&)

20: 0xa0a2f4a2 game::load(save_t const&)

21: 0xa0c98eee main_menu::load_character_tab(bool)

22: 0xa0c96bba main_menu::opening_screen()

23: 0xa0c92390 SDL_main

24: 0xa1ed4e2a Java_org_libsdl_app_SDLActivity_nativeRunMain

Backtrace emission took 1 seconds. (continued from above) ERROR : /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/item_location.cpp:290 [bool item_location::impl::item_on_person::ensure_who_unpacked() const] Failed to find item_location owner with character_id 1 21:16:20.571 ERROR : /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/item_location.cpp:290 [bool item_location::impl::item_on_person::ensure_who_unpacked() const] Failed to find item_location owner with character_id 1 21:16:20.571 ERROR : /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/item_location.cpp:114 [void item_location::impl::ensure_unpacked() const] item_location lost its target item during a save/load cycle 21:16:22.841 ERROR : /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/item_location.cpp:784 [void item_location::deserialize(JsonIn &)] parent location does not point to valid item 21:17:52.565 ERROR : (error message will follow backtrace)#01: 0xa0962aa4 DebugLog(DebugLevel, DebugClass)

02: 0xa0962650 realDebugmsg(char const, char const, char const*, std::ndk1::basic_string<char, std::__ndk1::char_traits, std::ndk1::allocator > const&)

03: 0xa0733ab6 void realDebugmsg<>(char const, char const, char const, char const)

04: 0xa0bb0cc6 item_location::impl::ensure_unpacked() const

05: 0xa0bb08b4 item_location::get_item()

06: 0xa0760678 unload_activity_actor::unload(Character&, item_location&)

07: 0xa0f8d2f2 player_activity::do_turn(player&)

08: 0xa0a24988 game::process_activity()

09: 0xa0a23464 game::do_turn()

10: 0xa0c923b4 SDL_main

11: 0xa1ed4e2a Java_org_libsdl_app_SDLActivity_nativeRunMain

Backtrace emission took 0 seconds. (continued from above) ERROR : /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/item_location.cpp:114 [void item_location::impl::ensure_unpacked() const] item_location lost its target item during a save/load cycle

PatrikLundell commented 2 years ago

If your save folder is small enough, you can zip it up and attach it to the report.

LeahLuong commented 2 years ago

I compressed my 239MB save folder into a 30MB save.zip but it's not letting me attach it here. It says it fails to upload & "is not included in the list" despite ZIP being listed as an acceptable format.

Also, I got the 2nd issue number above wrong; #44772, not what I posted before. This issue was merged w/ #44850 & later closed but I think my issue is closely related. I believe my game initially crashed @ a point where I didn't have room for additional clips. It was having me wield the empty clips while dropping previous 1's. I think it autosaved while trying to split bullets between any spare space I had in pockets & the ground. Now, the game is seemingly unable to progress because it can't find item locations or somesuch on reload.

PatrikLundell commented 2 years ago

The zipped save ought to be small enough: I think the limit is 100 MB or something like that.

Regarding the incorrect reference, you can update the original post using the "..." "button".

LeahLuong commented 2 years ago

I removed the pointer to the incorrect issue.

The "..." is what I'm trying to use to attach the save.zip but it's not letting me. Am I doing something wrong??

PatrikLundell commented 2 years ago

Ah, yes, I think it's "easier", as in drag-and-drop into the ordinary text fie (just tested that with a .png, and it started an upload before I cancelled it).

LeahLuong commented 2 years ago

I don't follow. I'm doing this on my Android phone so my options may be limited. I zipped my save using ZArchiver & when I use "..." to "Edit" a previous comment I only have the option of pointing to the save.zip in my File Manager. It fails to open & tells me "is not included in the list" @ the bottom of the comment I'm attempting to edit where you normally click to upload a file.

PatrikLundell commented 2 years ago

Hm, it looks like this page works differently on a phone compared to a PC then. When I use "..." and then select "Edit" there's a dotted line at the bottom of the post and text beneath saying "Attack files by dragging & dropping, selecting or pasting them."

It looks like we need to await the arrival of someone who knows how the phone interface works.

LeahLuong commented 2 years ago

Yeah, I have that box. It defaults to trying to upload a picture from my phone's Gallery but I have the option of uploading from elsewhere. I tap on File Manager & can dig out my save.zip but I've already told you what happens; "is not included in the list" is the feedback I get from that box.

PatrikLundell commented 2 years ago

If it was a PC I'd try to copy the zip file to the Gallery place it defaults to looking for files in, but I have no idea how to work a phone.

LeahLuong commented 2 years ago

I attempted your suggestion but received the same result. I was able to move save.zip to the folder where my Camera's images are stored but attempting to attach it only showed me the images. I could still tap on File Manager, go to the folder where the images are stored, see save.zip sitting next to the image files whose images I could see, & select save.zip for attachment. No dice.

I think there is some issue w/ save.zip itself or this site's attachment function w/ regards to my phone. ZArchiver originally compressed my save into the .7z format as its default. That's why the attachment box had listed acceptable formats to me. ZArchiver can also make .zip's so now I'm getting the aforementioned feedback instead of the list. Strange that it would tell you the list when not uploading acceptable formats but say "is not in the list" when uploading an ostensibly good 1.

PatrikLundell commented 2 years ago

Ugh! If that doesn't work I'd try to change the extension to .png (or whatever format your images are in). Obviously with an explanation that you'd need to change the extension back should the trick actually work.

LeahLuong commented 2 years ago

Got a different result. Camera images are stored as .jpg. Renaming save.zip to "save.jpg" still didn't show up in the default Gallery for attachment but I could dig it up through the File Manager:

"Yowza that's a big file. Try again with a file size less than 10MB."

Note, I did attempt to preempt all this wheelspinning @ the beginning by stating the size of the save both compressed & not.

Is there a way to pare the file size down further or should we try something else??

PatrikLundell commented 2 years ago

It might be that there are different size limits for images and zip files. The limit for saves is definitely larger than 10 MB, unless something has changed in the last year or so, but I did eventually get a save that grew too large (when zipped) for the upload limit.

LeahLuong commented 2 years ago

Good to know but it's not accepting the upload either way. Tried changing to "save.ZIP" just in case case matters. It doesn't. What now??

PatrikLundell commented 2 years ago

Hope somebody who actually know how to do this from a phone decides to help.

LeahLuong commented 2 years ago

Is there a way to edit my save file to eliminate the offending items so there is no longer a segmentation fault?? It seems ToxiClay was able to find a solution like this in #48765.

PatrikLundell commented 2 years ago

If you can identify what to remove, then yes, in principle. The save consists of a large number of JSON files, which are enormous oneliners of text. Hacking/editing can thus be done using a normal text editor. Items on the ground are found in the file that contains the contents of the overmap coordinates at which they are, while I would guess items in the inventory is stored in a different file. I've been able to find the "current" overmap file by looking at time stamps, as the file for the location you're at should be among the set saved at the last save point, and I would assume the inventory likewise has been changed recently.

If you're going to try to modify files, make sure to make a backup first so you can restore them when/if things go horribly wrong (you may well know that already, but better warn one time too many than one time too few).

I have done some light hacking in the map files (I thing the were just experiments, but not saved), but haven't tried to hack items (if things aren't screwed up as badly as they are in your case, it's easier and safer to use debug commands to spawn items, and I've done that at least once when I was completely convinced the quest item actually was nowhere to be found).

LeahLuong commented 2 years ago

I was able to locate the map file where my char is standing using timestamps but I believe the problem item is in my char's invo; likely the clip I was unloading when the crash happened. I believe the file labeled "o.0.0" contains that info but it tells me it's too big to be opened in my device. It's 20MB. Would I be able to upload that file, have the offending item(s) edited out, & the file returned to me?? I've already made a backup of my save.

PatrikLundell commented 2 years ago

We can try... However, you're probably targeting the wrong file. That one seems to contain general overall info, while a file called [alphanumsequence].sav had a match for "protein" (the save I used had a character with protein bars in the inventory), and it looks like it lists the character's inventory.

LeahLuong commented 2 years ago

I'd looked @ my .sav but was unable to scroll to the bottom. My phone becomes progressively boggier the further down I get despite the file's relatively small size: 2.36MB. Eventually, my File Manager becomes unresponsive & I have to close it. The file seemed to contain a lot of junk info like every single item my char has consumed & every single kill I've accumulated w/ what weapon on an individual basis. There was already a kill list broken down by monster type. I also saw a list of current CBM's in there. But the file seemed absolutely dominated by "total_time_played" & "time_since_load" entries measured in "chrono_seconds"; I don't see how that spam is helping anyone & doesn't seem like a reflection of my actual play history because the entries seemed to be listing random numbers & seemed way more numerous than actual play sessions. I was unable to find anything that looked like my char's current invo.

Regardless, I'll attempt to attach it to this message once it posts & perhaps you can make some sense of it. #TGVhaCBMdW9uZw==.txt

Of course, .sav is not a supported file type so you may need to revert from .txt. That's the suffix I changed on this file.

PatrikLundell commented 2 years ago

OK, I've tried to hack the file, removing a bazillion magazines from your lab grab everything run (and can't guarantee I haven't missed any). However, it's very error prone, so I wouldn't expect it to work. I used Notepad++, which has some basic understanding of JSON, so it helped me with matching up parenthesis, but still.

TGVhaCBMdW9uZw.txt

LeahLuong commented 2 years ago

Hey, good news: I didn't get any of the debug error messages I was getting before on reloading the save. The bad news is there was a whole slew of new 1's that finally resulted in the game asking if I wanted to watch my last moments. I closed the game @ that point. Here's a copy of the 1st error message: DEBUG : Bad save json Json error: :22:540026: comma not allowed at end of array

"_sealed": false }, { "pocket_type": 0, "contents": [ { "typeid": "blt", "charges": 3, "owner": "your_followers", "active": true, "last_temp_check": 14784994, "item_tags": [ "FROZEN" ], "specific_energy": 50949824, "temperature": 25474912 }, ^ ], "_sealed": false }, { "pocket_type": 0, "contents": [ { "typeid": "chem_aluminium_powder", "charges": 100, "owner": "your_followers", "last_temp_check": 0 } ], "_sealed": false }, { "pocket_type": 0, "contents": [ { "typeid": "oxy_powd

FUNCTION : void game::unserialize(std::istream &) FILE : /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/savegame.cpp LINE : 238 VERSION : 0.F-2 The other messages seemed to indicate many submap elements were missing, a camp had failed to hoist @ my char's location, my vehicle had been deleted, & my char's left leg was somehow missing. I deleted the hack & popped my backup save back in & got the same 3 errors as before w/ accompanying seg fault.

So, this seems like a partial success. Removing the mags eliminated the seg fault but had the unintended consequence of killing my char. Can we somehow be more surgical about it & avoid killing my char so I can explore the gamestate more from within??

PatrikLundell commented 2 years ago

Well, the error message says there's a comma too much at the ½ million:th character on line 22, which was easy to find (just search for the temperature value). It's the kind of mistakes that this sort of manual editing is prone to.

TGVhaCBMdW9uZw.txt

I suspect the death is a result of the failure to parse the JSON file. I hesitate to call this hacking "surgical" as it's more of a shotgun hail of slugs removing what looks like they may be magazines...

Edit: I wouldn't make too much out of the previous messages not appearing, as the processing probably aborted before it got to them.

LeahLuong commented 2 years ago

Another step forward but 2 steps back, it appears. I didn't get any of the debug errors from last time but several new 1's have appeared & it looks like the old seg fault has reared its ugly head again: DEBUG : Failed to find item_location owner with character_id 1

FUNCTION : bool item_location::impl::item_on_person::ensure_who_unpacked() const FILE : /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/item_location.cpp LINE : 290 VERSION : 0.F-2 That's the 1st of the 3 messages I get on the old save & this new 1. The other 2 appear to be dupes as well & inevitably lead to a crash once the save loads. In addition to those, it appears my starting scenario was nullified & defaulted to "Evacuee", several random books made it into my active or failed missions, & many, many field names were invalidated or misplaced.

Perhaps another approach is warranted. In #48765, ToxiClay was able to set the char's current activity to "NULL" & that seemed to allow the game to progress past the fault. The error message above references line 290. Maybe nullifying the char activity can work in this case??

EDIT: wanted to get the other 2 messages in here so they're all in 1 place. Strangely, the 1st 1(above) seems duped because I have to press space twice to get past it but nothing onscreen changes. DEBUG : item_location lost its target item during a save/load cycle

FUNCTION : void item_location::impl::ensure_unpacked() const FILE : /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/item_location.cpp LINE : 114 VERSION : 0.F-2

DEBUG : parent location does not point to valid item

FUNCTION : void item_location::deserialize(JsonIn &) FILE : /var/lib/jenkins/workspace/Cataclysm-Android/android/app/jni/src/../../../../src/item_location.cpp LINE : 784 VERSION : 0.F-2

PatrikLundell commented 2 years ago

I think clearing the broken activity is a more promising (and less invasive) approach. I went back to the original file (with all the mags in it) and tried to replace "activity" with ACT_NULL, removing all the parameters (and one parameter mentioned a character id of 1, so if it doesn't work we might try -1, as that seems to be what other self references use). However, I don't know if this entry interacts with earlier entries, such as "current_activity" with a value of 1.0... TGVhaCBMdW9uZw.txt

LeahLuong commented 2 years ago

Good work, Patrik, I believe you've done it! Nullifying the activity seems to have rewound time to just before the crash where I was able to make room in my invo & complete unloading the clips. It's a shame we didn't act on this sooner based on the 1st 2 sentences in this lengthy thread.

I'll go ahead & close this issue once it falls off the front page & if nothing else comes up. Thank you for saving my game from the jaws of the debug monster.

PatrikLundell commented 2 years ago

Congratulations!

I didn't rewind time as much as ditching a partially performed task, so the task would have to be restarted from scratch.

Personally I disable the auto save and try to make backups of my save file from time to time so I have some refuge when the contents of the bucket hits the fan. That also invites the save scumming monster to the party, and I've made use of its services more than once, so if you hate that particular monster and don't trust your ability to withstand temptation it might not be something for you.

LeahLuong commented 2 years ago

It happened again. @ least, something very similar. The ice lab I've been plundering still had some bionic prisoners to "salvage", 1 more barracks to clear, & I still need to unfreeze the mutagen in the standing tank @ the bottom. I'd gotten in a couple of hours of play, obtaining those filthy CBM's & dragging all the remaining weaponry up to my vehicle. I'd unloaded all the guns & was using the advanced invo manager to clear out my pack into the car when the game crashed. Reloading showed me the same debug errors as before & crashed out, just like before.

It's looking like the problem may simply be the game fumbling my char's action during an autosave but it may be something deeper. I've been running this char for a couple of months now & the game regularly crashes on me, usually w/out anything lost besides a min or 2 going back to the last autosave, especially while driving around. I think this is because my phone "only" has a gig of RAM & covering a lot of in-game ground taxes it. I also get crashes when almost nothing is going on, like here where I'm sitting on a dead lab w/ just some containment prisoners & cleaning bots. I'm hoping this is simply a freak occurence where the autosave happened simultaneously w/ a random crash but it's worrying it's happened twice like this so close together.

Could you please fix my .sav like you did before?? #TGVhaCBMdW9uZw==.txt

PatrikLundell commented 2 years ago

I've modified the file the same way as before (or at least I think I've done so). Whether it works is another matter... TGVhaCBMdW9uZw.txt

I'd definitely recommend turning off auto save and only save manually. That ought to work around this bug, at least (and the bug ought to be fixed, but that obviously takes time).

I GB isn't much in current day PC game terms, and probably isn't on a phone either, and I don't even know if phones support virtual memory. However, with reasonable programming running out of memory should give a corresponding error report, not a seg fault, but the game is written in High Level Assembly (a.k.a. C(++), a language where the standard procedure is to never check for errors in order to run as quickly as possible (including off the rail).

LeahLuong commented 2 years ago

Thank you, again. This lets me move past the seg fault once more. 1 thing to note: the game loaded to where I was outside the vehicle & still had a couple of clips to unload. I know the crash happened after I'd unloaded everything & was in the car sorting things into cargo spaces. The seg fault may still have something to do w/ unloading guns & ammo.

I don't think turning off autosave is going to help. A crash could still happen during a manual save & the game poops out frequently enough that not having a recent point to recoup from would be extremely frustrating. I can try dialing back the autosave frequency when I'm not driving around but perhaps these seg faults are a sign that my game file is becoming too unwieldy for my phone to handle. After all, I can't even manually open the o.0.0 file on this device & I'm seemingly unable to make the repair like you can because the .sav is unable to scroll far enough down before becoming unresponsive.

I've also noticed some really long, occasional pauses in gameplay while raiding this lab that I wasn't getting before; I drove a few overmap sections to get here (7, going by the coord system in the maps folder) in order to complete a refugee center mission. Before this, I was mainly tooling about in the section where I started. 1 of these pauses seems to always occur shortly after loading into the game, then semi-regularly after. Hopefully, these long pauses stop when I get back over by the refugee center. I just need to thaw the mutagen, load up the car & head back.

PatrikLundell commented 2 years ago

Sounds to me that there are (at least) two issues here:

Pauses frequently happens when there's a lot the game processes. I get that when returning to base due the the amount of junk stored there, and in the past (0.E stable) it happened while driving and carrying a medium number of Merchs (due to them not being a stack but a few hundred individual items, and some logic moved them from tile to tile or something, rather than just moving the PC and have them just being in the inventory, wherever the inventory was located). That's long since fixed, although the buggers still don't stack.

I think the shoddy editor you've got on the phone doesn't have the problem with vertical movement, but rather horizontal. as the file consists of 30 or so lines, some of which are extremely long. In order to edit it I had to either improve my hand/eye/cursor coordination to never stray one line up/down while painting what should be removed, or cut up the line using newlines which I then remove when done (because straying up/down move the focus to the closest location on that line, which was nowhere near the location of the target line, resulting in the need to scroll sideways for hundreds of thousands of characters to get back if insisting on still painting).

LeahLuong commented 2 years ago

I decided to take your recommendation after realizing I won't be able to manually save mid-action. I still need to turn on autosave while driving because the frequent saves seem to keep the overflowing memory bank somewhat under control. Otherwise, the game crashes every 10 or so map tiles unless a save has happened. The worst I've seen happen so far is a failed autosave placing my vehicle @ the previous autosave's location w/ its velocity & heading set from when the last save happened. I've installed drive-by-wire controls & have the radio controller bionic to bring it to a safe halt.

The long pauses seemingly stopped once I left the vicinity of the ice lab. I might've gotten 1 shortly after it had left my reality bubble. I think it was doing temperature checks on everything in the lab.