UnityMarkdownViewer icon indicating copy to clipboard operation
UnityMarkdownViewer copied to clipboard

(BUG) Sometimes does not render document contents when selecting another text asset

Open kaygeecee opened this issue 3 years ago • 7 comments

Thanks for creating this asset! It's a lot more sexy than the default text document renderer that ships with Unity ❤

It seems that after rendering a markdown document, if you select a new markdown document (no matter what other markdown document it is), the document rendering fails. So if you are tapping the arrow keys to browse through your markdown files, you'd experience alternating "working/not working" document rendering as you browse through the files. I've added steps to reproduce below :)

Steps to reproduce:

  1. Click markdown file. Observe: Renders as expected. image

  2. Press up arrow or click the markdown file above it in the Project window. Observe: Does not render document contents. image

  3. Press up arrow or click the markdown file above it in the Project window. Observe: Renders as expected. image

  4. Press up arrow or click the markdown file above it in the Project window. Observe: Does not render document contents. image

kaygeecee avatar Jun 25 '21 13:06 kaygeecee

This works for me in 2020.2.1, which Unity version are you using?

gwaredd avatar Jun 28 '21 13:06 gwaredd

Oh wow, cant believe i forgot to write the Unity version in my bug report xD

I tested it in 2019.3.10f1

kaygeecee avatar Jun 29 '21 16:06 kaygeecee

This is working fine for me in 2019.3.10f1.

I suspect this might be a bug with Unity but we can check.

Could you try putting a breakpoint or some logging at the top of MarkdownEditor.OnEnable()? This is the entry point, so if this is still being called in the errant case then it's probably a bug with UMV. If it isn't, then Unity isn't calling the custom editor.

gwaredd avatar Jun 30 '21 09:06 gwaredd

Sure thing. I've even recorded a video of how it looks. It hits the breakpoint both during expected and unexpected behavior.

https://user-images.githubusercontent.com/5063329/123975702-d45f6500-d9bd-11eb-9958-e15a39a32ecf.mp4

kaygeecee avatar Jun 30 '21 14:06 kaygeecee

It looks like its rendering just the top part - the "raw text" button and the first line. I've seen something similar in very early versions where unity was reporting the height incorrectly.

Out of curiosity, if you toggle the "raw text" mode does it change anything?

Also if you stick a breakpoint here, what are the height and width being reported as? (sorry, I can't repro this locally)

gwaredd avatar Jul 06 '21 15:07 gwaredd

Out of curiosity, if you toggle the "raw text" mode does it change anything?

  • When enabling raw text once, it renders raw text mode properly
  • When enabling and disabling raw text, it renders the markdown viewer properly

https://user-images.githubusercontent.com/5063329/126603916-dc34772d-a9a8-49ca-9a1d-1651c95029e3.mp4

Also if you stick a breakpoint here, what are the height and width being reported as?

For one frame it is reported as 0, all following frames (where the GUI is actually updated/rendered) it is reported as 1304.75. This behavior is consistent whether or not the markdown viewer renders properly.

https://user-images.githubusercontent.com/5063329/126603878-fd12402d-b477-42ed-a970-b42cdc5d48da.mp4

kaygeecee avatar Jul 22 '21 07:07 kaygeecee

So my working theory is this is related to an issue in GUILayout.

UMV doesn't use GUILayout, it handles the layout of the document by hand. However for some versions of Unity, the height of the GUI control in the window is set internally in GUILayout somewhere. There is no way to set this, we just have to trick Unity into giving us the space to render into - which is what the GUILayout.Space( mLayout.Height ); bit is. It doesn't actually do anything, it's a work around.

I believe this was fixed in later versions of Unity, or at least the behaviour of the GUI system changed so it wasn't required any more.

You could try moving the GUILayout.Space( mLayout.Height ); hack to the top of the function so it is called for every event type (not just on the layout event). Bear in mind the height will be zero for some events, so maybe just call it for height > 0.

Alternatively, hack the height in and see if it makes a difference.

gwaredd avatar Jul 22 '21 10:07 gwaredd