Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

MLNStyleLayerDrawingContext not available #2099

Closed
bsudekum opened this issue Feb 11, 2024 · 14 comments
Closed

MLNStyleLayerDrawingContext not available #2099

bsudekum opened this issue Feb 11, 2024 · 14 comments
Labels
bug Something isn't working iOS

Comments

@bsudekum
Copy link
Contributor

bsudekum commented Feb 11, 2024

Describe the bug
A clear and concise description of what the bug is.

To Reproduce
Steps to reproduce the behavior:

  1. Checkout the branch MLNCustomStyleLayer + Metal example #2041
  2. Import MapLibre into a Swift file
  3. Create a simple layer which subclasses MGLOpenGLStyleLayer
final class MyLayer: MLNCustomStyleLayer {
    override func draw(in mapView: MGLMapView, with context: MGLStyleLayerDrawingContext) {
        super.draw(in: mapView, with: context)
        /// do stuff
    }
}
  1. Compile
  2. An error is thrown
....swift:18:61: error: cannot find type 'MLNStyleLayerDrawingContext' in scope
   override func draw(in mapView: MLNMapView, with context: MLNStyleLayerDrawingContext) {
                                                            ^~~~~~~~~~~~~~~~~~~~~~~~~~~
external/MapLibre/MapLibre.xcframework/ios-arm64_x86_64-simulator/MapLibre.framework/Headers/MLNCustomStyleLayer.h:19:16: note: record 'MLNStyleLayerDrawingContext' is not trivial to copy or destroy
typedef struct MLNStyleLayerDrawingContext {
               ^
....swift:18:18: error: method does not override any method from its superclass
   override func draw(in mapView: MLNMapView, with context: MLNStyleLayerDrawingContext) {
   ~~~~~~~~      ^
....swift:19:14: error: value of type 'MLNCustomStyleLayer' has no member 'draw'
       super.draw(in: mapView, with: context)
       ~~~~~ ^~~~
external/MapLibre/MapLibre.xcframework/ios-arm64_x86_64-simulator/MapLibre.framework/Headers/MLNCustomStyleLayer.h:52:1: note: method 'drawInMapView:withContext:' unavailable (cannot import)
- (void)drawInMapView:(MLNMapView *)mapView withContext:(MLNStyleLayerDrawingContext)context;
^
external/MapLibre/MapLibre.xcframework/ios-arm64_x86_64-simulator/MapLibre.framework/Headers/MLNCustomStyleLayer.h:52:58: note: parameter 'context' unavailable (cannot import)
- (void)drawInMapView:(MLNMapView *)mapView withContext:(MLNStyleLayerDrawingContext)context;

I think the note: record... record bit is a good clue. I'm wondering if this is not available in Swift, rendering the whole struct (MLNStyleLayerDrawingContext) invalid:

#if MLN_RENDER_BACKEND_METAL
id<MTLRenderCommandEncoder> renderEncoder;
#endif

@bsudekum bsudekum added the bug Something isn't working label Feb 11, 2024
@louwers
Copy link
Collaborator

louwers commented Feb 11, 2024

Note that OpenGL ES is no longer supported on iOS since the 6.0.0 release.

For development of the Metal renderer, OpenGL was kept around, but we'll be moving towards removing it completely from the iOS sources.

@bsudekum
Copy link
Contributor Author

Understood, I'm compiling with the metal flag here.

@louwers
Copy link
Collaborator

louwers commented Feb 11, 2024

Isn't it named MLNCustomStyleLayer on that branch?

@bsudekum
Copy link
Contributor Author

Sorry, copied old file, updated.

@louwers louwers added the iOS label Feb 11, 2024
@louwers
Copy link
Collaborator

louwers commented Feb 11, 2024

Yeah this might be a limitation of Swift's Objective-C interoperability.

Thanks for trying it out. Could you remove the renderEncoder field from the struct and see if it compiles?

@bsudekum
Copy link
Contributor Author

@louwers yep that did the trick.

@louwers
Copy link
Collaborator

louwers commented Feb 11, 2024

@bsudekum OK maybe @stefankarschti can think of a Swift-compatible interface.

@stefankarschti
Copy link
Collaborator

I added renderEncoder as a property. Please retry
image

@bsudekum
Copy link
Contributor Author

@stefankarschti it works! thanks for working through this.

@bsudekum
Copy link
Contributor Author

@stefankarschti found a slight bug. With the above code, there is a pretty massive memory leak if you just simulate the highway drive:

image

@stefankarschti
Copy link
Collaborator

stefankarschti commented Feb 13, 2024

Yep, that's on me 😄
Thanks for testing, please retry now.

@bsudekum
Copy link
Contributor Author

@stefankarschti cool that worked!

@louwers louwers closed this as completed Feb 13, 2024
@thothai94
Copy link

Understood, I'm compiling with the metal flag here.

Could you please tell me how to set compiling with metal flag in iOS project?
In my case, #if MLN_RENDER_BACKEND_METAL check statement always return false

@louwers
Copy link
Collaborator

louwers commented Mar 4, 2024

Please create a new Discussion or Issue for unrelated problems.

@thothai94 But you can generate the Xcode project with:

bazel run //platform/ios:xcodeproj --@rules_xcodeproj//xcodeproj:extra_common_flags="--//:renderer=metal"

https://github.com/maplibre/maplibre-native/blob/main/platform/ios/README.md#developing

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working iOS
Projects
None yet
Development

No branches or pull requests

4 participants