Saving, loading simulation with erased bodies crash.

Bug #803774 reported by Kneib François
6
This bug affects 1 person
Affects Status Importance Assigned to Milestone
Yade
Fix Released
Low
Unassigned

Bug Description

Here is the bug :

- launch yade (for example without any script)
- add a sphere : O.bodies.append(utils.sphere((0.2,0.2,0.2),0.006))
- delete it : O.bodies.erase(0)
- save yade's universe : O.save("./test")
- quit yade
- launch yade
- load the file : O.load("./test")
->segmentation fault

I think it's because when you erase something the size of O.bodies (etc...) doesn't change and now contains an empty value. (the c++ array may not be dynamic ?)
So when the O.load() function is called, yade try to load a non-existant body ?

Maybe this can be fixed by changing the load() method ?

I joined the debug output.

Related branches

Revision history for this message
Kneib François (francois-kneib) wrote :
Revision history for this message
Bruno Chareyre (bruno-chareyre) wrote :

For futur readers, including myself: it seems a "if (p)" before a "p->" would help...

#7 0x00007ffcc32a6941 in *__GI___assert_fail (assertion=0x7ffcbb0eff24 "px != 0", file=<value optimized out>, line=418, function=0x7ffcbb113240 "T* boost::shared_ptr< <template-parameter-1-1> >::operator->() const [with T = Body]") at assert.c:81
#8 0x00007ffcbaec0d63 in boost::shared_ptr<Body>::operator-> (this=0x2197670) at /usr/include/boost/smart_ptr/shared_ptr.hpp:418
#9 0x00007ffcbae641d1 in InteractionContainer::clear (this=0x2197f60) at /home/francoisk/yade/core/InteractionContainer.cpp:32
#10 0x00007ffcbae6535c in InteractionContainer::postLoad__calledFromScene (this=0x2197f60, bb=...) at /home/francoisk/yade/core/InteractionContainer.cpp:158

Revision history for this message
Anton Gladky (gladky-anton) wrote :

Hopefully fixed in r2880.
Please, check it. If the problem still appears, do not hesitate to reopen a bug.

Changed in yade:
status: New → Fix Released
importance: Undecided → Low
Revision history for this message
Chiara Modenese (chiara-modenese) wrote : Re: [Yade-dev] [Bug 803774] Re: Saving, loading simulation with erased bodies crash.

Hi Anton,

I am currently affected by this bug. I am using an older release (but not too old) andI updated the code following your fix in r2880. The bug still occurs though but I have have not rerun the test. I reload the old test using the code I recompiled after the change, I remove the bodies I do not need anymore, save the test and then reload it again (but the crash occurs). Do I perhaps need to rerun the test for the change to be effected?

Also, could you explain in words your fix in the code?

Thank you.
Chiara

On 2 Jul 2011, at 18:48, Anton Gladky wrote:

> Hopefully fixed in r2880.
> Please, check it. If the problem still appears, do not hesitate to reopen a bug.
>
> ** Changed in: yade
> Status: New => Fix Released
>
> ** Changed in: yade
> Importance: Undecided => Low
>
> --
> You received this bug notification because you are a member of Yade
> developers, which is the registrant for Yade.
> https://bugs.launchpad.net/bugs/803774
>
> Title:
> Saving, loading simulation with erased bodies crash.
>
> Status in Yet Another Dynamic Engine:
> Fix Released
>
> Bug description:
> Here is the bug :
>
> - launch yade (for example without any script)
> - add a sphere : O.bodies.append(utils.sphere((0.2,0.2,0.2),0.006))
> - delete it : O.bodies.erase(0)
> - save yade's universe : O.save("./test")
> - quit yade
> - launch yade
> - load the file : O.load("./test")
> ->segmentation fault
>
> I think it's because when you erase something the size of O.bodies (etc...) doesn't change and now contains an empty value. (the c++ array may not be dynamic ?)
> So when the O.load() function is called, yade try to load a non-existant body ?
>
> Maybe this can be fixed by changing the load() method ?
>
> I joined the debug output.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/yade/+bug/803774/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Anton Gladky (gladky-anton) wrote :

Hi Chiara,

the fix is here [1]. It checks, whether the body exist before
clearing its intrs-container.

If you are still affected by this bug, please, send a short
script, reproducing the problem

Thanks
Anton

[1] https://github.com/yade/trunk/commit/ce52daf69cc7b0d804703a0877ffffec68fafae8

2012/6/15 Chiara Modenese <email address hidden>:
> Hi Anton,
>
> I am currently affected by this bug. I am using an older release (but
> not too old) andI updated the code following your fix in r2880. The bug
> still occurs though but I have have not rerun the test. I reload the old
> test using the code I recompiled after the change, I remove the bodies I
> do not need anymore, save the test and then reload it again (but the
> crash occurs). Do I perhaps need to rerun the test for the change to be
> effected?
>
> Also, could you explain in words your fix in the code?
>
> Thank you.
> Chiara
>

Revision history for this message
Chiara Modenese (chiara-modenese) wrote :

OK, I see, thank you very much. Is the body deleted then? The length of the container is still the same when I delete something, even after the fix. Before sending you the script, do you think it makes any difference if I rerun the test with the new compilation? It will take a bit of time for me if I have to rerun it.

Chiara

On 15 Jun 2012, at 10:04, Anton Gladky wrote:

> Hi Chiara,
>
> the fix is here [1]. It checks, whether the body exist before
> clearing its intrs-container.
>
> If you are still affected by this bug, please, send a short
> script, reproducing the problem
>
> Thanks
> Anton
>
> [1]
> https://github.com/yade/trunk/commit/ce52daf69cc7b0d804703a0877ffffec68fafae8
>
>
> 2012/6/15 Chiara Modenese <email address hidden>:
>> Hi Anton,
>>
>> I am currently affected by this bug. I am using an older release (but
>> not too old) andI updated the code following your fix in r2880. The bug
>> still occurs though but I have have not rerun the test. I reload the old
>> test using the code I recompiled after the change, I remove the bodies I
>> do not need anymore, save the test and then reload it again (but the
>> crash occurs). Do I perhaps need to rerun the test for the change to be
>> effected?
>>
>> Also, could you explain in words your fix in the code?
>>
>> Thank you.
>> Chiara
>>
>
> --
> You received this bug notification because you are a member of Yade
> developers, which is the registrant for Yade.
> https://bugs.launchpad.net/bugs/803774
>
> Title:
> Saving, loading simulation with erased bodies crash.
>
> Status in Yet Another Dynamic Engine:
> Fix Released
>
> Bug description:
> Here is the bug :
>
> - launch yade (for example without any script)
> - add a sphere : O.bodies.append(utils.sphere((0.2,0.2,0.2),0.006))
> - delete it : O.bodies.erase(0)
> - save yade's universe : O.save("./test")
> - quit yade
> - launch yade
> - load the file : O.load("./test")
> ->segmentation fault
>
> I think it's because when you erase something the size of O.bodies (etc...) doesn't change and now contains an empty value. (the c++ array may not be dynamic ?)
> So when the O.load() function is called, yade try to load a non-existant body ?
>
> Maybe this can be fixed by changing the load() method ?
>
> I joined the debug output.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/yade/+bug/803774/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Anton Gladky (gladky-anton) wrote :

2012/6/15 Chiara Modenese <email address hidden>:
> OK, I see, thank you very much. Is the body deleted then? The length of
> the container is still the same when I delete something, even after the
> fix.

That is right. By this way we are trying to escape memory leaks, using
for newly created bodies the "places" of previously deleted ones.

> Before sending you the script, do you think it makes any difference
> if I rerun the test with the new compilation? It will take a bit of time
> for me if I have to rerun it.

Yes.
It would be better if you minimize the script as much as possible.
The best is just 1-2 bodies.

Anton

Revision history for this message
Chiara Modenese (chiara-modenese) wrote :

There is no need to post a script. You can (I can, at least) reproduce the bug just by following instructions that were given below when the bug was open. I think it is quite essential that we fix this as removing bodies is a common operation. Can you please try to reproduce the bug too, Anton (or anybody else) to make sure is not just me? Thanks, Chiara

On 2 Jul 2011, at 18:48, Anton Gladky wrote:

> Hopefully fixed in r2880.
> Please, check it. If the problem still appears, do not hesitate to reopen a bug.
>
> ** Changed in: yade
> Status: New => Fix Released
>
> ** Changed in: yade
> Importance: Undecided => Low
>
> --
> You received this bug notification because you are a member of Yade
> developers, which is the registrant for Yade.
> https://bugs.launchpad.net/bugs/803774
>
> Title:
> Saving, loading simulation with erased bodies crash.
>
> Status in Yet Another Dynamic Engine:
> Fix Released
>
> Bug description:
> Here is the bug :
>
> - launch yade (for example without any script)
> - add a sphere : O.bodies.append(utils.sphere((0.2,0.2,0.2),0.006))
> - delete it : O.bodies.erase(0)
> - save yade's universe : O.save("./test")
> - quit yade
> - launch yade
> - load the file : O.load("./test")
> ->segmentation fault
>
> I think it's because when you erase something the size of O.bodies (etc...) doesn't change and now contains an empty value. (the c++ array may not be dynamic ?)
> So when the O.load() function is called, yade try to load a non-existant body ?
>
> Maybe this can be fixed by changing the load() method ?
>
> I joined the debug output.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/yade/+bug/803774/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Chiara Modenese (chiara-modenese) wrote :

