These visuals had empty destructors which weren't cleaning up everything properly. I removed them, so the Visual base class destructor is used instead and your test passes. I also removed your unique name changes. See commit 3ceaa8b, feel free to merge if you think it's ok.
One thing I noticed though was that the test fails for Simbody right on the first ServerFixture::SpawnModel, so I left simbody out for now...
nice! thanks Louise. merged.
I will take a look at the simbody failure and see why it's failing.
hm... I have not been able to reproduce failure with simbody. What kind of error did you actually see?
Actually I just tried running gazebo with simbody and it crashes whenever I insert a box, so the problem is not with the test per se. It could be my installation... I'm ok with doing this test for simbody and investigating my failure separately.
Running the test several times, it always fails on the first SpawnModel. Most times with this message:
note the failure mode is exception thrown by server->Run(), so not a typical gtest failure.
So the test fails in default and in branch issue_1702, (but not in issue_1702_john with a hack). I am going to look some more at @chapulina 's solution and see if we can get issue_1702 branch to pass the test.
[==========] Running 1 test from 1 test case.
[----------] Global test environment set-up.
[----------] 1 test from PhysicsEngines/Issue1702Test
[ RUN ] PhysicsEngines/Issue1702Test.SpawnDeleteSpawnAgain/0
[Msg] Waiting for master.
[Msg] Connected to gazebo master @ http://127.0.0.1:11345
[Msg] Publicized address: 192.168.11.15
[Dbg] [ServerFixture.cc:169] ServerFixture load in 1.1 seconds, timeout after 600 seconds
Expected: this->server->Run() doesn't throw an exception.
Actual: it throws.
[Dbg] [ServerFixture.cc:118] ServerFixture::Unload
[ FAILED ] PhysicsEngines/Issue1702Test.SpawnDeleteSpawnAgain/0, where GetParam() = "ode" (2063 ms)
[----------] 1 test from PhysicsEngines/Issue1702Test (2063 ms total)
[----------] Global test environment tear-down
[==========] 1 test from 1 test case ran. (2063 ms total)
[ PASSED ] 0 tests.
[ FAILED ] 1 test, listed below:
[ FAILED ] PhysicsEngines/Issue1702Test.SpawnDeleteSpawnAgain/0, where GetParam() = "ode"
1 FAILED TEST
terminate called after throwing an instance of 'boost::exception_detail::clone_impl<boost::exception_detail::error_info_injector<boost::lock_error> >'
what(): boost: mutex lock failed in pthread_mutex_lock: Invalid argument
Aborted (core dumped)
Note that the test passes with my hack in issue_1702_john branch.
I can confirm the test fails as of 331e9f3 without the fix.
are you going to merge with that branch? this branch is currently failing the test
I am debugging the proper ogre scene node removal. My workaround is not a real fix, it will leave behind things in memory.
Should we close this pull request until it is ready?
If by late tonight a proper solution isn't found, I'll update the PR to my hack so at least gazebo doesn't segfault.
I've looked at it and confirmed that it works with your hack. Very strange... I was trying to figure out why the COM and Inertia visuals behave differently from say the LinkFrame visual... LinkFrame was implemented later, so it might have some extra detail we're missing.
test passes now, except for DART, documented issue #1723.
test/regression/1702_remove_model_scene_nodes.cc:79: Missing space before ( in while( [whitespace/parens] 
test/regression/1702_remove_model_scene_nodes.cc:85: Consider using EXPECT_LT instead of EXPECT_TRUE(a < b) [readability/check] 
test/regression/1702_remove_model_scene_nodes.cc:93: Missing space before ( in while( [whitespace/parens] 
Total errors found: 3
I made some changes to clean up the ogre scene nodes and entities in a visual in issue_1702_ian branch. Test passes. The fix should also be backwards compatible.
issue_1702_nate branch merged into this pull request (2dce80c)
Some of the changes to the regression test (timing tweaks) looks like they could be merged into pull request #1886
gazebo/rendering/COMVisual.hh:64: Lines should be <= 80 characters long [whitespace/line_length] 
gazebo/rendering/Visual.cc:172: Blank line at the start of a code block. Is this needed? [whitespace/blank_line] 
Another way to reproduce the original issue is to:
Insert a box
Copy the box and paste it
Delete the copy
Paste again - crash, because it would have the same name as the deleted one
On this branch, sometimes (most times?) the procedure above works. But at times:
The second pasted box disappears after a while from the 3D scene, but the name remains on the list. Clicking on the name makes it disappear. No crash, no error msgs.
I've also had a crash once but can't reproduce it anymore and have no backtrace.