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

load* functions can't use callbacks in preload() #949

Closed
Jared-Sprague opened this issue Sep 29, 2015 · 5 comments
Closed

load* functions can't use callbacks in preload() #949

Jared-Sprague opened this issue Sep 29, 2015 · 5 comments

Comments

@Jared-Sprague
Copy link
Contributor

I know only load functions should be in preload(), but are success callbacks blocked by design too?

function preload() {  // preload() runs once
  img = loadImage('assets/laDefense.jpg', function() {console.log('loaded');});
}

// setup() will never run
@Jared-Sprague
Copy link
Contributor Author

I found the root cause of this bug. Almost done with a fix.

@lmccart
Copy link
Member

lmccart commented Sep 30, 2015

awesome, thanks for looking into it!

@Jared-Sprague
Copy link
Contributor Author

@lmccart See PR: #956

The problem was that the decrementPreload() function was getting pushed on the argument list for load functions in _wrapPreload and when no success callback was passed to the load function decrementCallback() was assumed to be in the position of the success callback, but when a callback was passed in, decrementPreload would never get called.

I added logic to the load functions to separate the success and failure callbacks from the decrementPreload function which will always be the last argment when in preload(). And an example to show it working.

NOTE: for failure callbacks, I don't decrementPreload, because I think we want it to stick on the "loading..." if a load function fails in preload() because it won't satisfy the contract that it will be guaranteed to be loaded.

@Jared-Sprague Jared-Sprague changed the title loadImage() with success callback hangs in preload() loadI* functions can't use callbacks in preload() Oct 1, 2015
@Jared-Sprague Jared-Sprague changed the title loadI* functions can't use callbacks in preload() load* functions can't use callbacks in preload() Oct 1, 2015
@Jared-Sprague
Copy link
Contributor Author

@lmccart I added a bunch of new unit tests for loadFont and loadImage that tests calling these functions in preload() with and without success callbacks. There was even a TODO in the font_loading.js unit test from @dhowe that said // TODO: actually test loading from within preload. Well now that's done!

I would have added more unit test but since all the other load functions use reqwest there is no way I know of to unit test them without having a dependancy on a running http server. Most of those are commented out because of this I think. The script I added to examples/ serve as a way to prove these work too.

Seems to be working great! Let me know what you think!

@Jared-Sprague
Copy link
Contributor Author

Pull request was merged so closing this. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants