Skip to content
This repository has been archived by the owner on Jan 25, 2023. It is now read-only.

Web samples using Sprite2D is broken #2784

Open
1vanK opened this issue Feb 23, 2021 · 15 comments
Open

Web samples using Sprite2D is broken #2784

1vanK opened this issue Feb 23, 2021 · 15 comments

Comments

@1vanK
Copy link
Contributor

1vanK commented Feb 23, 2021

https://urho3d.github.io/samples/

  • 33_Urho2DSpriterAnimation.as
  • 49_Urho2DIsometricDemo.as
  • 50_Urho2DPlatformer.as

Reproduсed in both Firefox and Chrome.

@1vanK
Copy link
Contributor Author

1vanK commented Feb 24, 2021

Last tested version:

Broken:

commit bae8f680ee58616dc38aa3042be5e8805badbf0b
Date:   Wed Nov 25 23:58:16 2020 +0300

    Fix twice applied gravity

Worked version not found

@1vanK 1vanK added the backlog label Feb 24, 2021
@1vanK
Copy link
Contributor Author

1vanK commented Feb 24, 2021

@SirNate0 as active Emscripten user can you finding the bug and when it arose? I cannot compile old versions of the engine with Emscripten on my Windows

@SirNate0
Copy link
Contributor

Sure, I'll try to find it.

@SirNate0
Copy link
Contributor

SirNate0 commented Feb 25, 2021

I'm not 100% certain, I'll try to check more later, but I don't think there was ever a working version. I'm pretty sure the issue is that the sprites used are for the Urho2D/imp are non-power-of-two textures, which WebGL is pretty strict about:

https://www.khronos.org/webgl/wiki/WebGL_and_OpenGL_Differences#Non-Power_of_Two_Texture_Support

Some related Issues/PRs:
#2534
#1776

@SirNate0
Copy link
Contributor

Okay, it is not from the non-power-of-two textures, or at least it is not just from that. I tried changing all the imp textures to being power-of-two sizes, but the imp is still not visible. I will keep looking, but it might be a few days as I'll be busy with other things.

While I am looking, I'll note that it's possible it has something to do with these warnings from FireFox:

WebGL warning: drawElementsInstanced: TEXTURE_2D at unit 0 is incomplete: Mipmapping requires power-of-two sizes. 50_Urho2DPlatformer.js:1:209727
WebGL warning: drawElementsInstanced: Tex image TEXTURE_2D level 0 is incurring lazy initialization.

@1vanK
Copy link
Contributor Author

1vanK commented Mar 8, 2021

Any news here?

@SirNate0
Copy link
Contributor

SirNate0 commented Mar 9, 2021

So, I haven't been able to get the older versions to build and run successfully (I don't know if I'm using too new a version of emscripten or if browsers did something that broke the old code - some of the old ones build but then crashes with something related to gamepads).

That said, I have found that it is an issue that occurs when the OpenGL context is lost and then reset. Unfortunately, this tends to happen relatively immediately, as the initial window size (on engine startup) and the actual canvas size don't tend to match, and when the size is corrected, the context is lost. If you resize the window to have content 1024x768 and reload the page on sample 33, you will see that the imp remains until you resize the window. (Tip: if you open the developer tools in Firefox/Chrome, it shows the size of the page when you resize it).

I'm not certain, but I think using an Image in bool AnimationSet2D::EndLoadSpriter() rather than setting the texture data directly, and then maybe storing that image in the resource cache, and using that Image to load the Texture2D would allow it to recover correctly. Or maybe adding an OnDeviceReset() to the AnimationSet2D.

@1vanK
Copy link
Contributor Author

1vanK commented Mar 9, 2021

Why desktop OpenGL build with scaled window have no this problem?

@eugeneko
Copy link
Contributor

eugeneko commented Mar 9, 2021

I can confirm that in order to keep your textures working in OpenGL you must either have source resource to be reloaded from cache, or reload data manually on device loss.

Why desktop OpenGL build with scaled window have no this problem?

@1vanK, desktop OpenGL build is just as broken -- you just have to toggle fullscreen instead of resizing.

@eugeneko
Copy link
Contributor

eugeneko commented Mar 9, 2021

My best bet is to subscribe to E_DEVICERESET in AnimationSet2D and somehow re-load stuff there. Either from scratch or keep Image cached.

@1vanK 1vanK added the баг label Dec 12, 2022
@1vanK
Copy link
Contributor Author

1vanK commented Dec 15, 2022

Прикол в том, что пропадает только главный персонаж. В то время как зеленые орки, которые тоже AnimatedSprite2D не пропадают

@1vanK
Copy link
Contributor Author

1vanK commented Dec 15, 2022

Пример 50_Urho2DPlatformer

Если в

Node* Sample2D::CreateCharacter(const TileMapInfo2D& info, float friction, const Vector3& position, float scale)
{
    ...

поменять

auto* animationSet = cache->GetResource<AnimationSet2D>("Urho2D/imp/imp.scml");

на

auto* animationSet = cache->GetResource<AnimationSet2D>("Urho2D/Orc/Orc.scml");

то главный персонаж в виде орка все так же бегает и сражается и при этом не пропадает

@1vanK
Copy link
Contributor Author

1vanK commented Dec 15, 2022

Предполагаю, что пропадают только те AnimatedSprite2D, которые используют набор текстур вместо атласа, так как монеты тоже пропадают

@1vanK
Copy link
Contributor Author

1vanK commented Dec 15, 2022

Когда текстур несколько, то создается атлас и он не кэшируется, а когда текстура одна, то она хранится как есть и она перезагружается как обычная Texture2D

@1vanK
Copy link
Contributor Author

1vanK commented Dec 15, 2022

В шрифтах тоже используется генерация атласа, но там вызывается IsDataLost для проверки, что требуется перегенерировать

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

3 participants