错误访问返回 NSObject

Bad Access returning NSObject

提问人:cj- 提问时间:11/11/2023 最后编辑:eyllanesccj- 更新时间:11/11/2023 访问量:20

问:

我遇到了一个相当常见的错误,即从 C++ 类方法返回由 Kotlin Multiplatform 创建的 NSObject 会导致EXC_BAD_ACCESS(由 Sentry Error Tracking 报告)。为什么会发生这种情况,可以做些什么来防止它?

以下是课程的相关部分:

AgraQML::MountPoint::MountPoint(SMLMountPoint* point) {
    [point retain];
    m_mountPoint = point;
}

AgraQML::MountPoint::~MountPoint() {
    [m_mountPoint release];
}

SMLMountPoint* AgraQML::MountPoint::getMountPoint() const {
    return m_mountPoint;
}

以下是 MountPoint 和 SMLMountPoint 的实例化方式:

SMLMountPoint *point = [[SMLMountPoint alloc] initWithRecord:mountPointRecord.toNSString()];
auto oldMountPoint = findChild<AgraQML::MountPoint*>();
AgraQML::MountPoint* mountPoint;
if (oldMountPoint == nullptr || oldMountPoint->path() != QString::fromNSString(point.path)) {
    // Make a new MountPoint
    mountPoint = new AgraQML::MountPoint(point);
    mountPoint->setParent(this);
    if (oldMountPoint != nullptr) // Remove the outdated MountPoint
        oldMountPoint->deleteLater();
} else {
    // Use the old MountPoint
    mountPoint = oldMountPoint;
}

以下是发生的异常:

Exception Type: EXC_BAD_ACCESS (SIGSEGV)
Exception Codes: SEGV_NOOP at 0x0000000000000010
Crashed Thread: 0

Application Specific Information:
__cxa_guard_release > _setInvalidatesViewsOnAppearanceChange: > application:didFinishLaunchingWithOptions: >
KERN_INVALID_ADDRESS at 0x10.

Thread 0 Crashed:
0   AgraGPS                         0x2009acb74         AgraQML::MountPoint::getMountPoint (MountPoint.mm:16)
1   AgraGPS                         0x20099877c         AgraQML::NTRIP::restoreGetData (NTRIP.mm:61)
Kotlin-多平台 Objective-C++

评论

0赞 cj- 12/5/2023
没有选择,最终完全绕过了这段代码。仍然不确定原因,如果有人知道,将来知道会很棒。
0赞 The Dreams Wind 12/11/2023
您提供的错误列表显示它调用 ,而 又调用 。在给定的代码片段中都没有调用这两个函数,您能提供更相关的代码吗?另外 - 您在编译类时是否禁用了 ARC?restoreGetDatagetMountPointAgraQML::MountPoint

答: 暂无答案