The sample code for perception simulation crashes my device. The device do respond to voice commands but there is not response to hand gestures neither no visuals. I have to use WDR to reset it everytime
Link to the documentation
https://learn.microsoft.com/en-us/windows/mixed-reality/perception-simulation
Here is the source code.
class Program
{
static void Main(string[] args)
{
Task.Run(async () =>
{
try
{
RestSimulationStreamSink sink = await RestSimulationStreamSink.Create(
// use the IP address for your device/emulator
new Uri("http://127.0.0.1:10080"),
// no credentials are needed for the emulator
new System.Net.NetworkCredential("snarain", "snarain"),
// normal priorty
true,
// cancel token
new System.Threading.CancellationToken());
IPerceptionSimulationManager manager = PerceptionSimulationManager.CreatePerceptionSimulationManager(sink);
}
catch (Exception e)
{
Console.WriteLine(e);
}
});
// If main exits, the process exits.
Console.WriteLine("Press any key to exit...");
Console.ReadLine();
}
}
After a week of troubleshooting, I noticed the control mode switches to simulation that suspends all sensors to detect human gestures which makes the device unresponsive.
Switching it back to Default resolves this problem.
Solved !!
Related
my scenario is simple:i made a game using cocos2d-x and i want to download images (FB and Google play) for multi player users and show them once the download is done as texture for a button.
in ideal world, things work as expected.
things get tricky when those buttons got deleted before the download is done.
so the callback function is in weird state and then i get signal 11 (SIGSEGV), code 1 (SEGV_MAPERR)
and the app crashes
This is how i implmented it
I have a Layout class called PlayerIcon. the cpp looks like this
void PlayerIcon::setPlayer(string userName, string displayName, string avatarUrl){
try {
//some code here
downloadAvatar(_userName, _avatarUrl);
//some code here
}
catch(... ){
}
}
void PlayerIcon::downloadAvatar(std::string _avatarFilePath,std::string url) {
if(!isFileExist(_avatarFilePath)) {
try {
auto downloader = new Downloader();
downloader->onFileTaskSuccess=CC_CALLBACK_1(PlayerIcon::on_download_success,this);
downloader->onTaskError=[&](const network::DownloadTask& task,int errorCode,
int errorCodeInternal,
const std::string& errorStr){
log("error while saving image");
};
downloader->createDownloadFileTask(url,_avatarFilePath,_avatarFilePath);
}
catch (exception e)
{
log("error while saving image: test");
}
} else {
//set texture for button
}
}
void PlayerIcon::on_download_success(const network::DownloadTask& task){
_isDownloading = false;
Director::getInstance()->getScheduler()-> performFunctionInCocosThread(CC_CALLBACK_0(PlayerIcon::reload_avatar,this));
}
void PlayerIcon::reload_avatar(){
try {
// setting texture in UI thread
}
catch (...) {
log("error updating avatar");
}
}
As i said, things works fine until PlayerIcon is deleted before the download is done.
i dont know what happens when the call back of the download task point to a method of un object that s deleted (or flagged for deletion).
i looked in the downloader implementation and it doesn't provide any cancellation mechanism
and i'm not sure how to handle this
Also, is it normal to have 10% crash rate on google console for a cocos2dx game
any help is really appreciated
Do you delete de Downloader in de destructor of the PlayerIcon?
there is a destroy in the apple implementation witch is trigered by the destructor.
-(void)doDestroy
{
// cancel all download task
NSEnumerator * enumeratorKey = [self.taskDict keyEnumerator];
for (NSURLSessionDownloadTask *task in enumeratorKey)
{
....
DownloaderApple::~DownloaderApple()
{
DeclareDownloaderImplVar;
[impl doDestroy];
DLLOG("Destruct DownloaderApple %p", this);
}
In the demo code of cocos2d-x: DownloaderTest.cpp they use:
std::unique_ptr<network::Downloader> downloader;
downloader.reset(new cocos2d::network::Downloader());
instead of:
auto downloader = new Downloader();
It looks like you are building this network code as part of your scene tree. If you do a replaceScene/popScene...() call, while the async network software is running in the background, this will cause the callback to disappear (the scene will be deleted from the scene-stack) and you will get a SEGFAULT from this.
If this is the way you've coded it, then you might want to extract the network code to a global object (singleton) where you queue the requests and then grab them off the internet saving the results in the global-object's output queue (or their name and location) and then let the scene code check to see if the avatar has been received yet by inquiring on the global-object and loading the avatar sprite at this point.
Note, this may be an intermittent problem which depends on the speed of your machine and the network so it may not be triggered consistently.
Another solution ...
Or you could just set your function pointers to nullptr in your PlayerIcon::~PlayerIcon() (destructor):
downloader->setOnFileTaskSuccess(nullptr);
downloader->setOnTaskProgress(nullptr);
Then there will be no attempt to call your callback functions and the SEGFAULT will be avoided (Hopefully).
I completed this tutorial and can see data sent to Azure's cloud.
https://microsoft.github.io/azure-iot-developer-kit/docs/get-started/
But, looking at the serial monitor, I see it disconnecting and reconnecting over and over, between the successful sensor messages.
[...] hardware\stm32f4\1.6.0\cores\arduino\azure-iot-sdk-c\c-utility\adapters\socketio_mbed_os5.c Func:send_queued_data Line:213,
Socketio_Failure: encountered unknow connection issue, the connection will be restarted.
2019-03-27 00:35:28 INFO: >>>Connection status: disconnected
2019-03-27 00:35:30 INFO: >>>Re-connect.
My connection seems fine, judging by Google's speed test.
It's connection issue, the IoT DevKit only support 2.4GHz Wi-Fi, please make sure not connect with a 5GHz AP.
If 2.4GHz, can you try another AP? Like set your cell phone as a Hotspot.
Wasn't able to run the Get Started project on any connection, but I just created a new IotHub Project from scratch in Studio Code and it now stays connected.
Maybe I needed to update my firmware or something, I'll try it later, but if someone has the same issue and wants to get running, here's the simple working code that was generated:
#include "AZ3166WiFi.h"
#include "DevKitMQTTClient.h"
static bool hasWifi = false;
static bool hasIoTHub = false;
void setup() {
// put your setup code here, to run once:
if (WiFi.begin() == WL_CONNECTED)
{
hasWifi = true;
Screen.print(1, "Running...");
if (!DevKitMQTTClient_Init())
{
hasIoTHub = false;
return;
}
hasIoTHub = true;
}
else
{
hasWifi = false;
Screen.print(1, "No Wi-Fi");
}
}
void loop() {
// put your main code here, to run repeatedly:
if (hasIoTHub && hasWifi)
{
char buff[128];
// replace the following line with your data sent to Azure IoTHub
snprintf(buff, 128, "{\"topic\":\"iot\"}");
if (DevKitMQTTClient_SendEvent(buff))
{
Screen.print(1, "Sending...");
}
else
{
Screen.print(1, "Failure...");
}
delay(2000);
}
}
Having a weird problem with an UWP app I'm trying to create when creating a socket and reading back data from it. Here's the basic scenario:
_commandSocket = new StreamSocket();
await _commandSocket.ConnectAsync(new HostName("192.168.1.1"), "15740", SocketProtectionLevel.PlainSocket);
_commandOutput = _commandSocket.OutputStream;
_commandInput = _commandSocket.InputStream;
await _commandOutput.WriteAsync(initCommandBuffer);
var lengthBytes = new byte[4].AsBuffer();
await input.ReadAsync(lengthBytes, 4, InputStreamOptions.None);
etc..etc...etc...
I'm basically opening a socket and sending an initialization command to my device. The idea is that it'll reply by first sending me the length of the reply as an uint.
This all works perfectly well when I debug/run the app on my desktop, but if I try to run this on my Window 10 Mobile device (Nokia 930) it seems not a single byte is being read (I've tried reading 1 byte instead of 4). Since app development should be 'Universal' and it's all working perfectly on my desktop I have no idea where to start fixing this.
Opening the connection on the mobile device works, I'm also not getting any errors when sending the initialization command, it just keeps blocking on the await ReadAsync command (as if nothing is being sent back).
I don't have any influence on the device that I'm connecting to, but again since this is all working flawlessly on the desktop and the device doesn't know who's asking I'm pretty clueless.
Cannot confirm my answer for sure, becasue I only tested in on an emulator, but I used stream socket listener.
private async void StartServer()
{
int Port = 80;
try
{
//Bound to port 80
await listener.BindServiceNameAsync(Port.ToString());
}
catch (System.Runtime.InteropServices.COMException)
{
//Port 80 for communication is blocked.
}
listener.ConnectionReceived += async (s, e) =>
{
using (IInputStream input = e.Socket.InputStream)
{
var buffer = new Windows.Storage.Streams.Buffer(200);
await input.ReadAsync(buffer, buffer.Capacity, InputStreamOptions.Partial);
//reads incoming stream
string data = Encoding.ASCII.GetString(buffer.ToArray(), 0, (int) buffer.Length);
}
using (IOutputStream output = e.Socket.OutputStream)
{
using (Stream response = output.AsStreamForWrite())
{
response.Write(Encoding.ASCII.GetBytes("Response."), 0, 1);
}
}
};
}
I have a client application that receives video stream from a server via UDP or TCP socket.
Originally, when it was written using .NET 2.0 the code was using BeginReceive/EndReceive and IAsyncResult.
The client displays each video in it's own window and also using it's own thread for communicating with the server.
However, since the client is supposed to be up for a long period of time, and there might be 64 video streams simultaneously, there is a "memory leak" of IAsyncResult objects that are allocated each time the data receive callback is called.
This causes the application eventually to run out of memory, because the GC can't handle releasing of the blocks in time. I verified this using VS 2010 Performance Analyzer.
So I modified the code to use SocketAsyncEventArgs and ReceiveFromAsync (UDP case).
However, I still see a growth in memory blocks at:
System.Net.Sockets.Socket.ReceiveFromAsync(class System.Net.Sockets.SocketAsyncEventArgs)
I've read all the samples and posts about implementing the code, and still no solution.
Here's how my code looks like:
// class data members
private byte[] m_Buffer = new byte[UInt16.MaxValue];
private SocketAsyncEventArgs m_ReadEventArgs = null;
private IPEndPoint m_EndPoint; // local endpoint from the caller
Initializing:
m_Socket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
m_Socket.Bind(m_EndPoint);
m_Socket.SetSocketOption(SocketOptionLevel.Socket, SocketOptionName.ReceiveBuffer, MAX_SOCKET_RECV_BUFFER);
//
// initalize the socket event args structure.
//
m_ReadEventArgs = new SocketAsyncEventArgs();
m_ReadEventArgs.Completed += new EventHandler<SocketAsyncEventArgs>(readEventArgs_Completed);
m_ReadEventArgs.SetBuffer(m_Buffer, 0, m_Buffer.Length);
m_ReadEventArgs.RemoteEndPoint = new IPEndPoint(IPAddress.Any, 0);
m_ReadEventArgs.AcceptSocket = m_Socket;
Starting the read process:
bool waitForEvent = m_Socket.ReceiveFromAsync(m_ReadEventArgs);
if (!waitForEvent)
{
readEventArgs_Completed(this, m_ReadEventArgs);
}
Read completion handler:
private void readEventArgs_Completed(object sender, SocketAsyncEventArgs e)
{
if (e.BytesTransferred == 0 || e.SocketError != SocketError.Success)
{
//
// we got error on the socket or connection was closed
//
Close();
return;
}
try
{
// try to process a new video frame if enough data was read
base.ProcessPacket(m_Buffer, e.Offset, e.BytesTransferred);
}
catch (Exception ex)
{
// log and error
}
bool willRaiseEvent = m_Socket.ReceiveFromAsync(e);
if (!willRaiseEvent)
{
readEventArgs_Completed(this, e);
}
}
Basically the code works fine and I see the video streams perfectly, but this leak is a real pain.
Did I miss anything???
Many thanks!!!
Instead of recursively calling readEventArgs_Completed after !willRaiseEvent use goto to return to the top of the method. I noticed I was slowly chewing up stack space when I had a pattern similar to yours.
I have a BlackBerry App that sends data over a web service when a button has it state set to ON. When the button is ON a timer is started which is running continuously in the background at fixed intervals. The method for HttpConnection is called as follows:
if(C0NNECTION_EXTENSION==null)
{
Dialog.alert("Check internet connection and try again");
return;
}
else
{
confirmation=PostMsgToServer(encryptedMsg);
}
The method PostMsgToServer is as follows:
public static String PostMsgToServer(String encryptedGpsMsg) {
//httpURL= "https://prerel.track24c4i.com/track24prerel/service/spi/post?access_id="+DeviceBoardPassword+"&IMEI="+IMEI+"&hex_data="+encryptedGpsMsg+"&device_type=3";
httpURL= "https://t24.track24c4i.com/track24c4i/service/spi/post?access_id="+DeviceBoardPassword+"&IMEI="+IMEI+"&hex_data="+encryptedGpsMsg+"&device_type=3";
//httpURL= "http://track24.unit1.overwatch/track24/service/spi/post?access_id="+DeviceBoardPassword+"&IMEI="+IMEI+"&hex_data="+encryptedGpsMsg+"&device_type=3";
try {
String C0NNECTION_EXTENSION = checkInternetConnection();
if(C0NNECTION_EXTENSION==null)
{
Dialog.alert("Check internet connection and try again");
return null;
}
else
{
httpURL=httpURL+C0NNECTION_EXTENSION+";ConnectionTimeout=120000";
//Dialog.alert(httpURL);
HttpConnection httpConn;
httpConn = (HttpConnection) Connector.open(httpURL);
httpConn.setRequestMethod(HttpConnection.POST);
DataOutputStream _outStream = new DataOutputStream(httpConn.openDataOutputStream());
byte[] request_body = httpURL.getBytes();
for (int i = 0; i < request_body.length; i++) {
_outStream.writeByte(request_body[i]);
}
DataInputStream _inputStream = new DataInputStream(
httpConn.openInputStream());
StringBuffer _responseMessage = new StringBuffer();
int ch;
while ((ch = _inputStream.read()) != -1) {
_responseMessage.append((char) ch);
}
String res = (_responseMessage.toString());
responce = res.trim();
httpConn.close();
}
}catch (Exception e) {
//Dialog.alert("Connection Time out");
}
return responce;
}
My Question: The App freezes whenever the method is called, i.e. whenever the timer has to execute and send data to the web service the App freezes - at times for a few seconds and at times for a considerable amount of time applying to the user as if the handset has hanged. Can this be solved? Kindly help!!
You are running your networking operation on the Event Thread - i.e. the same Thread that processes your application's Ui interactions. Networking is a blocking operation so effectively this is stopping your UI operation. Doing this on the Event Thread is not recommended and to be honest, I'm surprised it is not causing your application to be terminated, as this is often what the OS will do, if it thinks the application has blocked the Event Thread.
The way to solve this is start your network processing using a separate Thread. This is generally the easy part, the difficult part is
blocking the User from doing anything else while waiting for the
response (assuming you need to do this)
updating the User Interface with the results of your networking
processing
I think the second of these issues are discussed in this Thread:
adding-field-from-a-nonui-thread-throws-exception-in-blackberry
Since it appears you are trying to do this update at regular intervals in the background, I don't think the first is an issue, - for completeness, you can search SO for answers including this one:
blackberry-please-wait-screen-with-time-out
There is more information regarding the Event Thread here:
Event Thread