在发布模式下崩溃,但是如果可调试为true,则为true-否...可能是什么问题? [英] Crash in release mode, but if debuggable true - not... What is possible issue?
问题描述
我使用ndk
+ openGL
创建了一个示例项目.该应用程序的想法很简单,点击屏幕上出现的AR对象时,请打开相机.
I made a sample project using ndk
+ openGL
. Idea of the app is simple, open the camera when you tap on the screen AR object appear on place where you tapped.
在debug mode
中工作时一切正常,但是在切换release mode
后,编译正常,我可以打开相机,但是当我点击屏幕时,应用程序崩溃了.
When I worked in debug mode
all was ok, but after I switched in release mode
, compilation is ok, I can open the camera, but when I tap on the screen the app crashed.
当然有任何日志...因此,为了打开日志选项(以找出崩溃的原因),我在release
部分中添加了这样的行debuggable true
.
Of course there any logs... So, to open the logs option (in order to find out the reason of the crash) I added such line debuggable true
in release
section.
但是,现在我在屏幕上点击时,应用程序不会崩溃...
But, now when I tap on the screen the app don't crash...
崩溃的可能原因是什么?如果我仅使用debuggable false
崩溃而看不到日志...怎么办?
What is the possible reason of crash? How can I check it if I get crash only with debuggable false
and can't see logs...?
这是我的gradle
apply plugin: 'com.android.application'
/*
The arcore aar library contains the native shared libraries. These are
extracted before building to a temporary directory.
*/
def arcore_libpath = "${buildDir}/arcore-native"
// Create a configuration to mark which aars to extract .so files from
configurations { natives }
android {
compileSdkVersion 27
defaultConfig {
applicationId "com.google.ar.core.examples.c.helloar"
// 24 is the minimum since ARCore only works with 24 and higher.
minSdkVersion 24
targetSdkVersion 27
versionCode 1
versionName "1.0"
signingConfig signingConfigs.debug
externalNativeBuild {
cmake {
cppFlags "-std=c++11", "-Wall"
arguments "-DANDROID_STL=c++_static",
"-DARCORE_LIBPATH=${arcore_libpath}/jni",
"-
DARCORE_INCLUDE=${project.rootDir}
/../../libraries/include"
}
}
ndk {
abiFilters "arm64-v8a", "armeabi-v7a", "x86"
}
}
compileOptions {
sourceCompatibility JavaVersion.VERSION_1_8
targetCompatibility JavaVersion.VERSION_1_8
}
buildTypes {
release {
debuggable true
minifyEnabled false
proguardFiles getDefaultProguardFile
('proguard-android.txt'), 'proguard-rules.pro'
}
}
externalNativeBuild {
cmake {
path "CMakeLists.txt"
}
}
}
dependencies {
// ARCore library
implementation 'com.google.ar:core:1.9.0'
natives 'com.google.ar:core:1.9.0'
implementation 'com.android.support:appcompat-v7:27.1.1'
implementation 'com.android.support:design:27.1.1'
}
// Extracts the shared libraries from aars in the natives configuration.
// This is done so that NDK builds can access these libraries.
task extractNativeLibraries() {
// Always extract, this insures the native libs
are updated if the version changes.
outputs.upToDateWhen { false }
doFirst {
configurations.natives.files.each { f ->
copy {
from zipTree(f)
into arcore_libpath
include "jni/**/*"
}
}
}
}
tasks.whenTaskAdded {
task-> if (task.name.contains("external") && !task.name.contains("Clean")) {
task.dependsOn(extractNativeLibraries)
}
}
和应用gradle
// Top-level build file where you can add
configuration options common to all sub-projects/modules.
buildscript {
repositories {
google()
jcenter()
}
dependencies {
classpath 'com.android.tools.build:gradle:3.3.0'
// NOTE: Do not place your application dependencies here; they belong
// in the individual module build.gradle files
}
}
allprojects {
repositories {
google()
jcenter()
mavenLocal()
}
}
task clean(type: Delete) {
delete rootProject.buildDir
}
编辑
我在这里得到了一些日志输出
Here I got some log output
*** *** *** *** *** *** *** *** *** *** *** *** *** *** *** ***
Build fingerprint: 'samsung/crownltexx/crownlte:9/PPR1.180610.011/N960FXXU2CSDE:user/release-keys'
Revision: '28'
ABI: 'arm64'
pid: 11411, tid: 11600, name: GLThread 82400 >>> com.myapp.ar <<<
signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
Abort message: 'terminating with uncaught exception of type std::bad_alloc: std::bad_alloc'
x0 0000000000000000 x1 0000000000002d50 x2 0000000000000006 x3 0000000000000008
x4 fefefefefefefeff x5 fefefefefefefeff x6 fefefefefefefeff x7 7f7f7f7f7f7f7f7f
x8 0000000000000083 x9 0000007f5c9fa890 x10 fffffff87ffffbdf x11 0000000000000001
x12 0000000000000018 x13 000000005d0788d4 x14 00057c28f4018340 x15 00001ef146270368
x16 0000007f5ca312b0 x17 0000007f5c970958 x18 0000000000000000 x19 0000000000002c93
x20 0000000000002d50 x21 0000000000000083 x22 ffffff80ffffffc8 x23 0000007e94b00cb0
x24 0000007e94b00b90 x25 0000007e94b00bd0 x26 0000000000000016 x27 ffffffffffffffb0
x28 0000007ebfc24e9c x29 0000007e94b00b00
sp 0000007e94b00ac0 lr 0000007f5c963da0 pc 0000007f5c963dcc
backtrace:
#00 pc 0000000000021dcc /system/lib64/libc.so (abort+124)
#01 pc 00000000000cccac /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so
#02 pc 00000000000cce0c /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so
#03 pc 00000000000c9bf0 /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so
#04 pc 00000000000c92f8 /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so
#05 pc 00000000000c9278 /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (__cxa_throw+120)
#06 pc 00000000000cc588 /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (operator new(unsigned long)+84)
#07 pc 000000000006c3c0 /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>::append(char const*, unsigned long)+264)
#08 pc 000000000006e59c /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (FrameManager::LoadImage(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>)+280)
#09 pc 0000000000050ed8 /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (hello_ar::VideoRender::thread_task2(std::__ndk1::basic_string<char, std::__ndk1::char_traits<char>, std::__ndk1::allocator<char>>, std::__ndk1::shared_ptr<FrameManager>)+60)
#10 pc 000000000006c800 /data/app/com.myapp.ar-jewGNQDDH4aeZ8zLn7v2aA==/lib/arm64/libhello_ar_native.so (_ZNSt6__ndk114__thread_proxyINS_5tupleIJNS_10unique_ptrINS_15__thread_structENS_14default_deleteIS3_EEEEMN8hello_ar11VideoRenderEFvNS_12basic_stringIcNS_11char_traitsIcEENS_9allocatorIcEEEENS_10shared_ptrI12FrameManagerEEEPS8_SE_SH_EEEEEPvSM_+132)
#11 pc 0000000000084df8 /system/lib64/libc.so (__pthread_start(void*)+208)
#12 pc 0000000000023ac4 /system/lib64/libc.so (__start_thread+68)
编辑
LoadImage
方法
void FrameManager::LoadImage(std::string const & path)
{
std::ifstream file(path, std::ios::binary);
const int PKM_HEADER_SIZE = 16;
char pkmHeader[PKM_HEADER_SIZE];
file.read(pkmHeader, sizeof(pkmHeader));
std::string magicNumber = "";
magicNumber.append("" + ((char) pkmHeader[0]));
magicNumber.append("" + ((char) pkmHeader[1]));
magicNumber.append("" + ((char) pkmHeader[2]));
magicNumber.append("" + ((char) pkmHeader[3]));
m_image_width = ((int) pkmHeader[9]) | (((int) pkmHeader[8]) << 8);
m_image_height = ((int) pkmHeader[11]) | (((int) pkmHeader[10]) << 8);
const int BLOCK_DIM = 4;
const int BLOCK_PIXELS = BLOCK_DIM * BLOCK_DIM;
const int BLOCK_BITS = 64;
int size = (BLOCK_BITS / 8) * m_image_width * m_image_height /
(BLOCK_PIXELS);
m_imageData.resize(size);
int pos = 0;
while (size > 0)
{
file.read((char *) &m_imageData[pos], size);
pos += (int) file.gcount();
size -= (int) file.gcount();
}
file.close();
}
推荐答案
"" + ((char) pkmHeader[0])
是const char*
,因此(假设pkmHeader[0] == 'A'
). "" + ((char) pkmHeader[0])
的结果是指向(预分配的)""
常量的指针,该常量与该指针的偏移量为65
.对我来说,
"" + ((char) pkmHeader[0])
is a const char*
, and therefore std::string::append() can receive it. But the value of this const char*
is not "A"
(assuming that pkmHeader[0] == 'A'
). The result of "" + ((char) pkmHeader[0])
is a pointer to (preallocated) ""
constant with offset of 65
from that pointer. For me,
printf("%p %p\n", "", "" + ((char) 'A') );
打印:
0x7f3cbf201025 0x7f3cbf201066
请注意,0x7f3cbf201066 - 0x7f3cbf201025 = 0x41
是'A'的值.
Note that 0x7f3cbf201066 - 0x7f3cbf201025 = 0x41
, the value of 'A'.
要修复代码,请使用
magicNumber.append(pkmHeader, 4);
这篇关于在发布模式下崩溃,但是如果可调试为true,则为true-否...可能是什么问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!