tzutalin / dlib-android

:dragon: Port dlib to Android
MIT License
868 stars 268 forks source link

demo failed, please help #35

Open laohuang112 opened 7 years ago

laohuang112 commented 7 years ago

In my demo project, invoke get_frontal_face_detector(); , when run, i will get the following error:

   terminate called after throwing an instance of 'std::ios_base::failure'
     what():  error occurred in compress_stream_kernel_1::decompress

I've checked the source code, in dlib/compress_stream/compress_stream_kernel_1.h,

if (out.sputc(static_cast<char>(symbol)) != static_cast<int>(symbol))
{ 
   throw std::ios::failure("error occurred in compress_stream_kernel_1::decompress"); 
}

I don't know the purpose of this code : out.sputc(static_cast(symbol)), sputc should change char to int, but when symbol equal or greater than 128, sputc will get a negtive signed char value. Then the demo running failed. The cross compiler is: arm-linux-gnueabi-gcc-4.7.1

But everything works fine in Ubuntu 14.04 x64, GCC 4.8.

How to fix it?

laohuang112 commented 7 years ago

Under arm linux, The symbol is decleared unsigned long in dlib/compress_stream/compress_stream_kernel_1.h,

        unsigned long symbol;
        unsigned long count = 0;

So, when I have the following code:

    symbol = 232;
    printf("%d\n",static_cast<char>(symbol));
    printf("%d\n",static_cast<int>(symbol));

Obviously, I should get the result: -24 232 Accoding to the source code of sputc,

      int_type 
      sputc(char_type __c)
      {
    int_type __ret;
    if (__builtin_expect(this->pptr() < this->epptr(), true))
      {
        *this->pptr() = __c;
        this->pbump(1);
        __ret = traits_type::to_int_type(__c);
      }
    else
      __ret = this->overflow(traits_type::to_int_type(__c));
    return __ret;
      }

So, out.sputc(static_cast(symbol), since symbol changed to char in the function, that's c = -24. c change to int , we get: -24 as return value. -24 != 232, that's why the error occured.

But, why this didn't happen under x64?