question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Minified OBJLoader2 Async fails on building worker code

See original GitHub issue

When OBJLoader2 is used async it builds the worker code by building up a string and passing it to the worker. Unfortunately some of the string is hard coded. That means that when it is minified (as all of my code is when I deploy) the strings aren’t the correct class/variable name any more.

In the following code you can see that LoaderSupport is hard-coded (eg. var LoaderSupport) but the Parser class definition has been minified, so where it should say LoaderSupport.Validator in prototype.setMaterials it says mh.Validator instead. I can’t think of a good way to handle this. Any ideas???

    var LoaderSupport = {};

    LoaderSupport.Validator = {
	    isValid: function(e){return null!==e&&void 0!==e},
	    verifyInput: function(e,t){return null===e||void 0===e?t:e},
    }

    Parser = (function () {

	function e(){this.callbackProgress=null,this.callbackMeshBuilder=null,this.contentRef=null,this.legacyMode=!1,this.materials={},this.useAsync=!1,this.materialPerSmoothingGroup=!1,this.useIndices=!1,this.disregardNormals=!1,this.vertices=[],this.colors=[],this.normals=[],this.uvs=[],this.rawMesh={objectName:"",groupName:"",activeMtlName:"",mtllibName:"",faceType:-1,subGroups:[],subGroupInUse:null,smoothingGroup:{splitMaterials:!1,normalized:-1,real:-1},counts:{doubleIndicesCount:0,faceCount:0,mtlCount:0,smoothingGroupCount:0}},this.inputObjectCount=1,this.outputObjectCount=1,this.globalCounts={vertices:0,faces:0,doubleIndicesCount:0,lineByte:0,currentByte:0,totalBytes:0},this.logging={enabled:!0,debug:!1}}

	e.prototype.resetRawMesh = function(){this.rawMesh.subGroups=[],this.rawMesh.subGroupInUse=null,this.rawMesh.smoothingGroup.normalized=-1,this.rawMesh.smoothingGroup.real=-1,this.pushSmoothingGroup(1),this.rawMesh.counts.doubleIndicesCount=0,this.rawMesh.counts.faceCount=0,this.rawMesh.counts.mtlCount=0,this.rawMesh.counts.smoothingGroupCount=0};

	e.prototype.setUseAsync = function(e){this.useAsync=e};

	e.prototype.setMaterialPerSmoothingGroup = function(e){this.materialPerSmoothingGroup=e};

	e.prototype.setUseIndices = function(e){this.useIndices=e};

	e.prototype.setDisregardNormals = function(e){this.disregardNormals=e};

	e.prototype.setMaterials = function(e){this.materials=mh.Validator.verifyInput(e,this.materials),this.materials=mh.Validator.verifyInput(this.materials,{})};

	e.prototype.setCallbackMeshBuilder = function(e){if(!mh.Validator.isValid(e))throw'Unable to run as no "MeshBuilder" callback is set.';this.callbackMeshBuilder=e};

	e.prototype.setCallbackProgress = function(e){this.callbackProgress=e};

And just for reference, here is the code that is causing the problem (the build worker code):

      var buildCode = function(funcBuildObject, funcBuildSingleton) {
            var workerCode = '';
            workerCode += '\n\n';
            workerCode += 'var LoaderSupport = {};\n\n';
            workerCode += funcBuildObject('LoaderSupport.Validator', Validator);
            workerCode += funcBuildSingleton('Parser', Parser);
            return workerCode;
      };
      this.workerSupport.validate(buildCode, 'Parser');
      this.workerSupport.setCallbacks(scopedOnMeshLoaded, scopedOnLoad);
      if (scope.terminateWorkerOnLoad) { this.workerSupport.setTerminateRequested(true); }

edit: add javascript tag to code

Issue Analytics

  • State:closed
  • Created 5 years ago
  • Comments:20 (8 by maintainers)

github_iconTop GitHub Comments

1reaction
Iteecommented, Sep 5, 2018

I will take a look deeper on this case but… i think this is a bug for three js library not this converter.

I aware that this “bug” appear due to the es6 portage of OBJLoader2, but unfortunately i’m not able to determine what will be the minimified version of such code…

Currently the best thing to do could be a manual find an replace against var LoaderSupport with the minimified version of it.

0reactions
mrz5018commented, Dec 7, 2018

@Itee Any updates?

Read more comments on GitHub >

github_iconTop Results From Across the Web

Functioning code no longer working after being minified and ...
I have some code in a web worker that is working perfectly locally, but as soon as I build and deploy (which minifies...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found