flame-engine / flame

A Flutter based game engine.
https://flame-engine.org
MIT License
9.29k stars 913 forks source link

Prevent methods that can't be called on web to crash the game #361

Closed erickzanardo closed 4 years ago

erickzanardo commented 4 years ago

There are some methods, like Flame.util.fullScreen that catastrophically crashes the game.

I think we should or do nothing when the method is called and is web, or throw a better message.

spydon commented 4 years ago

Is it possible to know the context from within the methods, whether it is in web or not? Then we could maybe just make those methods a no-op when they are called from a web context.

erickzanardo commented 4 years ago

It sure is, on the foundation lib there is a variable called kIsWeb.

I just wonder if we should just do nothing on this methods like you said, or to make an assert with a meaningful message

spydon commented 4 years ago

I think we should do nothing in that case but write a warning log message, so that people can easily run their app on web with the same code.

luanpotter commented 4 years ago

I just use kIsWeb on my games, eg (from GW):

  if (!kIsWeb) {
    if (debugDefaultTargetPlatformOverride != TargetPlatform.fuchsia) {
      await Flame.util.setLandscape();
    }
    await Flame.util.fullScreen();
  }
erickzanardo commented 4 years ago

I just use kIsWeb on my games, eg (from GW):


  if (!kIsWeb) {

    if (debugDefaultTargetPlatformOverride != TargetPlatform.fuchsia) {

      await Flame.util.setLandscape();

    }

    await Flame.util.fullScreen();

  }

So do I, the point here is to make these methods of Flame do not crash the game without any message/warning, which is what happens today

d-apps commented 4 years ago

We cannot preload audios too when running on web or it crashes, it overflows the path_provider channel.

Overflow on channel: plugins.flutter.io/path_provider. Messages on this channel are being discarded in FIFO fashion. The engine may not be running or you need to adjust the buffer size if of the channel.

To prevent this just use kIsWeb to check if it's running on web.

if(!kIsWeb){
    await Flame.audio.loadAll(
        [

         ...

        ]
    );
  }
erickzanardo commented 4 years ago

Fixed on #427, will be shipped on 0.25.0