GestureRecognizer 在 WP Direct3D App 中抛出异常
GestureRecognizer throws exception in WP Direct3D App
我现在正在开发 WP10 的图形应用程序。我需要使用 GestureRecognizer 来移动屏幕上的对象并调整其大小。看起来很酷,但在某些情况下使用两个手指手势时,GestureRecognizer 会抛出此错误。
WinRT 信息:帧中的数据包不一致。指针 ID 不唯一,或者时间戳、帧 ID、指针类型或源设备存在差异。
一个手指手势就可以了。奇怪的是,这个逻辑在 WP8.1 上运行良好。
这是我的 RecognizerHelper 的源代码:
GestureHelper::GestureHelper(){
this->recognizer = ref new GestureRecognizer();
this->recognizer->GestureSettings = GestureSettings::ManipulationScale | GestureSettings::ManipulationTranslateX |
GestureSettings::ManipulationTranslateY | GestureSettings::Tap | GestureSettings::ManipulationRotate | GestureSettings::DoubleTap;
this->recognizer->Tapped += ref new TypedEventHandler<GestureRecognizer ^, TappedEventArgs ^>(this, &GestureHelper::OnTapped);
this->recognizer->ManipulationStarted += ref new TypedEventHandler<GestureRecognizer ^, ManipulationStartedEventArgs ^>(this, &GestureHelper::OnManipulationStarted);
this->recognizer->ManipulationCompleted += ref new TypedEventHandler<GestureRecognizer ^, ManipulationCompletedEventArgs ^>(this, &GestureHelper::OnManipulationCompleted);
this->recognizer->ManipulationUpdated += ref new TypedEventHandler<GestureRecognizer ^, ManipulationUpdatedEventArgs ^>(this, &GestureHelper::OnManipulationUpdated);
}
void GestureHelper::ProcessPress(PointerPoint ^ppt){
this->recognizer->ProcessDownEvent(ppt);
if (this->Clicked) {
this->Clicked(ppt->Position.X, ppt->Position.Y);
}
}
void GestureHelper::ProcessMove(PointerPoint ^ppt){
this->recognizer->ProcessMoveEvents(ppt->GetIntermediatePoints(ppt->PointerId));
}
void GestureHelper::ProcessRelease(PointerPoint ^ppt){
this->recognizer->ProcessUpEvent(ppt);
}
void GestureHelper::OnManipulationStarted(GestureRecognizer^ sender, ManipulationStartedEventArgs^ e){
if (this->Pressed){
this->Pressed(e->Position.X, e->Position.Y);
}
}
void GestureHelper::OnManipulationCompleted(GestureRecognizer ^sender, ManipulationCompletedEventArgs ^e) {
if (this->Released) {
this->Released(e->Position.X, e->Position.Y);
}
}
void GestureHelper::OnManipulationUpdated(GestureRecognizer ^sender, ManipulationUpdatedEventArgs ^e){
if (this->MoveUpdated){
this->MoveUpdated(e->Position.X, e->Position.Y);
}
if (this->ZoomUpdated){
this->ZoomUpdated(e->Delta.Scale);
}
if (this->RotateUpdated) {
this->RotateUpdated(-e->Delta.Rotation);
}
}
void GestureHelper::OnTapped(GestureRecognizer ^sender, TappedEventArgs ^e){
if (this->Pressed) {
this->Pressed(e->Position.X, e->Position.Y);
}
if (this->Released){
this->Released(e->Position.X, e->Position.Y);
}
}
感谢您的帮助!
更新:
try-catch 有帮助,但还是想明白,为什么会抛出这个异常
好的,我在微软论坛上得到了答案。这是微软的错误,将在下一次更新中修复。所以现在我用try catch来解决这个问题。
我现在正在开发 WP10 的图形应用程序。我需要使用 GestureRecognizer 来移动屏幕上的对象并调整其大小。看起来很酷,但在某些情况下使用两个手指手势时,GestureRecognizer 会抛出此错误。
WinRT 信息:帧中的数据包不一致。指针 ID 不唯一,或者时间戳、帧 ID、指针类型或源设备存在差异。
一个手指手势就可以了。奇怪的是,这个逻辑在 WP8.1 上运行良好。
这是我的 RecognizerHelper 的源代码:
GestureHelper::GestureHelper(){
this->recognizer = ref new GestureRecognizer();
this->recognizer->GestureSettings = GestureSettings::ManipulationScale | GestureSettings::ManipulationTranslateX |
GestureSettings::ManipulationTranslateY | GestureSettings::Tap | GestureSettings::ManipulationRotate | GestureSettings::DoubleTap;
this->recognizer->Tapped += ref new TypedEventHandler<GestureRecognizer ^, TappedEventArgs ^>(this, &GestureHelper::OnTapped);
this->recognizer->ManipulationStarted += ref new TypedEventHandler<GestureRecognizer ^, ManipulationStartedEventArgs ^>(this, &GestureHelper::OnManipulationStarted);
this->recognizer->ManipulationCompleted += ref new TypedEventHandler<GestureRecognizer ^, ManipulationCompletedEventArgs ^>(this, &GestureHelper::OnManipulationCompleted);
this->recognizer->ManipulationUpdated += ref new TypedEventHandler<GestureRecognizer ^, ManipulationUpdatedEventArgs ^>(this, &GestureHelper::OnManipulationUpdated);
}
void GestureHelper::ProcessPress(PointerPoint ^ppt){
this->recognizer->ProcessDownEvent(ppt);
if (this->Clicked) {
this->Clicked(ppt->Position.X, ppt->Position.Y);
}
}
void GestureHelper::ProcessMove(PointerPoint ^ppt){
this->recognizer->ProcessMoveEvents(ppt->GetIntermediatePoints(ppt->PointerId));
}
void GestureHelper::ProcessRelease(PointerPoint ^ppt){
this->recognizer->ProcessUpEvent(ppt);
}
void GestureHelper::OnManipulationStarted(GestureRecognizer^ sender, ManipulationStartedEventArgs^ e){
if (this->Pressed){
this->Pressed(e->Position.X, e->Position.Y);
}
}
void GestureHelper::OnManipulationCompleted(GestureRecognizer ^sender, ManipulationCompletedEventArgs ^e) {
if (this->Released) {
this->Released(e->Position.X, e->Position.Y);
}
}
void GestureHelper::OnManipulationUpdated(GestureRecognizer ^sender, ManipulationUpdatedEventArgs ^e){
if (this->MoveUpdated){
this->MoveUpdated(e->Position.X, e->Position.Y);
}
if (this->ZoomUpdated){
this->ZoomUpdated(e->Delta.Scale);
}
if (this->RotateUpdated) {
this->RotateUpdated(-e->Delta.Rotation);
}
}
void GestureHelper::OnTapped(GestureRecognizer ^sender, TappedEventArgs ^e){
if (this->Pressed) {
this->Pressed(e->Position.X, e->Position.Y);
}
if (this->Released){
this->Released(e->Position.X, e->Position.Y);
}
}
感谢您的帮助!
更新: try-catch 有帮助,但还是想明白,为什么会抛出这个异常
好的,我在微软论坛上得到了答案。这是微软的错误,将在下一次更新中修复。所以现在我用try catch来解决这个问题。