OK, I had to do a clean scons but now it works fine so I confirm the fix was appropriate. Thanks, Anton.
Chiara

On 15 Jun 2012, at 10:37, Anton Gladky wrote:

> 2012/6/15 Chiara Modenese <email address hidden>:
>> OK, I see, thank you very much. Is the body deleted then? The length of
>> the container is still the same when I delete something, even after the
>> fix.
>
> That is right. By this way we are trying to escape memory leaks, using
> for newly created bodies the "places" of previously deleted ones.
>
>> Before sending you the script, do you think it makes any difference
>> if I rerun the test with the new compilation? It will take a bit of time
>> for me if I have to rerun it.
>
> Yes.
> It would be better if you minimize the script as much as possible.
> The best is just 1-2 bodies.
>
> Anton
>
> --
> You received this bug notification because you are a member of Yade
> developers, which is the registrant for Yade.
> https://bugs.launchpad.net/bugs/803774
>
> Title:
> Saving, loading simulation with erased bodies crash.
>
> Status in Yet Another Dynamic Engine:
> Fix Released
>
> Bug description:
> Here is the bug :
>
> - launch yade (for example without any script)
> - add a sphere : O.bodies.append(utils.sphere((0.2,0.2,0.2),0.006))
> - delete it : O.bodies.erase(0)
> - save yade's universe : O.save("./test")
> - quit yade
> - launch yade
> - load the file : O.load("./test")
> ->segmentation fault
>
> I think it's because when you erase something the size of O.bodies (etc...) doesn't change and now contains an empty value. (the c++ array may not be dynamic ?)
> So when the O.load() function is called, yade try to load a non-existant body ?
>
> Maybe this can be fixed by changing the load() method ?
>
> I joined the debug output.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/yade/+bug/803774/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Chiara Modenese (chiara-modenese) wrote :
Download full text (17.5 KiB)

Hi all,

Unfortunately I am still affected by this bug. I cannot provide a simple script but below is what I obtained in debug mode. Could you please help? Thanks very much. Chiara

yade --debug
Welcome to Yade unknown (debug build)
TCP python prompt on localhost:9001, auth cookie `ksyecu'
XMLRPC info provider on http://localhost:21001
Traceback (most recent call last):
  File "/home/chia/yade/inst/lib/yade/dbg/py/yade/remote.py", line 121, in run
    def run(self): self.func()
  File "/usr/lib/python2.6/SocketServer.py", line 224, in serve_forever
    r, w, e = select.select([self], [], [], poll_interval)
select.error: (4, 'Interrupted system call')
[[ ^L clears screen, ^U kills line. F12 controller, F11 3d view, F10 both, F9 generator, F8 plot. ]]
Yade [1]: O.load('test_removeBodies.xml.bz2')
python: /usr/include/boost/smart_ptr/shared_ptr.hpp:418: T* boost::shared_ptr< <template-parameter-1-1> >::operator->() const [with T = Body]: Assertion `px != 0' failed.
SIGSEGV/SIGABRT handler called; gdb batch file is `/tmp/yade-yk3ih0/tmp-0'
GNU gdb (GDB) 7.1-ubuntu
Copyright (C) 2010 Free Software Foundation, Inc.
License GPLv3+: GNU GPL version 3 or later <http://gnu.org/licenses/gpl.html>
This is free software: you are free to change and redistribute it.
There is NO WARRANTY, to the extent permitted by law. Type "show copying"
and "show warranty" for details.
This GDB was configured as "x86_64-linux-gnu".
For bug reporting instructions, please see:
<http://www.gnu.org/software/gdb/bugs/>.
[Thread debugging using libthread_db enabled]
[New Thread 0x7faeb4bb7700 (LWP 25248)]
0x00007faed433a2bd in __libc_waitpid (pid=25250, stat_loc=<value optimised out>, options=0) at ../sysdeps/unix/sysv/linux/waitpid.c:41
41 ../sysdeps/unix/sysv/linux/waitpid.c: No such file or directory.
 in ../sysdeps/unix/sysv/linux/waitpid.c
No symbol "info" in current context.

Thread 2 (Thread 0x7faeb4bb7700 (LWP 25248)):
#0 sem_wait () at ../nptl/sysdeps/unix/sysv/linux/x86_64/sem_wait.S:86
#1 0x00000000004d4498 in PyThread_acquire_lock ()
#2 0x00000000004a20e4 in PyEval_RestoreThread ()
#3 0x00000000004f701e in ?? ()
#4 0x00000000004a7c5e in PyEval_EvalFrameEx ()
#5 0x00000000004a9671 in PyEval_EvalCodeEx ()
#6 0x00000000004a7809 in PyEval_EvalFrameEx ()
#7 0x00000000004a9671 in PyEval_EvalCodeEx ()
#8 0x0000000000537620 in ?? ()
#9 0x000000000041f0c7 in PyObject_Call ()
#10 0x0000000000427dff in ?? ()
#11 0x000000000041f0c7 in PyObject_Call ()
#12 0x00000000004a1b03 in PyEval_CallObjectWithKeywords ()
#13 0x00007faeb53c2d3b in ?? () from /usr/lib/pymodules/python2.6/sip.so
#14 0x00007faeb566a468 in ?? () from /usr/lib/pymodules/python2.6/PyQt4/QtCore.so
#15 0x00007faeb569a630 in ?? () from /usr/lib/pymodules/python2.6/PyQt4/QtCore.so
#16 0x00007faed0802775 in ?? () from /usr/lib/libQtCore.so.4
#17 0x00007faed549c9ca in start_thread (arg=<value optimised out>) at pthread_create.c:300
#18 0x00007faed4376cdd in clone () at ../sysdeps/unix/sysv/linux/x86_64/clone.S:112
#19 0x0000000000000000 in ?? ()

Thread 1 (Thread 0x7faed58a3700 (LWP 25244)):
#0 0x00007faed433a2bd in __libc_waitpid (pid=25250, stat_loc=<value optimised out>, opt...

Revision history for this message
Bruno Chareyre (bruno-chareyre) wrote :

postLoad is trying to insert interactions with deleted body.
Did you erase just before saving?

Revision history for this message
Chiara Modenese (chiara-modenese) wrote :

On 15 Jul 2012, at 11:20, Chareyre wrote:

> postLoad is trying to insert interactions with deleted body.
> Did you erase just before saving?
Exactly! How to overcome the problem? I think that Anton's fix was/is not sufficient to solve it...
Chiara

>
> --
> You received this bug notification because you are a member of Yade
> developers, which is the registrant for Yade.
> https://bugs.launchpad.net/bugs/803774
>
> Title:
> Saving, loading simulation with erased bodies crash.
>
> Status in Yet Another Dynamic Engine:
> Fix Released
>
> Bug description:
> Here is the bug :
>
> - launch yade (for example without any script)
> - add a sphere : O.bodies.append(utils.sphere((0.2,0.2,0.2),0.006))
> - delete it : O.bodies.erase(0)
> - save yade's universe : O.save("./test")
> - quit yade
> - launch yade
> - load the file : O.load("./test")
> ->segmentation fault
>
> I think it's because when you erase something the size of O.bodies (etc...) doesn't change and now contains an empty value. (the c++ array may not be dynamic ?)
> So when the O.load() function is called, yade try to load a non-existant body ?
>
> Maybe this can be fixed by changing the load() method ?
>
> I joined the debug output.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/yade/+bug/803774/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Bruno Chareyre (bruno-chareyre) wrote :

Running one additional step without erasing may avoid the problem, but it
still needs a fix.

Revision history for this message
Chiara Modenese (chiara-modenese) wrote :

I found one solution but I think is a temporary fix. The problem is that somehow interactions are not deleted properly. Below is a modified version of postLoad__calledFromScene - I am checking whether both bodies in contact actually exist before the interaction is inserted, otherwise return - but is not the core solution to the bug so I will post it here although not commit.

Chiara

void InteractionContainer::postLoad__calledFromScene(const shared_ptr<BodyContainer>& bb){
   bodies=&bb->body; // update the internal pointer
   clear();
   FOREACH(const shared_ptr<Interaction>& I, interaction){
      Body::id_t id1=I->getId1(), id2=I->getId2();
      if (!(*bodies)[id1] || !(*bodies)[id2]) return;
      else insert(I);}
   interaction.clear();
}

On 15 Jul 2012, at 18:08, Chareyre wrote:

> Running one additional step without erasing may avoid the problem, but it
> still needs a fix.
>
> --
> You received this bug notification because you are a member of Yade
> developers, which is the registrant for Yade.
> https://bugs.launchpad.net/bugs/803774
>
> Title:
> Saving, loading simulation with erased bodies crash.
>
> Status in Yet Another Dynamic Engine:
> Fix Released
>
> Bug description:
> Here is the bug :
>
> - launch yade (for example without any script)
> - add a sphere : O.bodies.append(utils.sphere((0.2,0.2,0.2),0.006))
> - delete it : O.bodies.erase(0)
> - save yade's universe : O.save("./test")
> - quit yade
> - launch yade
> - load the file : O.load("./test")
> ->segmentation fault
>
> I think it's because when you erase something the size of O.bodies (etc...) doesn't change and now contains an empty value. (the c++ array may not be dynamic ?)
> So when the O.load() function is called, yade try to load a non-existant body ?
>
> Maybe this can be fixed by changing the load() method ?
>
> I joined the debug output.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/yade/+bug/803774/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Anton Gladky (gladky-anton) wrote :

Well, if it fixes your problem, at least prevents a crash, I am ok to
commit it. I don't see any regressions here.

Please, let me know.

Anton

2012/7/15 Chiara Modenese <email address hidden>:
> I found one solution but I think is a temporary fix. The problem is that
> somehow interactions are not deleted properly. Below is a modified
> version of postLoad__calledFromScene - I am checking whether both bodies
> in contact actually exist before the interaction is inserted, otherwise
> return - but is not the core solution to the bug so I will post it here
> although not commit.
>
> Chiara
>
> void InteractionContainer::postLoad__calledFromScene(const shared_ptr<BodyContainer>& bb){
> bodies=&bb->body; // update the internal pointer
> clear();
> FOREACH(const shared_ptr<Interaction>& I, interaction){
> Body::id_t id1=I->getId1(), id2=I->getId2();
> if (!(*bodies)[id1] || !(*bodies)[id2]) return;
> else insert(I);}
> interaction.clear();
> }
>

Revision history for this message
Bruno Chareyre (bruno-chareyre) wrote :

This fix is correct I think.
If I guess correctly (I didn't check the code), the problem is that calling
erase(i) on an interaction is not erasing immediatly. Instead it sends a
message to the collider to erase "i" at next step. If you save, the next
step never comes and junk interactions are saved.

An alternative fix would be to check bodies before saving (if b1 or b2 does
not exist, don't save). I'm not sure it would be better, but it would be
more complicated probably.

Revision history for this message
Chiara Modenese (chiara-modenese) wrote :

On 16 Jul 2012, at 02:00, Chareyre wrote:

> This fix is correct I think.
> If I guess correctly (I didn't check the code), the problem is that calling
> erase(i) on an interaction is not erasing immediatly. Instead it sends a
> message to the collider to erase "i" at next step. If you save, the next
> step never comes and junk interactions are saved.
Good point.

>
> An alternative fix would be to check bodies before saving (if b1 or b2 does
> not exist, don't save). I'm not sure it would be better, but it would be
> more complicated probably.
The problem is with contacts (and ultimately with bodies) so I think it is easier to fix it as I did. I think a better solution would be to modify erase() but I do not have further time to investigate/test. If you agree for the moment, Anton can you commit the fix please?

Chiara

>
> --
> You received this bug notification because you are a member of Yade
> developers, which is the registrant for Yade.
> https://bugs.launchpad.net/bugs/803774
>
> Title:
> Saving, loading simulation with erased bodies crash.
>
> Status in Yet Another Dynamic Engine:
> Fix Released
>
> Bug description:
> Here is the bug :
>
> - launch yade (for example without any script)
> - add a sphere : O.bodies.append(utils.sphere((0.2,0.2,0.2),0.006))
> - delete it : O.bodies.erase(0)
> - save yade's universe : O.save("./test")
> - quit yade
> - launch yade
> - load the file : O.load("./test")
> ->segmentation fault
>
> I think it's because when you erase something the size of O.bodies (etc...) doesn't change and now contains an empty value. (the c++ array may not be dynamic ?)
> So when the O.load() function is called, yade try to load a non-existant body ?
>
> Maybe this can be fixed by changing the load() method ?
>
> I joined the debug output.
>
> To manage notifications about this bug go to:
> https://bugs.launchpad.net/yade/+bug/803774/+subscriptions
>
> _______________________________________________
> Mailing list: https://launchpad.net/~yade-dev
> Post to : <email address hidden>
> Unsubscribe : https://launchpad.net/~yade-dev
> More help : https://help.launchpad.net/ListHelp

Revision history for this message
Anton Gladky (gladky-anton) wrote :

Ok, one more fix is in f22afe466ee5 commit.

Thanks. Chiara for pointing this out and providing a fix.

Anton

To post a comment you must log in.
This report contains Public information  
Everyone can see this information.

Other bug subscribers

Remote bug watches

Bug watches keep track of this bug in other bug trackers.