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

Nothing drawn on canvas #33

Closed
Mwni opened this issue Apr 29, 2021 · 18 comments
Closed

Nothing drawn on canvas #33

Mwni opened this issue Apr 29, 2021 · 18 comments
Labels
Android bug Something isn't working Canvas

Comments

@Mwni
Copy link

Mwni commented Apr 29, 2021

What could be the cause for the canvas remaining blank after calling draw functions? The setup is the core example given in the readme.

  • xmlns:canvas set on page tag
  • canvas is there, its bounds push other content lower
  • ready event fires and the canvas aswell as the ctx of the event are present

This is on Android emulator, I will try iOS tomorrow.

@triniwiz
Copy link
Member

Can you try wrapping the draw call in a setTimeout on android ? 🤔

@Mwni
Copy link
Author

Mwni commented Apr 29, 2021

I did, to no avail

@Mwni
Copy link
Author

Mwni commented Apr 29, 2021

Do I need to somehow install the native code for android? I ran ns plugin add @nativescript/canvas to install, sufficient?

@Mwni
Copy link
Author

Mwni commented Apr 29, 2021

For iOS I sadly cannot test it because:
None of your spec sources contain a spec satisfying the dependency: CanvasNative (~> 0.9.19)
Do I need to compile the pod myself?

@triniwiz
Copy link
Member

@Mwni fixed iOS there was plans to release a new pod but sadly I did not so the package had the wrong version update to 0.9.21 as for android I will fix also can you try webgl an lmk if it draws

let gl;
let canvas;
export function canvasReady(args) {
	console.log('canvas ready');
	canvas = args.object;
	gl = canvas.getContext('webgl'); // 'webgl' || 'webgl2'
	gl.viewport(0, 0, gl.drawingBufferWidth, gl.drawingBufferHeight);
	// Set the clear color to darkish green.
	gl.clearColor(0.0, 0.5, 0.0, 1.0);
	// Clear the context with the newly set color. This is
	// the function call that actually does the drawing.
	gl.clear(gl.COLOR_BUFFER_BIT);
}

@Mwni
Copy link
Author

Mwni commented Apr 29, 2021

The pod version 0.9.21 was not available, but 0.9.18 was, so the install worked, and the canvas did draw on iOS. Just as well did the WebGL context on android. So this could come down to some niche bug regarding my specific environment (Windows 7 Android emulator). triniwiz, thank you for looking into this. At this point I am perfectly able to continue developing my app.

@triniwiz
Copy link
Member

Okay so the gl context drew fine on both platforms ? Then it would be on my end to fix for android also that package version is the npm package not a pod

@Mwni
Copy link
Author

Mwni commented Apr 29, 2021

Yes, gl worked fine. For 2d context on android, I have not tested it on an actual android device, I will let you know once I have, but I'm assuming it will work there. On a tangent, I did not find where I can specifically fund this development, would it be through the OpenJS foundation?

@triniwiz
Copy link
Member

You can fund it through github sponsors or opencollective

@triniwiz triniwiz added Android bug Something isn't working Canvas labels May 10, 2021
@JacobFJ
Copy link

JacobFJ commented Jun 7, 2021

@triniwiz For android it working 2d but the canvas is broken layout it look like I draw a circle the result is cicle with broken it look like house tiles

@triniwiz
Copy link
Member

triniwiz commented Jun 7, 2021

@HakobiDev can you share a screenshot please

@OzymandiasTheGreat
Copy link

Re: rendering broken on Android. Here's the screenshot
Screenshot_20210616-052337_canvasbug

And here's the code behind that view

onReady(event: any): void {
    const canvas: Canvas = event.object;
    const ctx = <CanvasRenderingContext2D> canvas.getContext('2d');
    ctx.beginPath();
    ctx.moveTo(75, 50);
    ctx.lineTo(100, 75);
    ctx.lineTo(100, 25);
    ctx.scale(0.3, 0.5);
    ctx.fill();
  }

The white part is normally noise, but I have a non-attached canvas with a white background created as well and it somehow crosses over into the displayed canvas.

Sorry, if I should've opened a new issue, it's just that the last comment is describing this exact issue I think.

Oh and also, nativescript is version 8.0.2. Everything's as up to date as possible.

@triniwiz
Copy link
Member

Can you try updating to the latest alpha tag , also I added a new property to help with scaling ignorePixelScaling="true" you can also try it

@JacobFJ
Copy link

JacobFJ commented Jul 13, 2021

@triniwiz thanks! I will also check it out.

@OzymandiasTheGreat
Copy link

Just tried the latest alpha. The rendering is still broken. Noise is now replaced by black squares and it still tiles for some reason rather than displaying drawn image normally.

@triniwiz
Copy link
Member

triniwiz commented Aug 2, 2021

@OzymandiasTheGreat real device or emulator ?

@OzymandiasTheGreat
Copy link

Real device running android 10. My machine doesn't handle the emulator well.

@triniwiz
Copy link
Member

triniwiz commented Mar 9, 2022

Please try with the latest , reopen if the issue still persists

@triniwiz triniwiz closed this as completed Mar 9, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Android bug Something isn't working Canvas
Projects
None yet
Development

No branches or pull requests

4 participants