Monarch, Rendercam, and GUI Problems (SOLVED)

Hey, I’ve got a batch of problems here that I’d like to solve.

Problem 1 of 3: Resizing window and GUI text

1

The above screenshot shows a main menu screen with four GUI options. Each node is set to the “Fit” adjust method. When I resize the window, the font (mainly the black outline) is distorted as shown below:

2

How do I resize the window without distorting the GUI text? From what I understand, it should be possible to simply leave the GUI alone if the window is resized.

Problem 2 of 3: Rendercam’s screen_to_world_2d function error

I’m launching a projectile (called a “minimi” here). The first step to figuring out its spawn position is to get the mouse position and translate it into world position using Rendercam. The x and y arguments I passed in come from on_input's action.screen_x and action.screen_y fields:

3

Running this line outputs the following error:

Here is the exact code from the rendercam library that’s causing the issue:

Line 368 argument 2 (np) causes the problem. Rendercam is imported correctly, its properties are set correctly, and there is no ID collision with other collection proxies. Here’s how my rendercam is set up:

I’m at a loss with this one. @ross.grams might be able to help?

Problem 3 of 3: Monarch’s screen loading / preloading

This one is a continuation of @britzl’s responses in this thread: Revert to older Defold version? [SOLVED] (Thanks for writing this out by the way, helping me understand how everything works.)

One solution for the screen flicker is to use Monarch’s transitions, however I’m using my own transitions just by animating GUI nodes and the screen background before switching screens, so this is not an option for me. The solution I’m using is to monarch.preload() the next screen before monarch.show()ing it:

7

(The “screen” module is simply a wrapper around Monarch functions.) As you can see, when I call screen.show(), it first preloads the next screen then shows it when preloading is finished. This should allow screens to switch without any delay time, however I’m still getting a 1-frame black flicker… most of the time. Like 10% of the time the screens transition with no problem, but the other 90% a black flicker appears for a frame. It’s very strange. I thought maybe it could be some kind of issue with Rendercam, so I deleted the camera from both screens I was testing, however the same result occurred.

Part of me wants to think it’s not actually Monarch that causing the issue, since like I said there’s about a 10% chance that I don’t get the black flicker. I really don’t know how to solve this. I mentioned in the linked thread that reverting Defold engine to the version before Defold 1.2.169 has been released solves the flicker problem (so using version 1.2.168). I also tried reverting Monarch versions, but that did not change anything. I also tried unchecking V-Sync and using FPS cap instead (just for the sake of trying), but that didn’t work either.

Those are my three problems I’m struggling with right now. Let me know if you have any ideas on how to fix them. Thanks a lot for your support on here, it has been invaluable! I will continue trying out solutions in the meantime.

1 Like

Hmm, the Rendercam one sounds suspiciously similar to this issue: Crash when app comes back from sleep, but you’re just getting that error when building and running from the editor? Can you try putting 'print(m)' in before it errors? If it’s possible to share the project (or any project that has the error) I will check it out myself.

1 Like

print(m) gives me:
vmath.matrix4(1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1)

I placed it directly beneath:
local m = not delta and vmath.inv(M.proj * M.view) or vmath.inv(M.proj)

Does this look right?

Edit: I also printed (x1, y1) beneath if delta then x1 = x1 + 1; y1 = y1 + 1 end.
Both values are inf, which I believe explains why np ends up as not a number.

1 Like

And what if you check the Preload checkbox on the screen script instead of preloading using code?

Checking the preload box shows the same result as using the preload code. I was thinking that it may be worth a shot to try using collection factories instead of collection proxies for screens.

Yes, try that. Or think of a way to make a nice but short transition between the screens (fade-in/out)

Anything thoughts on fixing the inf problem? Wasn’t sure if you accidentally read my reply as a fix. :slight_smile:

1 Like

No, sorry, I just hadn’t gotten a chance to look into it more.

When are you getting this error? Is this on init or possibly before? With those camera settings, the matrix should not be that (1, 0, 0, 0, ...) unless it’s before it gets properly set, which happens on the first render script update. That by itself wouldn’t cause the error though, I’m just looking for clues…

So you get inf if you divide by zero…which could be happening either in screen_to_viewport (line 349), or on lines 355-356. Both of those seem to indicate that either the window width/height is being reported as 0, 0, or this is somehow happening before the render script inits…? (which I don’t think is possible.)

1 Like

Oi, sorry for taking your time with this one. Turns out I forgot to replace the default render script with rendercam’s version. Thought for sure I replaced that immediately after fetching the library. Thanks for your help!

1 Like

Ahh, haha, no problem! I’m glad it was an easy fix.

1 Like

Regarding issue #1, is it possible to set GUI rendering to not scale on window resize? Looks like text scaling is what’s causing the text distortion.

You can disable the Adjust Mode setting on the entire GUI component: https://defold.com/manuals/gui/#creating-a-gui-component

But there’s actually no setting to disable the adjust mode on a specific node. Nodes have Zoom, Fit and Stretch. Perhaps we should have None as well?

1 Like

What I’m looking for is a setting that respects gui anchors (or element translations in general) when the window is resized, while at the same time disables scaling on resize. This way, there is no text distortion on resize, but the element positions are correct on the screen.

One popular example of this is the Minecraft title screen. I’m sure there are plenty other examples, but none come to mind at the moment.

Regarding issue #3, collection factories fix the flicker issue. Since there’s a functional difference between factories and proxies, I didn’t go for this solution, but it’s good to know for future reference. I rolled the engine version back to 1.2.168 and it works perfectly with proxies. It was a strange issue for sure. I wonder if anybody else has run into this issue. Regardless, that will be the last time I deal with it. :slight_smile: