Exceptions in using astra sdk functions in multi-thread application

The sdk should not be used in multi thread applications?
here is the code below:

// HumanFollower.cpp : 定义控制台应用程序的入口点。
//

#include “stdafx.h”
#include <astra/astra.hpp>
#include <windows.h>

#pragma comment(lib,“astra.lib”)
#pragma comment(lib,“astra_core.lib”)
#pragma comment(lib,“astra_core_api.lib”)

class DetectListener : public astra::FrameListener
{
public:

virtual void on_frame_ready(astra::StreamReader& reader, 
	astra::Frame& frame) override
{
	processBodies(frame);
}

protected:

void processBodies(astra::Frame& frame)
{
	astra::BodyFrame bodyFrame = frame.get<astra::BodyFrame>();

	if (!bodyFrame.is_valid())
	{
		return;
	}

	const auto& bodies = bodyFrame.bodies();
	//身体数据,但是有bodyid
	for (auto& body : bodies)
	{
		auto ptCOM = body.center_of_mass();
		printf(" body %d center of mass: x: %d , y: %d , z: %d\n",
			body.id(), int(ptCOM.x), int(ptCOM.y), int(ptCOM.z));

// if (NULL != m_pEvt)
// {
// m_pEvt->UserTracked(body.id(), ptCOM);
// }
}
}
};

astra::DepthStream configure_depth(astra::StreamReader& reader)
{
auto depthStream = reader.streamastra::DepthStream();

//We don't have to set the mode to start the stream, but if you want to here is how:
astra::ImageStreamMode bodyMode;

bodyMode.set_width(160);
bodyMode.set_height(120);
bodyMode.set_pixel_format(astra_pixel_formats::ASTRA_PIXEL_FORMAT_DEPTH_MM);
bodyMode.set_fps(30);

depthStream.set_mode(bodyMode);

return depthStream;

}

#include <conio.h>

astra::StreamSet streamSet;
astra::StreamReader reader;

DetectListener listener;

HANDLE hDetectThread = INVALID_HANDLE_VALUE;

void DetectThread(LPVOID pVoid)
{
printf(“threead begiiiiiiiiiiiiiiin \n”);
bool bExit = false;

while (!bExit)
{
	astra_status_t st = astra_update();

	//键盘输入,非阻塞
	if (_kbhit() != 0)
	{
		//判断缓冲区内容
		if (_getch() == 'c')
		{
			bExit = true;
		}
	}
}

reader.remove_listener(listener);

astra::terminate();

}

int main()
{
astra_status_t sta = astra::initialize();
//astra::StreamSet streamSet;
/*astra::StreamReader */reader = streamSet.create_reader();

//DetectListener listener;

auto depthStream = configure_depth(reader);
depthStream.start();

reader.stream<astra::BodyStream>().start();

reader.add_listener(listener);

DWORD dwThId;
hDetectThread = CreateThread(NULL, 0, (LPTHREAD_START_ROUTINE)DetectThread, NULL, 0, &dwThId);


if(hDetectThread == INVALID_HANDLE_VALUE)
{
	return -1;
}

return 0;

}

1 Like

I am facing same problems. Any solutions here? If there is not a support for multi-threading, how can I do other jobs if I do while states for listener?

i am facing problem while installing the driver can you help me
my contact:-
mobile no:-+917249857104
mail id:- kalebalram43@gmail.com

Hi, have you tried with different PC? Please try this:

  1. Uninstall the driver you installed
  2. Restart PC
  3. Install the driver again.
  4. Restart PC

If still does not work, please let me know:

  1. You are using Windows 10 32bit or 64bit?
  2. The sensor is plugged to USB3.0 or USB2.0?

You may try installing with different PC to check whether the problem persists.

  • Sattiyan