raisimTech / raisimOgre

Other
25 stars 20 forks source link

Black screen in renderer after brief flash #13

Closed RobertoRoos closed 3 years ago

RobertoRoos commented 3 years ago

I was making a new URDF model and started debugging it with a simple application. However, the renderer just shows a black screen with my model. Though it seems to flash a single regular frame.

The command line shows no errors. I tried stepping through the code, that also provided no extra information.

The URDF model:

<?xml version="1.0"?>

<!-- Single tetrahedron (three-point pyramid), with four end-effectors on all corners -->

<robot name="tetrahedron">

    <!-- Basic colors -->
    <material name="gray">
        <color rgba="0.2 0.2 0.2 1.0"/>
    </material>

    <link name="base_link">
        <inertial>
            <origin rpy="0 0 0" xyz="0 0 0"/>
            <mass value="1.0"/>
            <!-- Inertia of a sphere -->
            <inertia ixx="0.4" ixy="0.0" ixz="0.0" iyy="0.4" iyz="0.0" izz="0.4"/>
        </inertial>
        <visual>
            <origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
            <geometry>
                <sphere radius="0.5"/>
            </geometry>
            <material name="gray"/>
        </visual>
        <collision>
            <origin rpy="0 0 0" xyz="0.0 0.0 0.0"/>
            <geometry>
                <sphere radius="0.5"/>
            </geometry>
        </collision>
    </link>

    <!-- Corner 1 -->

    <joint name="corner1_joint" type="fixed">
        <parent link="bae_link"/>
        <child link="corner1_link"/>
        <origin rpy="0 0 0" xyz="0 0 0"/>
    </joint>

    <link name="corner1_link">
        <visual>
            <origin rpy="0.0 0.0 0.0" xyz="0.0 0.0 0.0"/>
            <geometry>
                <sphere radius="0.1"/>
            </geometry>
            <material name="gray"/>
        </visual>
        <collision>
            <origin rpy="0 0 0" xyz="0.0 0.0 0.0"/>
            <geometry>
                <sphere radius="0.1"/>
            </geometry>
        </collision>
    </link>

</robot>

And the application with which I run the model (nearly identical to one of the provided examples):

/**
 * This is a basic application that simulates a URDF file passed from the command line.
 */

#include <iostream>
#include <string>
#include <raisim/OgreVis.hpp>
#include "raisimBasicImguiPanel.hpp"
#include "raisimKeyboardCallback.hpp"
#include "helper.hpp"

void setupCallback() {
    auto vis = raisim::OgreVis::get();

    /// light
    vis->getLight()->setDiffuseColour(1, 1, 1);
    vis->getLight()->setCastShadows(true);
    vis->getLightNode()->setPosition(3, 3, 3);

    /// load  textures
    vis->addResourceDirectory(vis->getResourceDir() + "/material/gravel");
    vis->loadMaterialFile("gravel.material");

    vis->addResourceDirectory(vis->getResourceDir() + "/material/checkerboard");
    vis->loadMaterialFile("checkerboard.material");

    /// shadow setting
    vis->getSceneManager()->setShadowTechnique(Ogre::SHADOWTYPE_TEXTURE_ADDITIVE);
    vis->getSceneManager()->setShadowTextureSettings(2048, 3);

    /// scale related settings!! Please adapt it depending on your map size
    // beyond this distance, shadow disappears
    vis->getSceneManager()->setShadowFarDistance(60);
    // size of contact points and contact forces
    vis->setContactVisObjectSize(0.1, 3.0);
    // speed of camera motion in freelook mode
    vis->getCameraMan()->setTopSpeed(10);

    /// background
    Ogre::Quaternion quat;
    quat.FromAngleAxis(Ogre::Radian(M_PI_2), {1., 0, 0});
    vis->getSceneManager()->setSkyBox(true,
                                      "white",
                                      500,
                                      true,
                                      quat,
                                      Ogre::ResourceGroupManager::AUTODETECT_RESOURCE_GROUP_NAME);
}

int main(int argc, char **argv) {
    //auto binaryPath = raisim::Path::setFromArgv(argv[0]);
    //raisim::World::setActivationKey(binaryPath.getDirectory() + "/rsc/activation.raisim");

    /// get target file from command line
    if (argc < 2) {
        std::cerr << "Please provide the path to a URDF file in the command line" << std::endl;
        return 1;
    }
    std::string filepath = argv[1];

    /// create raisim world
    raisim::World world;
    world.setTimeStep(0.003);
    world.setGravity({0.0, 0.0, -9.81});

    /// these method must be called before initApp
    auto vis = raisim::OgreVis::get();
    vis->setWorld(&world);
    vis->setWindowSize(1024, 768);
    vis->setImguiSetupCallback(imguiSetupCallback);
    vis->setImguiRenderCallback(imguiRenderCallBack);
    vis->setSetUpCallback(setupCallback);
    vis->setKeyboardCallback(raisimKeyboardCallback);
    //vis->setAntiAliasing(2);

    /// init
    vis->initApp();

    /// create raisim objects
    auto ground = world.addGround(-2.0);
    vis->createGraphicalObject(ground, 20, "floor", "checkerboard_green");

    /// make robot
    auto robot = world.addArticulatedSystem(filepath);
    auto robot_visual = vis->createGraphicalObject(robot, robot->getName());

    /// info
    std::cout << "Robot: " << robot->getName() << std::endl;
    std::cout << "DOF: " << robot->getDOF() << std::endl;
    std::cout << "n(q): " << robot->getGeneralizedCoordinateDim() << std::endl;

    /// set camera
    vis->getCameraMan()->getCamera()->setPosition(0, 2.0, 1.0);
    vis->getCameraMan()->getCamera()->pitch(Ogre::Radian(1.2));
    vis->select(robot_visual->at(0));
    vis->getCameraMan()->setYawPitchDist(Ogre::Radian(0.), Ogre::Radian(-1.5), 5);

    /// run the app
    vis->run();

    /// terminate
    vis->closeApp();

    return 0;
}
RobertoRoos commented 3 years ago

Alright, problem was in the joint definition:

    <joint name="corner1_joint" type="fixed">
        <parent link="bae_link"/>

I made a typo in the parent link name.

Regardless, raisimLib or raisimOgre should probably handle it differently than simply a black screen.

jhwangbo commented 3 years ago

I pushed a fix to raisimLib. Now it should display an error message

RobertoRoos commented 3 years ago

I pulled and rebuild raisimLib and raisimOgre, but now my program instantly crashes with a "SIGILL (Illegal instruction)". (For both valid and invalid URDF files.)

Could something have gone wrong?

jhwangbo commented 3 years ago

are you testing it on Linux?

jhwangbo commented 3 years ago

that might be due to a discrepancy between the linked library and one used for compilation. Can you do a clean build?

RobertoRoos commented 3 years ago

Yeah, I'm testing on Linux. I've done a clean build on both libraries and my application, with no changes.

jhwangbo commented 3 years ago

can you identify which line is causing the error?

RobertoRoos commented 3 years ago

Not really. The error happens before the first line the debugger can catch.

It also happens with an empty program:

#include <iostream>
#include <string>
#include <raisim/OgreVis.hpp>
#include "raisimBasicImguiPanel.hpp"
#include "raisimKeyboardCallback.hpp"
#include "helper.hpp"

int main() {
    return 0;
}

When I comment out the line #include "raisimBasicImguiPanel.hpp" the program does run. I copied those *.hpp headers again from the raisimOgre examples. I'm not sure if they've been changed.

EDIT: I also cannot run the 'primitives' example from raisimOgre. Should have tried that before. EDIT 2: Same error with raisimLib examples.

jhwangbo commented 3 years ago

can you ldd the executable and see what raisim it is linking against?

RobertoRoos commented 3 years ago

ldd ./anymal output:

robert@kubuntu:~/Libraries/raisimOgre/examples/build$ ldd anymal
        linux-vdso.so.1 (0x00007ffc41f84000)
        libraisimOgre.so => /home/robert/Libraries/local/lib/libraisimOgre.so (0x00007fd9a26b3000)
        libOgreBites.so.1.12.2 => /home/robert/Libraries/local/lib/libOgreBites.so.1.12.2 (0x00007fd9a266b000)
        libOgreMain.so.1.12.2 => /home/robert/Libraries/local/lib/libOgreMain.so.1.12.2 (0x00007fd9a2161000)
        libraisim.so => /home/robert/Libraries/local/lib/libraisim.so (0x00007fd9a1ec6000)
        libstdc++.so.6 => /lib/x86_64-linux-gnu/libstdc++.so.6 (0x00007fd9a1ccd000)
        libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007fd9a1b7e000)
        libgcc_s.so.1 => /lib/x86_64-linux-gnu/libgcc_s.so.1 (0x00007fd9a1b61000)
        libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007fd9a196f000)
        libOgreRTShaderSystem.so.1.12.2 => /home/robert/Libraries/local/lib/libOgreRTShaderSystem.so.1.12.2 (0x00007fd9a1850000)
        libassimp.so.4 => /home/robert/Libraries/local/lib/libassimp.so.4 (0x00007fd9a0fef000)
        libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007fd9a0fcc000)
        libOgreOverlay.so.1.12.2 => /home/robert/Libraries/local/lib/libOgreOverlay.so.1.12.2 (0x00007fd9a0f59000)
        libX11.so.6 => /lib/x86_64-linux-gnu/libX11.so.6 (0x00007fd9a0e1a000)
        libXt.so.6 => /lib/x86_64-linux-gnu/libXt.so.6 (0x00007fd9a0bb1000)
        libXaw.so.7 => /lib/x86_64-linux-gnu/libXaw.so.7 (0x00007fd9a093d000)
        libSDL2-2.0.so.0 => /lib/x86_64-linux-gnu/libSDL2-2.0.so.0 (0x00007fd9a07e8000)
        libzzip-0.so.13 => /lib/x86_64-linux-gnu/libzzip-0.so.13 (0x00007fd9a07df000)
        libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007fd9a07c3000)
        libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007fd9a07bb000)
        libraisimPng.so => /home/robert/Libraries/local/lib/libraisimPng.so (0x00007fd9a0579000)
        libraisimODE.so => /home/robert/Libraries/local/lib/libraisimODE.so (0x00007fd9a0279000)
        libraisimMine.so => /home/robert/Libraries/local/lib/libraisimMine.so (0x00007fd9a0065000)
        /lib64/ld-linux-x86-64.so.2 (0x00007fd9a27c7000)
        libfreetype.so.6 => /lib/x86_64-linux-gnu/libfreetype.so.6 (0x00007fd99ffa6000)
        libxcb.so.1 => /lib/x86_64-linux-gnu/libxcb.so.1 (0x00007fd99ff7a000)
        libSM.so.6 => /lib/x86_64-linux-gnu/libSM.so.6 (0x00007fd99ff6f000)
        libICE.so.6 => /lib/x86_64-linux-gnu/libICE.so.6 (0x00007fd99ff51000)
        libXext.so.6 => /lib/x86_64-linux-gnu/libXext.so.6 (0x00007fd99ff3c000)
        libXmu.so.6 => /lib/x86_64-linux-gnu/libXmu.so.6 (0x00007fd99ff20000)
        libXpm.so.4 => /lib/x86_64-linux-gnu/libXpm.so.4 (0x00007fd99fd0e000)
        libasound.so.2 => /lib/x86_64-linux-gnu/libasound.so.2 (0x00007fd99fc11000)
        libpulse.so.0 => /lib/x86_64-linux-gnu/libpulse.so.0 (0x00007fd99fbbc000)
        libXcursor.so.1 => /lib/x86_64-linux-gnu/libXcursor.so.1 (0x00007fd99fbaf000)
        libXinerama.so.1 => /lib/x86_64-linux-gnu/libXinerama.so.1 (0x00007fd99fbaa000)
        libXi.so.6 => /lib/x86_64-linux-gnu/libXi.so.6 (0x00007fd99fb98000)
        libXrandr.so.2 => /lib/x86_64-linux-gnu/libXrandr.so.2 (0x00007fd99fb8b000)
        libXss.so.1 => /lib/x86_64-linux-gnu/libXss.so.1 (0x00007fd99fb84000)
        libXxf86vm.so.1 => /lib/x86_64-linux-gnu/libXxf86vm.so.1 (0x00007fd99fb7d000)
        libwayland-egl.so.1 => /lib/x86_64-linux-gnu/libwayland-egl.so.1 (0x00007fd99fb78000)
        libwayland-client.so.0 => /lib/x86_64-linux-gnu/libwayland-client.so.0 (0x00007fd99fb67000)
        libwayland-cursor.so.0 => /lib/x86_64-linux-gnu/libwayland-cursor.so.0 (0x00007fd99fb5c000)
        libxkbcommon.so.0 => /lib/x86_64-linux-gnu/libxkbcommon.so.0 (0x00007fd99fb1a000)
        libraisimZ.so => /home/robert/Libraries/local/lib/libraisimZ.so (0x00007fd99f8ff000)
        libpng16.so.16 => /lib/x86_64-linux-gnu/libpng16.so.16 (0x00007fd99f8c7000)
        libXau.so.6 => /lib/x86_64-linux-gnu/libXau.so.6 (0x00007fd99f8c1000)
        libXdmcp.so.6 => /lib/x86_64-linux-gnu/libXdmcp.so.6 (0x00007fd99f8b9000)
        libuuid.so.1 => /lib/x86_64-linux-gnu/libuuid.so.1 (0x00007fd99f8b0000)
        libbsd.so.0 => /lib/x86_64-linux-gnu/libbsd.so.0 (0x00007fd99f894000)
        libpulsecommon-13.99.so => /usr/lib/x86_64-linux-gnu/pulseaudio/libpulsecommon-13.99.so (0x00007fd99f812000)
        libdbus-1.so.3 => /lib/x86_64-linux-gnu/libdbus-1.so.3 (0x00007fd99f7c1000)
        libXrender.so.1 => /lib/x86_64-linux-gnu/libXrender.so.1 (0x00007fd99f5b7000)
        libXfixes.so.3 => /lib/x86_64-linux-gnu/libXfixes.so.3 (0x00007fd99f5af000)
        libffi.so.7 => /lib/x86_64-linux-gnu/libffi.so.7 (0x00007fd99f5a1000)
        libsystemd.so.0 => /lib/x86_64-linux-gnu/libsystemd.so.0 (0x00007fd99f4f2000)
        libwrap.so.0 => /lib/x86_64-linux-gnu/libwrap.so.0 (0x00007fd99f4e6000)
        libsndfile.so.1 => /lib/x86_64-linux-gnu/libsndfile.so.1 (0x00007fd99f469000)
        libasyncns.so.0 => /lib/x86_64-linux-gnu/libasyncns.so.0 (0x00007fd99f263000)
        libapparmor.so.1 => /lib/x86_64-linux-gnu/libapparmor.so.1 (0x00007fd99f24c000)
        librt.so.1 => /lib/x86_64-linux-gnu/librt.so.1 (0x00007fd99f241000)
        liblzma.so.5 => /lib/x86_64-linux-gnu/liblzma.so.5 (0x00007fd99f218000)
        liblz4.so.1 => /lib/x86_64-linux-gnu/liblz4.so.1 (0x00007fd99f1f7000)
        libgcrypt.so.20 => /lib/x86_64-linux-gnu/libgcrypt.so.20 (0x00007fd99f0d9000)
        libnsl.so.1 => /lib/x86_64-linux-gnu/libnsl.so.1 (0x00007fd99f0ba000)
        libFLAC.so.8 => /lib/x86_64-linux-gnu/libFLAC.so.8 (0x00007fd99f07c000)
        libogg.so.0 => /lib/x86_64-linux-gnu/libogg.so.0 (0x00007fd99f06f000)
        libvorbis.so.0 => /lib/x86_64-linux-gnu/libvorbis.so.0 (0x00007fd99f041000)
        libvorbisenc.so.2 => /lib/x86_64-linux-gnu/libvorbisenc.so.2 (0x00007fd99ef96000)
        libresolv.so.2 => /lib/x86_64-linux-gnu/libresolv.so.2 (0x00007fd99ef7a000)
        libgpg-error.so.0 => /lib/x86_64-linux-gnu/libgpg-error.so.0 (0x00007fd99ef55000
jhwangbo commented 3 years ago

is libraisim.so in /home/robert/Libraries/local/lib latest? I can run all raisimOgre and raisimLib examples. All unit tests are passing in Azure pipeliens.

RobertoRoos commented 3 years ago

Odd.

I can reproduce my problem with Docker. The Dockerfile:

FROM utwentebe/gcc-ogre:latest

# Get packages
RUN apt update -qqq && \
    apt install -y libeigen3-dev

# Clone and install RaiSim
RUN git clone https://github.com/raisimTech/raisimLib.git && \
    cd raisimLib && \
    mkdir build && \
    cd build && \
    cmake .. && \
    make install

(Or an alternative Dockerfile that does not depend on my custom base container:)

FROM ubuntu:20.04

ENV DEBIAN_FRONTEND=noninteractive

# Get packages
RUN apt update -qqq && \
    apt install -y build-essential git cmake libeigen3-dev

# Clone and install RaiSim
RUN git clone https://github.com/raisimTech/raisimLib.git && \
    cd raisimLib && \
    mkdir build && \
    cd build && \
    cmake .. && \
    make install

And running it with:

$ sudo docker build -t raisim .
$ sudo docker run -it --rm --entrypoint="/bin/bash" raisim
# cd /raisimLib/build/examples
# ./anymals
jhwangbo commented 3 years ago

I reverted the last change. Can you pull and try again?

jhwangbo commented 3 years ago

I figured out the issue. I compiled with my laptop but the compilation architecture was set to "native". It contains a few instructions that are not available on your PC.

jhwangbo commented 3 years ago

I also pushed the new changes to feature/haswell after recompiling it with march=haswell. Can you test it? Im on holidays now and I only have a laptop with me

RobertoRoos commented 3 years ago

It's working again! Thank you for your help.