Abort() error encountered when adding points from input PointCloud to OctreePointCloud in PCL - c++

I've encountered an error I'm having some difficulty solving in my current PCL c++ program. My original code is much larger and part of a classification project so I have tested using the following code and am still encountering my issue. When calling addPointsFromInputCloud() from my octree the function is running once for the first point, then appears to be unable to read the memory in which the defined input cloud is located. It throws the following error: R6010 - abort() has been called. I'm using PCL 1.8 with Visual Studio 2012. I have had PCL up and running in this project but started to have this issue yesterday after changing some binary reading code in an unrelated part of the project. In my header file I include:
#include <pcl\point_types.h>
#include <pcl\point_cloud.h>
#include <pcl\octree\octree.h>
In my function in the corresponding class I attempt to implement the code from the basic PCL octree tutorial (http://www.pointclouds.org/documentation/tutorials/octree.php):
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud (new pcl::PointCloud<pcl::PointXYZ>);
// Generate pointcloud data
cloud->width = 1000;
cloud->height = 1;
cloud->points.resize (cloud->width * cloud->height);
for (size_t i = 0; i < cloud->points.size (); ++i) {
cloud->points[i].x = 1024.0f * rand () / (RAND_MAX + 1.0f);
cloud->points[i].y = 1024.0f * rand () / (RAND_MAX + 1.0f);
cloud->points[i].z = 1024.0f * rand () / (RAND_MAX + 1.0f);
}
float resolution = 128.0f;
pcl::octree::OctreePointCloudSearch<pcl::PointXYZ> octree (resolution);
octree.setInputCloud(cloud);
octree.addPointsFromInputCloud();
This throws the error above when attempting to execute the final line.
This is the code from octree_poointcloud.hpp wherein the failure occurs:
//////////////////////////////////////////////////////////////////////////////////////////////
template<typename PointT, typename LeafContainerT, typename BranchContainerT, typename OctreeT> void
pcl::octree::OctreePointCloud<PointT, LeafContainerT, BranchContainerT, OctreeT>::addPointsFromInputCloud ()
{
size_t i;
if (indices_)
{
for (std::vector<int>::const_iterator current = indices_->begin (); current != indices_->end (); ++current)
{
assert( (*current>=0) && (*current < static_cast<int> (input_->points.size ())));
if (isFinite (input_->points[*current]))
{
// add points to octree
this->addPointIdx (*current);
}
}
}
else
{
for (i = 0; i < input_->points.size (); i++)
{
if (isFinite (input_->points[i]))
{
// add points to octree
this->addPointIdx (static_cast<unsigned int> (i));
}
}
}
}
The first execution of the loop under the else statement is successful but it then appears to be unable to read from _input and errors.

Answered my own question and figured I'd let everyone know what my issue was. In the reading section of my program I had altered the packing to ensure there was no padding when I was casting the read bytes to my struct. Simply changing '#pragma pack(1)' to #pragma pack(push,1) before the declaration of my struct and '#pragma pack(pop)' after the declaration brought PCL back to life. Of course that wasn't until recompiling PCL from scratch...lesson learned though!

Related

ImGui sample code/basic initialisation not working (Windows and Linux)

I am trying to setup ImGui to make some apps in, however I can't get it working. I installed the .h and .cpp files from the GitHub, https://github.com/ocornut/imgui, and followed the instructions to allow the project to compile, which it does. But on Windows and Linux (i've tried both), it spits out a runtime error, (stopped responding Windows, segmentation fault (core dumped) Linux). This is the sample code that was published,
#include "imgui.h"
int main()
{
// Create a window called "My First Tool", with a menu bar.
ImGui::Begin("My First Tool", &my_tool_active, ImGuiWindowFlags_MenuBar);
if (ImGui::BeginMenuBar())
{
if (ImGui::BeginMenu("File"))
{
if (ImGui::MenuItem("Open..", "Ctrl+O")) { /* Do stuff */ }
if (ImGui::MenuItem("Save", "Ctrl+S")) { /* Do stuff */ }
if (ImGui::MenuItem("Close", "Ctrl+W")) { my_tool_active = false; }
ImGui::EndMenu();
}
ImGui::EndMenuBar();
}
// Edit a color (stored as ~4 floats)
ImGui::ColorEdit4("Color", my_color);
// Plot some values
const float my_values[] = { 0.2f, 0.1f, 1.0f, 0.5f, 0.9f, 2.2f };
ImGui::PlotLines("Frame Times", my_values, IM_ARRAYSIZE(my_values));
// Display contents in a scrolling region
ImGui::TextColored(ImVec4(1,1,0,1), "Important Stuff");
ImGui::BeginChild("Scrolling");
for (int n = 0; n < 50; n++)
ImGui::Text("%04d: Some text", n);
ImGui::EndChild();
ImGui::End();
return 0;
}
Now this code doesn't compile due to my_tool_active and my_color, so I added these 2 lines to the code before the ImGui::Begin():
bool my_tool_active = true;
float my_color[4] = {0.5, 0.5, 0.5, 1};
So now when I compile and run, it gets to the ImGui::Begin() and then crashes at that stage. I have tried it in a much smaller example where it is just the ImGui::Begin() and ImGui::End() and placed print statements around it, and it showed that it never finished executing the Begin().
Imgui doesn't provide a graphics backend, neither it creates a window or a graphics API context. You have to provide it by yourself (using OpenGL/DirectX/Vulkan ecc...) or use a library that creates one for you (SDL/glfw ecc...).
Refer to the sample directory to a more complete sample.
This one is using sdl+openGl.
https://github.com/ocornut/imgui/blob/master/examples/example_sdl_opengl3/main.cpp

Program crashed during PCL visualization Error

I am new to PCL(Point Cloud Library).I used the default All-in-one-installer to install the PCL .The visual studio version is 2019.
Now, I want to run the simple PCD visualization code like this:
'''
#include <pcl/visualization/cloud_viewer.h>
#include <iostream>
#include <pcl/io/io.h>
#include <pcl/io/pcd_io.h>
int user_data;
void
viewerOneOff(pcl::visualization::PCLVisualizer& viewer)
{
viewer.setBackgroundColor(1.0, 0.5, 1.0);
pcl::PointXYZ o;
o.x = 1.0;
o.y = 0;
o.z = 0;
viewer.addSphere(o, 0.25, "sphere", 0);
std::cout << "i only run once" << std::endl;
}
void
viewerPsycho(pcl::visualization::PCLVisualizer& viewer)
{
static unsigned count = 0;
std::stringstream ss;
ss << "Once per viewer loop: " << count++;
viewer.removeShape("text", 0);
viewer.addText(ss.str(), 200, 300, "text", 0);
//FIXME: possible race condition here:
user_data++;
}
int
main()
{
pcl::PointCloud<pcl::PointXYZ>::Ptr cloud(new pcl::PointCloud<pcl::PointXYZ>);
pcl::io::loadPCDFile("C:/Users/Shinelon/Desktop/test_pcd.pcd", *cloud);
pcl::visualization::CloudViewer viewer("Cloud Viewer");
//blocks until the cloud is actually rendered
viewer.showCloud(cloud);
//use the following functions to get access to the underlying more advanced/powerful
//PCLVisualizer
//This will only get called once
viewer.runOnVisualizationThreadOnce(viewerOneOff);
////This will get called once per visualization iteration
viewer.runOnVisualizationThread(viewerPsycho);
while (!viewer.wasStopped())
{
//you can also do cool processing here
//FIXME: Note that this is running in a separate thread from viewerPsycho
//and you should guard against race conditions yourself...
user_data++;
}
return 0;
}
'''
The Result is:
I don't get any error, the compilation was successful. When I run, it will display a window, and then the program crashes.
I can not find the cause.Could someone help me?
Any suggestions will be appreciated.
Sorry, I don't know the version number of the previous NVIDIA driver on my laptop.
Coincidentally, a game running on my computer crashed yesterday because of "nvwgf2umx.DLL".The official solution is to reinstall the latest version of the NVIDIA driver which I did later.
As a result, the game worked, and the bugs in the post disappeared.
I hope that this answer will be helpful to others in the future.

