gwaredd/UnityMarkdownViewer

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

Closed this issue · 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

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

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

I tested it in 2019.3.10f1

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.

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

UMW.RenderingBug.-.2021-06-30.16-06-02.mp4

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)

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
2021-07-22.09-23-19-1.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.

2021-07-22.09-21-29-1.mp4

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.