Browse Source

Merge pull request #992 from bitonator/MK-GETJSCOMPONENT-BUGFIX

Issue #991 getJSComponent fails if called immediately after createChildPrefab
JoshEngebretson 9 years ago
parent
commit
8d5792c448

+ 2 - 0
AUTHORS.md

@@ -39,6 +39,8 @@
 
 - Benjamin Wolf (https://github.com/Benwolf)
 
+- Mahadevan K (https://github.com/bitonator)
+
 ### Contribution Copyright and Licensing
 
 Atomic Game Engine contribution copyrights are held by their authors.  Each author retains the copyright to their contribution and agrees to irrevocably license the contribution under the Atomic Game Engine Contribution License `CONTRIBUTION_LICENSE.md`.  Please see `CONTRIBUTING.md` for more details.

+ 4 - 0
Source/AtomicJS/Javascript/JSComponent.cpp

@@ -161,6 +161,10 @@ void JSComponent::ApplyAttributes()
 {
 }
 
+bool JSComponent::IsInstanceInitialized() {
+    return instanceInitialized_;
+}
+
 void JSComponent::InitInstance(bool hasArgs, int argIdx)
 {
     if (context_->GetEditorContext() || componentFile_.Null())

+ 1 - 0
Source/AtomicJS/Javascript/JSComponent.h

@@ -78,6 +78,7 @@ public:
 
     void SetDestroyed() { destroyed_ = true; }
 
+    bool IsInstanceInitialized();	
     void InitInstance(bool hasArgs = false, int argIdx = 0);
 
     /// Get script attribute

+ 2 - 0
Source/AtomicJS/Javascript/JSScene.cpp

@@ -95,6 +95,8 @@ static int Node_GetJSComponent(duk_context* ctx)
     {
         JSComponent* component = components[i];
         if (component->MatchScriptName(path)) {
+            if(!component->IsInstanceInitialized())
+                component->InitInstance();
 
             js_push_class_object_instance(ctx, component, "Component");
             return 1;