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

Device crashes when <Svg> is too wide #1302

Closed
caminoninja opened this issue Mar 3, 2020 · 22 comments
Closed

Device crashes when <Svg> is too wide #1302

caminoninja opened this issue Mar 3, 2020 · 22 comments

Comments

@caminoninja
Copy link

Bug

Device crashes when is too wide

Unexpected behavior

<Svg width="21489" >

Above code crashes using Expo on my Nokia 9 PureView.

Works fine on iPhone simulator.

Best,
Andy

@msand
Copy link
Collaborator

msand commented Mar 4, 2020

This would probably happen even in a native android java app, if you tried to create a bitmap of that width on that device, and nothing else, in similar memory conditions. Would probably be better not to crash though. Mind making a pr?

@caminoninja
Copy link
Author

It actually fails at 3400. What is a pr?

@caminoninja
Copy link
Author

caminoninja commented Mar 4, 2020

@msand not failing would be an upgrade. I got it in a thread over here at Expo:
https://forums.expo.io/t/svg-fails-when-width-is-high/34078/14

If it would be possible to select either trimming down to a certain width, height or proportional size it would be even nicer. Cant really handle those errors in Expo ...as far as I know.

Best,
Andy

@msand
Copy link
Collaborator

msand commented Mar 4, 2020

A pr is a pull request, i.e. a request to merge a proposed fix for the issue. I don't think it makes sense to render anything at all if the request memory is unavailable. Logging an error of some sort probably makes sense, ideally some catchable error event such that the author can decide how to handle that there is not enough memory on the device.

@caminoninja
Copy link
Author

Well yeah it's a Android problem. But am surprised it is drawing bitmaps and also not internally being able to cache instead of throwing errors. Not sure how errors could be handled gracefully in this context though if not drawing anything.

@caminoninja
Copy link
Author

I really do not think I have enough knowledge about the underlying structures to suggest a Pull Request. But this should be handled in a more gracefull way. I almost consider this one useless as is. And really, I know you can blame Android for their poor implementation, but also errors can be handled in this project but not in projects using this project.

@msand
Copy link
Collaborator

msand commented Mar 5, 2020

I'm not sure what you mean, isn't the issue that you're trying to make an svg which is several times larger than the screen, even so large that it wont even fit in memory, the main issue? Why would you even need a bitmap much larger than the screen? Seems more like a bug in your use of svg rather than something that could even in theory be fixed, at best it can not render at all and throw an exception / call an error handler. Do you expect it to expand the amount of hardware inside the device when you request to allocate too much?

@caminoninja
Copy link
Author

I do not considder it an issue that I'm making an Elevation Chart that scrolls sideways and are bigger than the screen size. I consider it an issue that the component crashes the system on Android if for whatever unknown issue it is not able to handle it. iPhone do not have a problem drawing it.

It is not a bug in the use of the SVG. The problem only exists on Android, because the way Android implements it, and the component layer is not handling it garcefully.

@msand
Copy link
Collaborator

msand commented Mar 5, 2020

I recommend you study how memory and bitmaps work, and how the amount of memory, not the os, is the deciding factor.

@msand
Copy link
Collaborator

msand commented Mar 5, 2020

You can certainly make it bigger than the screen, but not bigger than available memory.

@msand
Copy link
Collaborator

msand commented Mar 5, 2020

Anyway, you're doing it wrong. I'm informing you this as the maintainer of the lib. Ignore at your own peril.

@caminoninja
Copy link
Author

I did study how the memory works on Android and they have a 100 MB limit on bitmaps. It might crash before the 100 MB though. I can currently make it 5 times bigger than the screen on Nikia 9 PureView.

But is it not possible to make a pure vector based implementation on Android? It would most likely save a lot of memory.

@msand
Copy link
Collaborator

msand commented Mar 5, 2020

And yes, trying to do what you want the way you are is as you say "useless", not supported, and most likely never will be. Use a screen sized bitmap, and transform the content instead, or split it into smaller pieces and use a flatlist or something.

@caminoninja
Copy link
Author

I think I'll try spending my time on Flutter instead. Seems like they have better vector support.

@msand
Copy link
Collaborator

msand commented Mar 5, 2020

Good

@caminoninja
Copy link
Author

If I get you right, I should just make one big Svg on iPhone and on Android I should make a lot of small ones and make something like a ScrollView? That's the right way to use Svg according to you?

I think that shold be handled in the Svg component. But as you think it is a mistake to make big Svg's I'm pretty sure that is not going to happen. Right?

@msand
Copy link
Collaborator

msand commented Mar 6, 2020

No, use a single svg view, the size of the screen, have infinite content inside, use transforms to move it around.

@msand
Copy link
Collaborator

msand commented Mar 6, 2020

Only if you insist on rendering lots of pixels offscreen you could make several views, I don't know how or when that would make sense though, but if you insist on rendering more content than the user can see, and spending battery on that, you can draw as many redundant pixels as the device restrictions allow you to.

@msand
Copy link
Collaborator

msand commented Mar 6, 2020

Alternatively if you want to oversample the rendering it might make sense, but seems mostly reasonable for creating png:s for display on larger screens. It wont make the rendering on the phone any higher resolution than the actual screen anyway. I see no good reason for having much larger bitmap than screen size. Why would you sacrifice the user experience that way? Would just make almost everything take much longer.

@msand msand closed this as completed Mar 8, 2020
@macfanatic
Copy link

I was surpised to see that using this library with expo that an SVG size of over about 1200x1200 causes an app crash immediately, and doesn't cause that issue in the emulator for android, nor for iOS (device or simulator).

I appreciate the discussion above, but I'm just as lost on how to best achieve my goal of offering lines drawn on mobile atop a background image, that stay in position. My only idea at the moment is adjusting the viewBox attribute itself on the SVG element, so that the width of the SVG is pretty small, but the viewbox is larger.

I'd appreciate any insight, however trivial or small.

@brookemitchell
Copy link

@mrousavy Have a look at comment: #926 (comment) . The solution is to have the svg be at most the size of device view, and transform the content in response to touch.

There is also a good example from msand that sounds like your desired use case of lines atop an image linked to here: #573 (comment) in the Soundcloud player example

@caminoninja
Copy link
Author

@mrousavy Have a look at comment: #926 (comment) . The solution is to have the svg be at most the size of device view, and transform the content in response to touch.

There is also a good example from msand that sounds like your desired use case of lines atop an image linked to here: #573 (comment) in the Soundcloud player example

I ended up just using a WebView and adding a SVG to that. Works like a charm.

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

4 participants