SetScissor won't reset with scaled image on Flash

Monkey Forums/Monkey Bug Reports/SetScissor won't reset with scaled image on Flash

Pudsy(Posted 2011) [#1]
Hi,

The code below requires an "image.png" of size 64x64 pixels.
Give it some kind of pattern so you can see it being scaled etc.

This issue only seems to occur with the Flash target. HTML5 & Android seem to be ok. Haven't tested any others.

After using SetScissor and then trying to reset the clipping rect to the entire screen, if you try to draw a SCALED or ROTATED image using the parameters on DrawImage(), something weird happens...

The scaled and/or rotated image is drawn successfully the first time around. But on subsequent calls to OnRender(), it isn't drawn at all.

Calls to DrawImage() without the scale or rotation parameters seem to be ok though.

In the example code below, the smaller rotated version of the image doesn't move along the screen with the non-scaled version - but since the bottom half of the screen isn't cleared each frame, you can see where it was drawn successfully the first time.

Thanks!

Strict
Import mojo


Global img:Image
Global x:Int = 0


Function Main:Int()
	New ScissorApp
	Return 0
End Function


Class ScissorApp Extends App

	Method OnCreate:Int()
		SetUpdateRate(60)
		
		img = LoadImage("image.png")
		If (img = Null) Then Error "Can't load 'image.png' - should be 64x64 pixels with a distinctive pattern"

		Return 0
	End Method
	
	Method OnUpdate:Int()
		x = (x + 1) Mod DeviceWidth()
		Return 0
	End Method
	
	Method OnRender:Int()

		' should clip to top half of the screen
		SetScissor 0,0, DeviceWidth(),240

		' draw a large scaled image to cover top half of screen
		DrawImage img, 0,0, 0, 10,10

		' should restore clipping rect to full screen
		SetScissor 0,0, DeviceWidth(),DeviceHeight()
		

		' WORKS: THIS *NON-SCALED* IMAGE IS DRAWN PROPERLY EVERY FRAME
		DrawImage img, x,280
		
		' BUG (FLASH ONLY): THIS *SCALED AND/OR ROTATED* IMAGE IS ONLY DRAWN THE FIRST TIME
		DrawImage img, x,380, 45, 0.5,0.5

		
		Return 0
	End Method
	
End Class



therevills(Posted 2011) [#2]
Yep... happens here too.

If you add a Cls to the start of OnRender it works okay.

[edited ;)]


Pudsy(Posted 2011) [#3]
Thanks for testing & confirming.

I assume you meant "Cls" rather than "Cs".
In fact, adding something like this to the top of OnRender...
If x < 50 Then Cls

...you can see it stops rendering the scaled image when the Cls no longer triggers.

The issue arose because I was trying to avoid wasteful overdrawing or a Cls of the whole screen, so I'd rather not have to resort to that as a workaround. Obviously, this is a heavily simplified & meaningless extract from the code, just to demo the actual problem.


marksibly(Posted 2011) [#4]
Hi,

This is a bit weird and I'll have a look at it, but in general you should ALWAYS Cls or at least DrawImage a background before rendering.


Pudsy(Posted 2011) [#5]
Thanks Mark!

Definitely weird... I actually discovered the problem because the image that wasn't being rendered *WAS* the background, or at least part of it :)

So, in reality I'm not trying to allow left-overs from the previous frame to carry over as a background. That's just how the example code above turned out after I'd trimmed it down to the bare minimum to reproduce the issue.