New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
internal/ui: a wrong calculation of a region for anti-aliasing #2679
Comments
Last render frame dump:
|
The new-image is likely whiteImage here: https://github.com/divVerent/aaaaxy/blob/main/internal/menu/map.go#L101 Commenting out all that has to do with it works around the bug. Commenting out the contents of DrawPolyLine works around the bug: https://github.com/divVerent/aaaaxy/blob/main/internal/engine/polyline.go#L28 |
Hmm, interesting.
|
Not reproducible on macOS, but likely this is an optional debug feature (MTLDebugRenderCommandEncoder) I do not know how to trigger on macOS. Minimized test case is unlikely, as I do not yet know why it happens. The DrawPolyLine call to DrawTriangles looks entirely harmless to me. Quite possible it's internal state messup inside Ebitengine. |
Hm... (rect.x(0) + rect.width(800))(800) must be <= render pass width(128) Any chance I can get this "render pass width" from Go code? I guess it'd be much easier if we could just panic in Go code there, to get a proper Go backtrace. |
I have no idea about this. We might be able to investigate this by using MTLDebugRenderCommandEncoder explicitly, but I'm not familiar with this... |
800x384 makes no sense at all here BTW - nothing in my game has this size. Typical screen texture is 640x360. And after changing to the iPad emulator, even in portrait mode, it's still 800x384 in the error. 128x64 feels like some sort of minimum texture size used for whiteImage. |
Issue still happens (including new-image call) if I move whiteImage elsewhere and initialize it at game start. That's weird. |
One recent change to that code: I had toggled Reverting that stops the bug from happening. Too bad I don't know how to run the examples in the iOS Simulator without starting new Xcode project and doing lots of work there. |
It crashes at least in the Simulator. Works around hajimehoshi/ebiten#2679
Using anti-aliasing means using a double-sized offscreen image. |
Yeah, even then, 400x192 also makes no sense. |
Grounding this call: https://github.com/hajimehoshi/ebiten/blob/main/internal/ui/image.go#L400 Prevents the crash. |
Randomized stuff so only one draw call takes place per frame, to rule out interference of draw calls with each other. Caught one of those with these variable contents:
|
dstRegion quite certainly oversteps i.image's bounds. |
dstRegion is computed by taking initial dstRegion shifted by i.region.X/Y, intersecting with 0/0/i.region.Width/i.region.Height, and doubling. At least that's how it LOOKS - there's an obvious bug there (subtraction of i.region.X/Y is missing when computing x1/y1). That can't be all there is to the bug though, as the min() should still prevent the worst. Looking further. |
OH, it also adds region.X for the upper bound. That too can't be right. Yeah, I can see how dstRegion is wrong - let me see if fixing that is all it takes. |
One issue is, I can sure write a fix, but as the wrong dstRegion is always bigger than the correct region, it may not be possible to cover this by a test case, UNLESS we can run a test case with MTLDebugRenderCommandEncoder. |
Fix confirmed, sending PR. |
I see ONE potential chance to make a test case: allocate an atlas with multiple textures, then DrawTriangles on one and ReadPixels the others. I will try, but not sure if it will work. Plus, the test would be highly dependent on how atlas texture allocation work. Don't quite like that. |
When I test on macOS, the temp texture AntiAlias uses never ends up on the same atlas as my NewImage textures, so I can never observe an out-of-bounds write attempt. |
Ebitengine Version
v2.5.4
Operating System
Go Version (
go version
)go version go1.20.5 darwin/arm64
What steps will reproduce the problem?
Run AAAAXY in the iOS Simulator. Issue doesn't happen on real iPhone 6S or real iPad Air 1st Gen. Walk right and jump until you touch the first checkpoint, then click the back button at the top left and click "Play".
What is the expected result?
A map screen shows up.
What happens instead?
Game halts, and debugger shows:
Anything else you feel useful to add?
Issue already exists in v2.5.0. I cannot go back further. Do not yet know what exact render call triggers it.
Size 800x384 surprises me - there's no object in my game of that size. Also don't know yet which render pass this is.
The text was updated successfully, but these errors were encountered: