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

Error: Width and height must be set prior to rendering #109

Open
ghost opened this issue Apr 10, 2020 · 4 comments
Open

Error: Width and height must be set prior to rendering #109

ghost opened this issue Apr 10, 2020 · 4 comments

Comments

@ghost
Copy link

ghost commented Apr 10, 2020

I get this error with p5.js.

<script src="CCapture.all.min.js"></script>

<script>
		var capturer = new CCapture( {
			 format: 'gif', 
			 workersPath: 'js/gif.worker.js',
		} );

                var width = 300;
		var height = 500;

		function setup () {
			p5canvas = createCanvas(width,height);
		}
               function draw () {
               // code
               		if (frameCount === 0)  capturer.start();
			
			if (frameCount <= 100) {
				capturer.capture(p5canvas);
				console.log(frameCount);
			} else {
				capturer.stop();
				capturer.save();
			}
               }
Error: Width and height must be set prior to rendering CCapture.all.min.js:1:16873
    render file:///C:/Users/admin/Documents/Cubase Projects/Untitled-31/Video/CCapture.all.min.js:1
    save file:///C:/Users/admin/Documents/Cubase Projects/Untitled-31/Video/CCapture.all.min.js:2
    v file:///C:/Users/admin/Documents/Cubase Projects/Untitled-31/Video/CCapture.all.min.js:1
    draw file:///C:/Users/admin/Documents/Cubase Projects/Untitled-31/Video/index.html:66
    redraw file:///C:/Users/admin/Documents/Cubase Projects/Untitled-31/Video/p5.min.js:3
    _draw file:///C:/Users/admin/Documents/Cubase Projects/Untitled-31/Video/p5.min.js:3
@ghost
Copy link
Author

ghost commented Apr 10, 2020

I couldn't make the right debuggin, but I can confirm everything works fine. With p5.js v1
In my sketch there are many mistakes, wrong canvas DOM element for capturer, wrong if-esle condition, etc etc. I double-checked everything and finally made it work.

@latostadorano
Copy link

I have that error too, I changed the code as it is here and i'm still having it..

@AlexZ005
Copy link

AlexZ005 commented Sep 17, 2021

You probably need to add render function to the code and call it in the setup function, for example:
function render(){
requestAnimationFrame(render);
// rendering stuff ...
capturer.capture( p5canvas );
}
function setup(){
render()
...
}

@otse
Copy link

otse commented Aug 4, 2022

What is the solution for this?

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

3 participants