Skip to content
This repository was archived by the owner on Aug 8, 2023. It is now read-only.
This repository was archived by the owner on Aug 8, 2023. It is now read-only.

setSprite does not handle scales <1.0x or >2.0x #2506

Closed

Description

@ljbade

As I discovered while working on #2440 the current core setSprite function is not flexible enough for the needs of Android. @friedbunny also noted that 3x needed for new iOS devices is also not supported.

The scale parameter crashes if you pass it <1.0 or >2.0. Android needs to support at least up to 4.0 (currently - future devices can increase this) and below 1.0.

A below 1.0 case might be where a developer only includes hdpi bitmaps assets, then a user runs the app on a ldpi or mdpi phone. In this case we need to scale down.

There are two ways I can see to fix this:

  • scale the Bitmap to the correct 1x or 2x sprite texture size using the CPU - will result in blurry markers on higher DPI devices
  • make sprites scale independent by storing them in their native resolution in the texture, then using the vertex shader to scale them on the CPU

/cc @1ec5 @incanus @kkaefer @nickidlugash @bleege @jfirebaugh

Activity

  1. added
    iOS
    Android
    on Oct 2, 2015
  2. added this to the android-v2.1.0 milestone on Oct 2, 2015
  3. ljbade commented on Oct 3, 2015

    @ljbade
    ContributorAuthor

    @bleege Until this bug is fixed I think in v2.1.0 and forwards we should make setSprite private. There could be big changes to the way this function works and I think it would be easier to not support for the moment. Developers can still use the Maki sprites from the styles just like Sirius does.

  4. ljbade commented on Oct 12, 2015

    @ljbade
    ContributorAuthor

    A workaround pending a Core GL refactor might be to override the Android platforms default Bitmap DPI selection and just force load a 1x or 2x sprite as required, essentially copying iOS.

    Can use getResources().getDrawableForDensity(id, density); for this. mdpi = 1x, xhdpi = 2x

  5. bleege commented on Oct 14, 2015

    @bleege
    Contributor

    Developers can still use the Maki sprites from the styles just like Sirius does.

    Just to clarify, that for Android this means loading a Style specific sprite from the sprite style sheet. For example, with Emerald style this means that the image has to be in https://github.com/mapbox/mapbox-gl-styles/blob/mb-pages/sprites/emerald.json.

  6. incanus commented on Oct 14, 2015

    @incanus
    Contributor

    No, this API is what the platform clients use to set runtime marker imagery, i.e. rasters as textures outside of the stock style resources.

  7. 1ec5 commented on Oct 14, 2015

    @1ec5
    Contributor

    I think the confusion is that the iOS SDK used to allow you to name a sprite from the style’s sprite sheet. That’s no longer the case and to my knowledge no longer supported by mbgl.

  8. bleege commented on Oct 14, 2015

    @bleege
    Contributor

    No, this API is what the platform clients use to set runtime marker imagery, i.e. rasters as textures outside of the stock style resources.

    Agreed @incanus. The confusion was around the statement that "Developers can still use the Maki sprites from the styles just like Sirius does." This means using Style Specific Sprites that are in the Style Sprite JSON Sheets and not Maki icons in their traditional sense.

  9. ljbade commented on Oct 14, 2015

    @ljbade
    ContributorAuthor

    @1ec5 Wait a minute, you mean iOS no longer allows you to specify a String as the sprite? It only allows loading from a provided Bitmap?

  10. 2 remaining items

  11. jfirebaugh commented on Oct 16, 2015

    @jfirebaugh
    Contributor

    @ljbade What scale parameter are you referring to? Can you link to code? Also, can you post a stack trace of the crash?

  12. ljbade commented on Oct 21, 2015

    @ljbade
    ContributorAuthor

    @jfirebaugh Sorry sprite is the parameter on the Java side.

    In C++ side it is the pixelRatio of SpriteImage class.

  13. ljbade commented on Oct 21, 2015

    @ljbade
    ContributorAuthor

    @jfirebaugh here is the stack trace:

    ********** Crash dump: **********
    Build fingerprint: 'samsung/zerofltedv/zeroflte:5.1.1/LMY47X/G920IDVU3DOJ6:user/release-keys'
    pid: 30046, tid: 30046, name: apboxgl.testapp  >>> com.mapbox.mapboxgl.testapp <<<
    signal 6 (SIGABRT), code -6 (SI_TKILL), fault addr --------
    Stack frame #00 pc 0003bfa8  /system/lib/libc.so (tgkill+12)
    Stack frame #01 pc 00017cf5  /system/lib/libc.so (pthread_kill+52)
    Stack frame #02 pc 00018907  /system/lib/libc.so (raise+10)
    Stack frame #03 pc 000151a5  /system/lib/libc.so (__libc_android_abort+36)
    Stack frame #04 pc 00012fec  /system/lib/libc.so (abort+4)
    Stack frame #05 pc 0044bb10  /data/app/com.mapbox.mapboxgl.testapp-2/lib/arm/libmapbox-gl.so: Routine abort_message at /tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/src/abort_message.cpp:47
    Stack frame #06 pc 0044bc40  /data/app/com.mapbox.mapboxgl.testapp-2/lib/arm/libmapbox-gl.so: Routine default_terminate_handler() at /tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/src/cxa_default_handlers.cpp:63
    Stack frame #07 pc 0043c298  /data/app/com.mapbox.mapboxgl.testapp-2/lib/arm/libmapbox-gl.so: Routine std::__terminate(void (*)()) at /tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/src/cxa_handlers.cpp:68
    Stack frame #08 pc 0043b4d4  /data/app/com.mapbox.mapboxgl.testapp-2/lib/arm/libmapbox-gl.so (__cxa_throw+240): Routine __cxxabiv1::failed_throw(__cxxabiv1::__cxa_exception*) at /tmp/ndk-user/tmp/build-libc++/ndk/sources/cxx-stl/llvm-libc++/../llvm-libc++abi/libcxxabi/src/cxa_exception.cpp:149
    Stack frame #09 pc 00203704  /data/app/com.mapbox.mapboxgl.testapp-2/lib/arm/libmapbox-gl.so (mbgl::SpriteImage::SpriteImage(unsigned short, unsigned short, float, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> >&&, bool)+300): Routine SpriteImage at /home/leith/mb/mapbox-gl-native/build/android-arm-v7/../../src/mbgl/annotation/sprite_image.cpp:25 (discriminator 1)
    Stack frame #10 pc 00120b08  /data/app/com.mapbox.mapboxgl.testapp-2/lib/arm/libmapbox-gl.so: Routine __libcpp_compressed_pair_imp<std::__1::allocator<mbgl::SpriteImage> &, unsigned short &&, unsigned short &&, float &&, std::__1::basic_string<char, std::__1::char_traits<char>, std::__1::allocator<char> > &&, 0, 0, 1, 2, 3> at /home/leith/mb/mapbox-gl-native/mason_packages/linux-x86_64/android-ndk/arm-9-r10e/bin/../lib/gcc/arm-linux-androideabi/4.9/../../../../include/c++/4.9/memory:2100
    Stack frame #11 pc 00138807  /data/dalvik-cache/arm/data@[email protected]@[email protected]
    
  14. ljbade commented on Oct 21, 2015

    @ljbade
    ContributorAuthor

    After looking closer at the crash log ^ I realised C++ was throwing an exception because the expected pixel data size, and actual size did not match.

    Turns out there was a bug in the JNI for setSprite.

    After fixing I now get the default sprite marker loading correctly:
    device-2015-10-21-225458

    Next steps are to refactor the Marker APIs to take Bitmaps (or perhaps a object to manage loaded sprites) instead of Strings.

    @friedbunny Seems to me like it should be possible to load iOS 3x bitmaps?

    /cc @bleege @jfirebaugh

  15. self-assigned this
    on Oct 21, 2015
  16. ljbade commented on Oct 21, 2015

    @ljbade
    ContributorAuthor

    The fix:
    e149fb8

  17. jfirebaugh commented on Oct 21, 2015

    @jfirebaugh
    Contributor

    @ljbade So can this be closed?

  18. ljbade commented on Oct 22, 2015

    @ljbade
    ContributorAuthor

    @jfirebaugh Once I get that branch merged. Currently waiting on 2.1.0 release branch to be merged into master.

  19. added a commit that references this issue on Oct 22, 2015
    2daa5f1
  20. added a commit that references this issue on Nov 6, 2015
    0daf004
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

AndroidiOSrefactor

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions