FIFE forums

Please login or register.

Login with username, password and session length
Advanced search  

News:

FIFE 0.4.0 has been released on 15th of January, 2017!

Author Topic: [UH] Segfault because of invalid element in m_actionlisteners  (Read 2365 times)

totycro

  • Newbie
  • Posts: 17
    • View Profile
[UH] Segfault because of invalid element in m_actionlisteners
« on: August 19, 2009, 06:28:02 pm »

Hi,

We are having a segfault in uh with this bt:
Code: [Select]
#0  0x0b441688 in ?? ()
#1  0xb7278fec in FIFE::Instance::finalizeAction (this=0xb47a8d0) at engine/core/model/structures/instance.cpp:417
#2  0xb727b42c in FIFE::Instance::update (this=0xb47a8d0) at engine/core/model/structures/instance.cpp:374
#3  0xb727f28b in FIFE::Layer::update (this=0x8ac9d88) at engine/core/model/structures/layer.cpp:227
#4  0xb72834d9 in FIFE::Map::update (this=0x8ac8d90) at engine/core/model/structures/map.cpp:119
#5  0xb7286635 in FIFE::Model::update (this=0x8748458) at engine/core/model/model.cpp:264
#6  0xb723d40e in FIFE::Engine::pump (this=0x81e92b0) at engine/core/controller/engine.cpp:305
#7  0xb7408b07 in _wrap_Engine_pump (args=0xb05506c) at engine/swigwrappers/python/fife_wrap.cxx:25646
#8  0xb7e39164 in PyCFunction_Call () from /usr/lib/libpython2.6.so.1.0
#9  0xb7c19fd4 in ?? ()
#10 0xb76e2750 in ?? ()
#11 0xb7ee0c14 in ?? () from /usr/lib/libpython2.6.so.1.0
#12 0xb7ed3ff4 in ?? () from /usr/lib/libpython2.6.so.1.0
#13 0x0804b050 in ?? ()
#14 0x0b05506c in ?? ()
#15 0xffffffff in ?? ()
#16 0xb7e7f73c in PyEval_EvalFrameEx () from /usr/lib/libpython2.6.so.1.0
#17 0xbfa412a4 in ?? ()
#18 0x00000001 in ?? ()
#19 0x00000002 in ?? ()
#20 0xb7d994b8 in ?? () from /lib/libc.so.6
#21 0x0832e89c in ?? ()
#22 0xb7ee0d24 in _Py_SwappedOp () from /usr/lib/libpython2.6.so.1.0
#23 0xbfa412c8 in ?? ()
#24 0x01d993b0 in ?? ()
#25 0x00000170 in ?? ()
#26 0xb7d99380 in ?? () from /lib/libc.so.6
#27 0x96be1d8c in ?? ()
#28 0xb7e36f2a in ?? () from /usr/lib/libpython2.6.so.1.0
#29 0x0000002f in ?? ()

The corresponding fife code is this:
Code: [Select]
00415         std::vector<InstanceActionListener*>::iterator i = m_activity->m_actionlisteners.begin();
00416         while (i != m_activity->m_actionlisteners.end()) {
00417             (*i)->onInstanceActionFinished(this, action);
00418             ++i;
00419         }

So it seems, that there is a null ptr or invalid ptr in m_actionlisteners.
The only InstanceActionListener we use is in the Unit code. Does this mean, that this ActionListener isn't removed correctly?

The code for this can be seen here: http://trac.unknown-horizons.org/browser/trunk/horizons/world/units/unit.py
The InstanceActionListener is created and attached to the unit via addActionListener(). When the unit dies, we use removeActionListener(). Is this usage correct?
If yes, it might be possible, that removeActionListener isn't called. But if no, where could be the source of this error?

thanks,
totycro
Logged

phoku

  • Developer
  • Full Member
  • *
  • Posts: 102
    • View Profile
    • IZ dev blog
Re: [UH] Segfault because of invalid element in m_actionlisteners
« Reply #1 on: August 20, 2009, 02:27:55 am »

I'm pretty sure that's a FIFE issue.

Let me guess: The Unit dies and finishes it's death action. That triggers
removal of the ActionListener from inside the action callback.
And then, woosh, it crashes.

The loop which crashes isn't robust against changes of the listeners
during looping ...

So if you don't remove the action listener it should work.
It's still a FIFE problem, though.

-phoku
Logged

totycro

  • Newbie
  • Posts: 17
    • View Profile
Re: [UH] Segfault because of invalid element in m_actionlisteners
« Reply #2 on: August 23, 2009, 03:13:58 pm »

Sorry for the late answer.

The unit currenlty doesn't have a death action. It is just removed whatever it does.

I was told here that _not_ removing the actionlistener would cause a crash: http://forums.fifengine.net/index.php?topic=292.0

The Unit dying code currenlty looks like this:
Code: [Select]
# self._instance is returned by createInstance
self._instance.removeActionListener(self.InstanceActionListener)
self._instance.getLocationRef().getLayer().deleteInstance(self._instance)
self._instance = None
horizons.main.session.scheduler.rem_all_classinst_calls(self) # makes sure that the unit isn't used in the uh code anymore

Is there something wrong with this?
Logged

phoku

  • Developer
  • Full Member
  • *
  • Posts: 102
    • View Profile
    • IZ dev blog
Re: [UH] Segfault because of invalid element in m_actionlisteners
« Reply #3 on: August 24, 2009, 01:58:00 pm »

Recent changes might have fixed this.
Please scons and test again.

-phoku
Logged