System error: The program can't start because MSVCP140D.DLL is missing from your computer. Try reinstalling the program to fix this problem [duplicate]

This question already has answers here:
MSVCP140D.dll missing, is there a way around? [closed]
(2 answers)
Closed 3 years ago.
So I have programmed a simple graphical snake game using SFML in visual studio 2015
and it runs perfectly on my main computer. And I thought that I should try it on my laptop. When running the program it gave me this error:
System error: The program can't start because MSVCP140D.DLL is missing from your computer. Try reinstalling the program to fix this problem
So I searched it in my computer and found it so I copied it on my laptop and then again I received another error which was:
Application error: The application was unable to start correctly (0xc000007b). Click OK to close the application.
I tried reinstalling the Microsoft Visual C++ Redistributable and still it didn't work. (BTW it is not a code problem and I have installed SFML correctly and used its libraries and bins without any problem). Your help would mean a lot to me. Thank you!
Here is my code:
//
GraphicalLoopSnakeGame.cpp :
Defines the entry point for
the console application.
//
#include "stdafx.h"
#include <SFML/Graphics.hpp>
#include <time.h>
using namespace sf;
int N = 30, M = 20;
int size = 16;
int w = size*N;
int h = size*M;
int dir, num = 4;
struct Snake
{
int x, y;
} s[100];
struct Fruit
{
int x, y;
} f;
void Tick()
{
for (int i = num;i>0;--i)
{
s[i].x = s[i - 1].x;
s[i].y = s[i - 1].y;
}
if (dir == 0) s[0].y += 1;
if (dir == 1) s[0].x -= 1;
if (dir == 2) s[0].x += 1;
if (dir == 3) s[0].y -= 1;
if ((s[0].x == f.x) && (s[0].y == f.y))
{
num++; f.x = rand() % N; f.y = rand() % M;
}
if (s[0].x>N) s[0].x = 0; if (s[0].x<0) s[0].x = N;
if (s[0].y>M) s[0].y = 0; if (s[0].y<0) s[0].y = M;
for (int i = 1;i<num;i++)
if (s[0].x == s[i].x && s[0].y == s[i].y) num = i;
}
int main()
{
srand(time(0));
RenderWindow
window(VideoMode(w, h),
"Snake Game!");
Texture t1, t2, t3;
t1.loadFromFile("images/white.png");
t2.loadFromFile("images/red.png");
t3.loadFromFile("images/green.png");
Sprite sprite1(t1);
Sprite sprite2(t2);
Sprite sprite3(t3);
Clock clock;
float timer = 0, delay = 0.12;
f.x = 10;
f.y = 10;
while (window.isOpen())
{
float time = clock.getElapsedTime().asSeconds();
clock.restart();
timer += time;
Event e;
while (window.pollEvent(e))
{
if (e.type == Event::Closed)
window.close();
}
if (Keyboard::isKeyPressed(Keyboard::Left)) dir = 1;
if (Keyboard::isKeyPressed(Keyboard::Right)) dir = 2;
if (Keyboard::isKeyPressed(Keyboard::Up)) dir = 3;
if (Keyboard::isKeyPressed(Keyboard::Down)) dir = 0;
if (timer>delay) { timer = 0; Tick(); }
////// draw ///////
window.clear();
for (int i = 0; i<N; i++)
for (int j = 0; j<M; j++)
{
sprite1.setPosition(i*size, j*size); window.draw(sprite1);
}
for (int i = 0;i<num;i++)
{
sprite2.setPosition(s[i].x*size, s[i].y*size); window.draw(sprite2);
}
sprite3.setPosition(f.x*size, f.y*size); window.draw(sprite3);
window.display();
}
return 0;
}
You are using the debug visual studio runtime, if you want to try it on another computer you should recompile your code in release mode and make sure that the appropriate visual studio runtime redistributable is installed.
If you really need to run a debug executable on another machine you need to make sure you copy the correct runtime (32 or 64-bit according to how you've compiled your program), this can be found in C:\Program Files (x86)\Microsoft Visual Studio\2019\Professional\VC\Redist\MSVC\14.24.28127\debug_nonredist (at least for visual studio 2019, the exact path will be slightly different depending on your visual studio version, e.g. visual studio 2015 uses C:\Program Files (x86)\Microsoft Visual Studio 14.0\VC\redist\debug_nonredist).
As far as I'm concerned the PC is missing the runtime support DLLs for your program. I sugges you should download it from MS site and be sure there is no viruses: https://www.microsoft.com/en-US/download/details.aspx?id=48145
The application was unable to start correctly (0xc000007b). Click OK to close the application. Firstly I suggest to test whether there is a problem between your application and its dependencies using dependency walker.
And then the Error Code means: 0xC000007B STATUS_INVALID_IMAGE_FORMAT. I think that you trying to use 64-bit DLL with 32-bit application (or vice versa).

glutWarpPointer crash

I'm following these tutorials on modern OpenGL. I've done them up to number 15 "Camera Control - Part 2". The tutorial suggests using glutWarpPointer(). The problem is, my program crashes at that call. This is my code:
c_camera::c_camera(int width, int height, const c_vector3f& Pos, const c_vector3f& Target, const c_vector3f& Up){
m_windowWidth = width;
m_windowHeight = height;
m_pos = Pos;
m_target = Target;
m_target.Normalize();
m_up = Up;
m_up.Normalize();
Init();
}
void c_camera::Init(){
c_vector3f HTarget(m_target.x, 0.0, m_target.z);
HTarget.Normalize();
if (HTarget.z >= 0.0f){
if (HTarget.x >= 0.0f){
m_AngleH = 360.0f - (asin(HTarget.z) TO_DEG);
} else {
m_AngleH = 180.0f + (asin(HTarget.z) TO_DEG);
}
} else {
if (HTarget.x >= 0.0f){
m_AngleH = (asin(-HTarget.z) TO_DEG);
} else {
m_AngleH = 90.0f + (asin(-HTarget.z) TO_DEG);
}
}
m_AngleV = -(asin(m_target.y) TO_DEG);
m_OnUpperEdge = false;
m_OnLowerEdge = false;
m_OnLeftEdge = false;
m_OnRightEdge = false;
m_mousePos.x = m_windowWidth / 2;
m_mousePos.y = m_windowHeight / 2;
cout << "this gets printed just fine" << endl;
glutWarpPointer(500,400); //program crashes
cout << "this doesn't get printed" << endl;
}
I'm not sure if I'm doing something weird here, or if I just have a bad glut version (seems unlikely to me) or if the tutorial is just wrong... Do I need to set up something glut specific before I can call glutWarpPointer()? I am new to glut, and new to modern OpenGL (I learned immediate mode first).
A quick google search didn't help me much. Any help would be appreciated.
Edit: I am on windows, and I'm using mingw 4.5
Edit2: These are the details windows gives me about the crash:
Problem Event Name: APPCRASH
Application Name: modern_opengl.exe
Application Version: 0.0.0.0
Application Timestamp: 51044575
Fault Module Name: glut32.dll
Fault Module Version: 0.0.0.0
Fault Module Timestamp: 3bea4ff3
Exception Code: c0000005
Exception Offset: 0000a879
OS Version: 6.2.9200.2.0.0.256.48
Locale ID: 1043
Additional Information 1: 5861
Additional Information 2: 5861822e1919d7c014bbb064c64908b2
Additional Information 3: f3d5
Additional Information 4: f3d5be0cad2787556264647dc02181c3
Edit3: This is my call stack:
0 1000A879 glutWarpPointer() (C:\Windows\system\glut32.dll:??)
1 004033FB c_camera::Init(this=0x4aa0e0) (C:\CodeBlocks\projects\modern_opengl\c_camera.cpp:50)
2 00403164 c_camera::c_camera(this=0x4aa0e0, width=800, height=600, Pos=..., Target=..., Up=...) (C:\CodeBlocks\projects\modern_opengl\c_camera.cpp:18)
3 00402F4B __static_initialization_and_destruction_0(__initialize_p=1, __priority=65535) (C:\CodeBlocks\projects\modern_opengl\main.cpp:55)
4 00403004 GLOBAL_sub_I_vertices() (C:\CodeBlocks\projects\modern_opengl\main.cpp:177)
5 0043595B __do_global_ctors() (../mingw/gccmain.c:59)
6 00401098 __mingw_CRTStartup() (../mingw/crt1.c:236)
7 00401284 mainCRTStartup() (../mingw/crt1.c:264)
Your function seems to be in c_camera::Init, which seems to be called before main probably due to it being instantiated as a global object (globals are constructed before main is entered). You should delay glut calls till after you enter main and called glutInit is called.

Octave c++ and VS2010

I'm trying to Use Octave with Visual C++.
I have downloaded octave-3.6.1-vs2010-setup-1.exe. Created a new project, added octave include folder to include path, octinterp.lib and octave.lib to lib path, and I added Octave bin folder as running directory.
The program compiles and runs fine except feval function that causes the exception:
Microsoft C++ exception: octave_execution_exception at memory location 0x0012faef
and on Octave side:
Invalid resizing operation or ambiguous assignment to an out-of-bounds array element.
What am I doing wrong?
Code for a standalone program:
#include <octave/octave.h>
#include <octave/oct.h>
#include <octave/parse.h>
int main(int argc, char **argv)
{
if (octave_main (argc, argv, true))
{
ColumnVector NumRands(2);
NumRands(0) = 10;
NumRands(1) = 1;
octave_value_list f_arg, f_ret;
f_arg(0) = octave_value(NumRands);
f_ret = feval("rand",f_arg,1);
Matrix unis(f_ret(0).matrix_value());
}
else
{
error ("Octave interpreter initialization failed");
}
return 0;
}
Thanks in advance.
I tried it myself, and the problem seems to originate from the feval line.
Now I don't have an explanation as to why, but the problem was solved by simply switching to the "Release" configuration instead of the "Debug" configuration.
I am using the Octave3.6.1_vs2010 build, with VS2010 on WinXP.
Here is the code I tested:
#include <iostream>
#include <octave/oct.h>
#include <octave/octave.h>
#include <octave/parse.h>
int main(int argc, char **argv)
{
// Init Octave interpreter
if (!octave_main(argc, argv, true)) {
error("Octave interpreter initialization failed");
}
// x = rand(10,1)
ColumnVector sz(2);
sz(0) = 10; sz(1) = 1;
octave_value_list in = octave_value(sz);
octave_value_list out = feval("rand", in, 1);
// print random numbers
if (!error_state && out.length () > 0) {
Matrix x( out(0).matrix_value() );
std::cout << "x = \n" << x << std::endl;
}
return 0;
}
with an output:
x =
0.165897
0.0239711
0.957456
0.830028
0.859441
0.513797
0.870601
0.0643697
0.0605021
0.153486
I'd guess that its actually stopped pointing at the next line and the error actually lies at this line:
f_arg(0) = octave_value(NumRands);
You seem to be attempting to get a value (which value?) from a vector and then assigning it to element 0 of a vector that has not been defined as a vector.
I don't really know though ... I've never tried writing octave code like that. I'm just trying to work it out by translating the code to standard matlab/octave code and that line seems really odd to me ...