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

Lazy initialization of ApplicationContext #24

Open
stoffera opened this issue Jul 18, 2017 · 0 comments
Open

Lazy initialization of ApplicationContext #24

stoffera opened this issue Jul 18, 2017 · 0 comments
Assignees
Milestone

Comments

@stoffera
Copy link
Contributor

This is an issue that was raised in #20

Problem

User objects defined in C++ global space might cause the system to crash, by dereferencing null pointers.

Background

The global object ApplicationContext is defined in C++ global space. This means it is initialized by the language runtime. Especially Arduino SDK needs to declare user interface objects in global space, that depends on an initialized ApplicationContext. However, C++ (or C) runtime does not guarantee any order of of object initialization.

Solution

Currently the singleton ApplicationContext is obtained by the static member variable of the context interface:

mono::IApplicationContext::Instance

Here Instance is the stat9c member of the interface. The member is null until the global app. context is constructed by the C++ runtime.

We should reference the app. context by using a function - not a member variable. Instead this function will create and return, or later just return the global ApplicationContext. Then, to get a reference to the context you could do this:

mono::IApplicationContext::get()
@stoffera stoffera self-assigned this Jul 18, 2017
@stoffera stoffera added this to the 2.0 milestone Jul 18, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant