Skip to content

Pattern for interacting with the main thread #42

@jlongster

Description

@jlongster

I exported a function on my controller:

- (void)loadMesh:(NSString *)path {
    RCT_EXPORT();
    node.mesh = [REMeshCache meshNamed:path];
}

This is called when selecting an item from a list:

var controller = require('NativeModules').TeapotController;

// ....

selectModel: function(file) {
  controller.loadMesh(file);
},

I've been trying to debug why OpenGL crashes, and I finally realized that my OpenGL context doesn't exist. Which made me realize that this method in Obj-C is not running on the main thread. It's running in a different thread which all calls into Obj-C seem to run on.

I'm not familiar with iOS, so this is over my head. Is there a simple pattern I can use to interact with the main thread? How do I send a message to it?

I realize this not usually needed, and most custom native modules can probably be run standalone, but I'm basically implementing a custom view that needs to render on the main thread (not technically true, just a custom controller to a normal view, but still).

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions