diff --git a/include/emp/web/Attributes.hpp b/include/emp/web/Attributes.hpp index 30e34dc7e..dd4cab39c 100644 --- a/include/emp/web/Attributes.hpp +++ b/include/emp/web/Attributes.hpp @@ -118,7 +118,7 @@ namespace web { MAIN_THREAD_EM_ASM({ var name = UTF8ToString($0); var value = UTF8ToString($1); - emp_i.cur_obj.setAttribute(name, value); + if (emp_i.cur_obj) emp_i.cur_obj.setAttribute(name, value); }, attr_pair.first.c_str(), attr_pair.second.c_str()); #else std::cout << "Setting '" << widget_id << "' attribute '" << attr_pair.first diff --git a/include/emp/web/Listeners.hpp b/include/emp/web/Listeners.hpp index 22798c9d2..e97bc5e63 100644 --- a/include/emp/web/Listeners.hpp +++ b/include/emp/web/Listeners.hpp @@ -95,7 +95,7 @@ namespace web { #ifdef __EMSCRIPTEN__ MAIN_THREAD_EM_ASM({ var name = UTF8ToString($0); - emp_i.cur_obj.addEventListener(name, function(evt) { + if (emp_i.cur_obj) emp_i.cur_obj.addEventListener(name, function(evt) { emp.Callback($1, evt); }); }, event_pair.first.c_str(), event_pair.second); diff --git a/include/emp/web/Style.hpp b/include/emp/web/Style.hpp index 2e41370d6..45fe95940 100644 --- a/include/emp/web/Style.hpp +++ b/include/emp/web/Style.hpp @@ -122,7 +122,7 @@ namespace web { MAIN_THREAD_EM_ASM({ var name = UTF8ToString($0); var value = UTF8ToString($1); - emp_i.cur_obj.style[name] = value; + if (emp_i.cur_obj) emp_i.cur_obj.style[name] = value; }, css_pair.first.c_str(), css_pair.second.c_str()); #else std::cout << "Setting '" << widget_id << "' attribute '" << css_pair.first @@ -135,7 +135,7 @@ namespace web { #ifdef EMSCRIPTEN EM_ASM_ARGS({ var name = UTF8ToString($0); - emp_i.cur_obj.addClass( name ); + if (emp_i.cur_obj) emp_i.cur_obj.classList.add(name); }, class_.c_str()); #else std::cout << "Adding class to '" << widget_id << "': '" << class_;