Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Segfault when trying to open inventory after acquiring new item via dialogue #531

Open
phobos2077 opened this issue Apr 24, 2017 · 5 comments
Labels

Comments

@phobos2077
Copy link
Contributor

Description

A Segfault when trying to open inventory after acquiring new item via dialogue.
InventoryItem.cpp:137 (render function)

System

OS: Ubuntu 17.04 x64
Compiler: GCC

Steps to reproduce

  1. Start the game on arvillag map.
  2. Talk to the Elder.
  3. Be obedient and she will give you money and a flask.
  4. Close dialog.
  5. Try opening inventory.
@phobos2077 phobos2077 added the bug label Apr 24, 2017
@Zervox
Copy link
Contributor

Zervox commented Apr 25, 2017

Seems that the items given returns inventoryUI null even though from what I can see it is being created.

this is really the only difference I could find

Elder uses OP 8116 add_mult_objs_to_inven and its remove OP 8117
OP 8117 has no behavior about erasing pointer from original owner's inventory
Elder also calls OP 80B7 to create the given items(seems like it is a issue with the datastack creation of the object?)

slim in klamall uses OP 80D8 add_obj_to_inven and works fine.

@JanSimek
Copy link
Contributor

JanSimek commented Sep 24, 2017

The flask is created using create_object_sid(267, 0, 0, -1); in the Elder's script which calls Location::addObject() in the engine and there it is placed in the object list. Opcode8116 calls removeObjectFromMap() which removes the object, so in the inventory there is now a dangling pointer to a nonexisting object.

I don't know how it worked in the original game, but I presume that when you create an object with location set to 0 then you don't want it to appear on the map.

@JanSimek
Copy link
Contributor

This is my workaround for now:

--- a/src/VM/Handler/Opcode8116Handler.cpp
+++ b/src/VM/Handler/Opcode8116Handler.cpp
@@ -27,6 +27,7 @@
 #include "../../Game/CritterObject.h"
 #include "../../Game/Game.h"
 #include "../../Game/Object.h"
+#include "../../Game/ObjectFactory.h"
 #include "../../Logger.h"
 #include "../../State/Location.h"
 #include "../../VM/Script.h"
@@ -73,16 +74,19 @@ namespace Falltergeist
                     return;
                 }
 
-                inven->push_back(item);
+                Game::ItemObject* copy = item;
 
                 if (item->hexagon())
                 {
                     auto location = Game::Game::getInstance()->locationState();
                     if (location)
                     {
+                        copy = (Game::ItemObject*)Game::ObjectFactory::getInstance()->createObject(item->PID());
                         location->removeObjectFromMap(item);
                     }
                 }
+
+                inven->push_back(copy);
             }
         }
     }

@alexeevdv
Copy link
Contributor

@JanSimek Thanks! I'll check this on weekend when i'll have some time :)

@JanSimek
Copy link
Contributor

JanSimek commented Feb 22, 2018


EDIT: nevermind, the `ahelder.int` script checks for map index and since commit cc9d4d72f92b2454de1b5ab40f51040480b18479 `loadAmbient()` function where the current map index was set is now commented out, so I made this change in src/State/Location.cpp 

```diff
-            //loadAmbient(name);
+            loadAmbient(location()->name());
```

to get the right dialog and it still crashes.

EDIT2: I found a possible fix in one of the Falltergeist forks, but it doesn't seem to work as the crash still happens: https://github.com/thives/falltergeist/commit/57e27d4cf94b1ab1c90d193c5c81118259c9b02b

JanSimek added a commit to JanSimek/falltergeist that referenced this issue Nov 11, 2018
JanSimek added a commit to JanSimek/falltergeist that referenced this issue Nov 11, 2018
JanSimek added a commit to JanSimek/falltergeist that referenced this issue May 1, 2020
Prevent dangling pointers when removing obj from map. Closes falltergeist#531, cl…
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants