PxHeightField problem

Hi,
I’ve got some problems with PxHeightField. Objects behave unnaturally during contact with heightfield. The collision with heightfield results in object flying away at high velocity. The same simulation is stable when PxPlane is used.
I tried to tune various parameters but without visible results. I use PhysX 3.3.4 compiled on Ubuntu 16.04.
I prepared compressed version of the application:

main.cpp:

#include <iostream>
#include <PxPhysicsAPI.h>
#include <PxPhysics.h>

using namespace std;
using namespace physx;

///PhysX World
PxDefaultAllocator      gAllocator;
PxDefaultErrorCallback	gErrorCallback;
PxFoundation*           gFoundation = NULL;
PxPhysics*				gPhysics	= NULL;
PxDefaultCpuDispatcher*	gDispatcher = NULL;
PxScene*				gScene		= NULL;
PxMaterial*				gMaterial	= NULL;
PxVisualDebuggerConnection*
                        gConnection	= NULL;
PxRigidStatic* hf;


class UserErrorCallback : public PxErrorCallback
{
    public:
        void reportError(PxErrorCode::Enum code, const char* message, const char* file, int line) {
            std::cout<<"PhysX Error | Code: "<< code <<" "<< message <<" | "<< file << " (" << line << ")"<<std::endl;
        }
};
UserErrorCallback userErrorCallback;

int main() {
    /// Create world
    gFoundation = PxCreateFoundation(PX_PHYSICS_VERSION, gAllocator, userErrorCallback);
    PxProfileZoneManager* profileZoneManager = &PxProfileZoneManager::createProfileZoneManager(gFoundation);
    gPhysics = PxCreatePhysics(PX_PHYSICS_VERSION, *gFoundation, PxTolerancesScale(),true,profileZoneManager);

    PxSceneDesc sceneDesc(gPhysics->getTolerancesScale());
    sceneDesc.gravity = PxVec3(0.0f, 0.0f, -9.81f);
    gDispatcher = PxDefaultCpuDispatcherCreate(2);
    sceneDesc.cpuDispatcher	= gDispatcher;
    sceneDesc.filterShader	= PxDefaultSimulationFilterShader;
    gScene = gPhysics->createScene(sceneDesc);

    gScene->setVisualizationParameter(PxVisualizationParameter::eSCALE, 1.0);
    gScene->setVisualizationParameter(PxVisualizationParameter::eJOINT_LOCAL_FRAMES, 1.0);

    /// create box
    PxTransform t = PxTransform(physx::PxVec3(0,0,0.7f), physx::PxQuat(0,0,0,1.0f));
    gMaterial = gPhysics->createMaterial(0.5, 0.5, 0.5);
    float side = 0.4f;
    float mass = 2.5f;
    PxShape* shape = gPhysics->createShape(PxBoxGeometry(physx::PxVec3(side, side, side)/2.0), *gMaterial);
    shape->setContactOffset(0.002f);
    PxRigidDynamic* body = gPhysics->createRigidDynamic(t);
    body->setGlobalPose(t);
    body->attachShape(*shape);
    float volume = side*side*side;
    PxRigidBodyExt::updateMassAndInertia(*body, (float)mass/volume);

    body->setActorFlag(PxActorFlag::eVISUALIZATION,false);
    gScene->addActor(*body);
    shape->release();

    ///ground plane - works well
    PxRigidStatic* groundPlane = PxCreatePlane(*gPhysics, PxPlane(0,0,1,0), *gMaterial);
    groundPlane->setActorFlag(PxActorFlag::eVISUALIZATION, false);
    gScene->addActor(*groundPlane);

    ///heightfield - doesn't work properly - the box bounces
    /*
    PxHeightFieldDesc heightfieldDesc;
    heightfieldDesc.nbColumns = 100;
    heightfieldDesc.nbRows = 100;

    PxHeightFieldSample* samplesData = (PxHeightFieldSample*)malloc(sizeof(PxHeightFieldSample)*(heightfieldDesc.nbColumns*heightfieldDesc.nbRows));
    int sampleCount=0;
    for (size_t i = 0; i < heightfieldDesc.nbColumns;++i) {
        for (size_t j = 0; j < heightfieldDesc.nbRows; ++j) {
            samplesData[sampleCount].height = (PxI16)0;
            sampleCount++;
        }
    }

    heightfieldDesc.samples.data = samplesData;
    heightfieldDesc.samples.stride = sizeof(PxHeightFieldSample);

    PxHeightField* aHeightField = gPhysics->createHeightField(heightfieldDesc);
    PxReal zScale = 1;
    PxReal xScale = 0.015f;
    PxReal yScale = 0.015f;
    PxHeightFieldGeometry hfGeom(aHeightField, PxMeshGeometryFlags(), zScale /  (float)pow(10,1), xScale, yScale);

    PxTransform pose(PxVec3(-((PxReal)(heightfieldDesc.nbColumns) * xScale) / 2.0f, ((PxReal)(heightfieldDesc.nbRows) * yScale) / 2.0f, (float)0.0), PxQuat(0.707107f,0,0,0.707107f));
    PxRigidStatic* hf = gPhysics->createRigidStatic(pose);
    PxShape* shapeHf = gPhysics->createShape(hfGeom, *gMaterial);
    shapeHf->setFlag(PxShapeFlag::ePARTICLE_DRAIN, false);
    shapeHf->setFlag(PxShapeFlag::eSIMULATION_SHAPE, true);
    hf->attachShape(*shapeHf);
    hf->setActorFlag(PxActorFlag::eVISUALIZATION, false);
    gScene->addActor(*hf);
    */

    /// simulate the world
    int framerate = 20000;
    gScene->setGravity(PxVec3(0.0f, 0.0f, (float)(-9.81)));
    PxTransform prevPos(physx::PxVec3(0,0,0.71f), physx::PxQuat(0,0,0,1));
    PxTransform pos(physx::PxVec3(0,0,0.7f), physx::PxQuat(0,0,0,1));
    std::cout << "object position:\n";
    while (!((pos.p.z<0.21)&&(prevPos.p.z == pos.p.z))){
        prevPos = pos;
        gScene->simulate((float)(1.0/framerate));
        gScene->fetchResults(true);

        pos = body->getGlobalPose();

        std::cout << "Object position " << pos.p.x << ", " << pos.p.y << ", " << pos.p.z << "\n";
    }
    std::cout << "Object is stable on the ground\n";
    return 0;
}

CMakeLists.txt:

# cmake requirements
cmake_minimum_required(VERSION 2.8)

# Build options have to be before PROJECT(...)
SET(CMAKE_CONFIGURATION_TYPES "Release" CACHE PATH "Configuration types")
SET(CMAKE_BUILD_TYPE "Release" CACHE PATH "Current build configuration")

# Example Project configuration
PROJECT(PhysXplayground)
SET(CMAKE_CXX_FLAGS "-Wall -Wextra -Wconversion -std=c++11 -pthread")
#add_definitions(-DDEBUG)

# Folders
SET_PROPERTY(GLOBAL PROPERTY USE_FOLDERS ON)

# Settings
INCLUDE_DIRECTORIES("${CMAKE_SOURCE_DIR}")

set(CMAKE_MODULE_PATH ${PROJECT_SOURCE_DIR}/cmake_modules)
FIND_PACKAGE(OpenGL)
include_directories(${OPENGL_INCLUDE_DIR})
link_directories(${OPENGL_LIBRARY})

# Architecture
if(CMAKE_SIZEOF_VOID_P EQUAL 8)
        SET(X86_64 1)
        #MESSAGE("Architecture x86 64 bit")
else(CMAKE_SIZEOF_VOID_P EQUAL 8)
        SET(X86_64 0)
        #MESSAGE("Architecture x86 32 bit")
endif(CMAKE_SIZEOF_VOID_P EQUAL 8)
    
set(PHYSX_INCLUDE /usr/local/include/PhysX-3.3/Include CACHE PATH "Path prefix for PhysX include")
set(PHYSX_LIBRARY /usr/local/lib/PhysX-3.3 CACHE PATH "Path prefix for PhysX library")

include_directories(SYSTEM ${PHYSX_INCLUDE})
if(X86_64)
     link_directories(${PHYSX_LIBRARY}/Lib/linux64
                    ${PHYSX_LIBRARY}/Bin/linux64)
     add_definitions(-DLINUX=1 -DNX64=1 -DNDEBUG=1)
else(X86_64)
     link_directories(${PHYSX_LIBRARY}/Lib/linux32
                    ${PHYSX_LIBRARY}/Bin/linux32)
     add_definitions(-DLINUX=1 -DNX32=1 -DNDEBUG=1)
endif(X86_64)
        
# Executable output directory
SET(RUNTIME_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/bin${OUTPUT_DIRECTORY_POSTFIX} CACHE PATH "Executable output directory")
mark_as_advanced(RUNTIME_OUTPUT_DIRECTORY)

# Dynamic library output directory
SET(LIBRARY_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/bin${OUTPUT_DIRECTORY_POSTFIX} CACHE PATH "Dynamic library output directory")
mark_as_advanced(LIBRARY_OUTPUT_DIRECTORY)

# Static library output directory
SET(ARCHIVE_OUTPUT_DIRECTORY ${CMAKE_CURRENT_SOURCE_DIR}/build/lib${OUTPUT_DIRECTORY_POSTFIX} CACHE PATH "Static library output directory")
mark_as_advanced(ARCHIVE_OUTPUT_DIRECTORY)

SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY ${RUNTIME_OUTPUT_DIRECTORY})
SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY ${LIBRARY_OUTPUT_DIRECTORY})
SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY ${ARCHIVE_OUTPUT_DIRECTORY})
foreach(CONFIGURATION_TYPE ${CMAKE_CONFIGURATION_TYPES})
	string(TOUPPER ${CONFIGURATION_TYPE} CONFIGURATION_TYPE)
	SET(CMAKE_RUNTIME_OUTPUT_DIRECTORY_${CONFIGURATION_TYPE} ${RUNTIME_OUTPUT_DIRECTORY})
	SET(CMAKE_LIBRARY_OUTPUT_DIRECTORY_${CONFIGURATION_TYPE} ${LIBRARY_OUTPUT_DIRECTORY})
	SET(CMAKE_ARCHIVE_OUTPUT_DIRECTORY_${CONFIGURATION_TYPE} ${ARCHIVE_OUTPUT_DIRECTORY})
endforeach(CONFIGURATION_TYPE CMAKE_CONFIGURATION_TYPES)

SET(CMAKE_EXE_LINKER_FLAGS "${CMAKE_EXE_LINKER_FLAGS} -Wl,-rpath ./")
SET(DEMO_SOURCES ./main.cpp)
ADD_EXECUTABLE(simulator ${DEMO_SOURCES})
TARGET_LINK_LIBRARIES(simulator PhysX3DEBUG_x64 PhysX3CommonDEBUG_x64 PhysX3ExtensionsDEBUG PhysXProfileSDKDEBUG PhysXVisualDebuggerSDKDEBUG ${OPENGL_LIBRARY} glut)
INSTALL(TARGETS simulator RUNTIME DESTINATION bin)

The program works well when groundPlane is used. Problems are related to commented heightfield section (groundPlane section should be commented and heightfield section uncommented).
Where should I search for possible errors?
Thanks!

Hi,
simulation becomes stable when framerate is set to 200. It is intuitive for me. I expected more accurate and stable but slower simulation when the value (elapsedTime) passed to PxScene::simulate is smaller.