-
-
Notifications
You must be signed in to change notification settings - Fork 3.4k
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
Warning being logged in Safari when using a filter shader in 2D mode #6597
Comments
Hi! @davepagurek |
Hi @deveshidwivedi! The reason we don't use |
Thanks for the clarification! |
Ahh I see, so to summarize, in other browsers, A heavier solution for this could be to stop parsing the stack trace, but instead wrap every top-level function call in a decorator like this, that counts how nested we are: let nesting = 0
function topLevelCall(method) {
return function(...args) {
nesting++;
try {
method.apply(this, args);
} finally {
nesting--;
}
};
}
// Usage:
p5.prototype.createFilterShader = topLevelCall(function(vert, frag) {
// ...
}) Then in FES, you can only log an error if |
Yeah that makes more sense. Maybe a validateParameter wrapper which will validate the arguments and if a warning is logged will set a global variable which will be used to decide if error should be logged or not functions and on completion of execution of the function inside the wrapper the flag can be reset. function validateParameterWrap(method) {
return function (...args) {
p5.errorLogged = _validateParams(method, arguments);
method.apply(this, args);
p5.erroLogged = false;
}
}
p5.prototype.createFilterShader = validateParameterWrap(function(vert, frag) This can also be set as a decorator, based on this article a babel plugin can be used for that. https://blog.logrocket.com/understanding-javascript-decorators/ Just brainstorming. |
One small update to the code, I think it'd need to also pass the name: p5.prototype.createFilterShader = validateParameterWrap('createFilterShader', function(vert, frag) { ... })) I think combining the logging logic + validating parameters would make sense. I think the implementation would still need to have a nesting count in order to know whether or not the error should be logged though? @limzykenneth you've also looked into this a bit in the past, what do you think of this approach? |
Aplogies for the delay in response. Yeah I guess nesting count will be required. I was considering of using something like a lock variable which can only be set and reset by the top level function after calling _validateParams, but keeping a nesting count seems like a better and a straightforward approach. |
Sorry took a bit of time to get to this. @rohanjulka19 Very good investigative work to find this and a proposed implementation. I like this general idea with the What I'm thinking about right now is how to possibly make the footprint smaller as with the current proposed implementation, all functions will need to be wrapped by // Similar implementation as above
function validateParameterWrap(method) {
return function (...args) {
// Checks to see if `method` is a function and support parameter validation?
p5.errorLogged = _validateParams(method, arguments);
method.apply(this, args);
p5.erroLogged = false;
}
}
// Somewhere else once only
// Need to double check this for loop can actually work
for(const [name, member] of Object.entries(p5)){
validateParameterWrap(name, member);
} To make this also available to external libraries, the |
Most appropriate sub-area of p5.js?
p5.js version
1.9.0
Web browser and version
Safari 17.0
Operating System
MacOS 14
Steps to reproduce this
Steps:
createFilterShader
On safari this warning gets logged:
Weirdly, this doesn't happen in Chrome/Firefox, but honestly I'm not sure why it doesn't. It seems to be happening because when we call
copy()
to copy the 2D mode contents to the filter graphic, we're passing in thep5.Renderer2D
as the source:p5.js/src/image/pixels.js
Line 602 in 37d3324
Technically we do not validate
p5.Renderer
as a valid input fortexture
. Maybe we should?Snippet:
See the bouncing balls section of this sketch: https://openprocessing.org/sketch/2107682
The text was updated successfully, but these errors were encountered: