Rotated Sprite Bug PB561 tested x64 /x86 - all OS

Post bugreports for the Windows version here
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Rotated Sprite Bug PB561 tested x64 /x86 - all OS

Post by walbus »

Rotated Sprite Bug PB561 x64 tested - Fails on all OS

Code: Select all

InitSprite()

EnableExplicit

Define sprite_ID
Define output_width=800, output_height=800

Define window_ID=OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, output_width, output_height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)

If Not OpenWindowedScreen(WindowID(window_ID), 0, 0, output_width, output_height) : End : EndIf

sprite_ID=CreateSprite(#PB_Any, 600, 100)

StartDrawing(SpriteOutput(sprite_ID))
Box(0, 0, 600, 100, $FF)
StopDrawing()

Repeat
  
  FlipBuffers()
  ClearScreen(RGB(0, 0, 0))
  DisplaySprite(sprite_ID, 50, 50) ; Output at 50, 50 , OK
  
  RotateSprite(sprite_ID, 45, #PB_Absolute)
  
  DisplaySprite(sprite_ID, 50, 50) ; Fails, wrong output pos, fails on Lin and Mac, Win OK

  DisplaySprite(sprite_ID, 50, -150) ; Fails complete on all OS, you should see it
  
Until WaitWindowEvent()=#PB_Event_CloseWindow
Its a little strange
Last edited by walbus on Mon Oct 09, 2017 9:26 pm, edited 1 time in total.
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Rotated Sprite Bug PB561 tested x64

Post by Demivec »

To verify your bug report I've updated your demonstration code to make an interactive bug display.

Code: Select all

InitSprite()
InitKeyboard()

EnableExplicit

Procedure handleError(value, text.s): If value = 0: MessageRequester("Error", text.s): End: EndIf: EndProcedure

Define sprite_ID, sprite_ID_1, sprite_ID_2, sprite_ID_3
Define output_width=800, output_height=800

Define window_ID=OpenWindow(#PB_Any, #PB_Ignore, #PB_Ignore, output_width, output_height, "", #PB_Window_SystemMenu | #PB_Window_ScreenCentered)
handleError(window_ID, "Couldn't open window.")
handleError(OpenWindowedScreen(WindowID(window_ID), 0, 0, output_width, output_height), "Couldn't open WindowedScreen.")

;create sprites
sprite_ID=CreateSprite(#PB_Any, 600, 100): handleError(sprite_ID, "Couldn't create the needed sprites.")
sprite_ID_1=CreateSprite(#PB_Any, 150, 150): handleError(sprite_ID_1, "Couldn't create the needed sprites.")
sprite_ID_2=CreateSprite(#PB_Any, 100, 100): handleError(sprite_ID_2, "Couldn't create the needed sprites.")
sprite_ID_3=CreateSprite(#PB_Any, 60, 60): handleError(sprite_ID_3, "Couldn't create the needed sprites.")

StartDrawing(SpriteOutput(sprite_ID))
  DrawingMode(#PB_2DDrawing_Gradient)
  LinearGradient(0, 0, 600, 0)
  BackColor(#Green)
  Box(0, 0, 600, 100, $FF)
StopDrawing()
  
handleError(LoadFont(0, "", SpriteHeight(sprite_ID_1) - 10), "Couldn't load all fonts.")
handleError(LoadFont(1, "", SpriteHeight(sprite_ID_2) - 10), "Couldn't load all fonts.")
handleError(LoadFont(2, "", SpriteHeight(sprite_ID_3) - 10), "Couldn't load all fonts.")

StartDrawing(SpriteOutput(sprite_ID_1))
  DrawingFont(FontID(0))
  DrawText((SpriteWidth(sprite_ID_1) - TextWidth("1")) / 2, (SpriteHeight(sprite_ID_1) - TextHeight("1")) / 2, "1", #White, #Blue)
StopDrawing()
  
StartDrawing(SpriteOutput(sprite_ID_2))
  DrawingFont(FontID(1))
  DrawText((SpriteWidth(sprite_ID_2) - TextWidth("2")) / 2, (SpriteHeight(sprite_ID_2) - TextHeight("2")) / 2, "2", #White, #Red)
StopDrawing()
  
StartDrawing(SpriteOutput(sprite_ID_3))
  DrawingFont(FontID(2))
  DrawText((SpriteWidth(sprite_ID_3) - TextWidth("3")) / 2, (SpriteHeight(sprite_ID_3) - TextHeight("3")) / 2, "3", #White, #Yellow)
StopDrawing()

EnumerationBinary 
  #showSprite_1      ;display sprite 1
  #showSprite_2      ;display sprite 2
  #showSprite_3      ;display sprite 3
  #showRotation      ;use dynamic rotation of sprites
  #showZeroRotation  ;reset absolute rotation of sprites to zero
EndEnumeration

Define event, x, y, x3 = 50, y3 = 50, show = #showSprite_1, prevTextX, textX, textY
Repeat
  Repeat
    event = WaitWindowEvent(10)
  Until event = 0 Or event = #PB_Event_CloseWindow
  
  FlipBuffers()
  ClearScreen(RGB(0, 0, 0))
  
  ExamineKeyboard()
  If KeyboardReleased(#PB_Key_Escape): event = #PB_Event_CloseWindow: EndIf
  If KeyboardReleased(#PB_Key_1): show ! #showSprite_1: EndIf
  If KeyboardReleased(#PB_Key_2): show ! #showSprite_2: EndIf
  If KeyboardReleased(#PB_Key_3): show ! #showSprite_3: EndIf
  If KeyboardReleased(#PB_Key_R): show ! #showRotation: EndIf 
  If KeyboardReleased(#PB_Key_Z): show ! #showZeroRotation: EndIf
  
  If KeyboardPushed(#PB_Key_Up)
    y3 - 1
  EndIf
  
  If KeyboardPushed(#PB_Key_Down)
    y3 + 1
  EndIf
  
  If KeyboardPushed(#PB_Key_Left)
    x3 - 1
  EndIf
  
  If KeyboardPushed(#PB_Key_Right)
     x3 + 1
  EndIf
  
  If show & #showZeroRotation
    RotateSprite(sprite_ID, 0, #PB_Absolute)
    show & (%111111111111111111111111 - #showRotation - #showZeroRotation) ;disable #showRotation also
  EndIf
  
  If show & #showSprite_1  
    x = 50: y = 50
    DisplaySprite(sprite_ID, x, y)
    DisplaySprite(sprite_ID_1, x + (SpriteWidth(sprite_ID) - SpriteWidth(sprite_ID_1))/ 2, y + (SpriteHeight(sprite_ID) - SpriteHeight(sprite_ID_1)) / 2)
  EndIf
  
  If show & #showRotation
    RotateSprite(sprite_ID, 1, #PB_Relative)
  EndIf
  
  If show & #showSprite_2
    x = 50: y = 50 
    DisplaySprite(sprite_ID, x, y)
    DisplaySprite(sprite_ID_2, x + (SpriteWidth(sprite_ID) - SpriteWidth(sprite_ID_2))/ 2, y + (SpriteHeight(sprite_ID) - SpriteHeight(sprite_ID_2)) / 2)
  EndIf
  
  If show & #showSprite_3
    DisplaySprite(sprite_ID, x3, y3)
    DisplaySprite(sprite_ID_3, x3 + (SpriteWidth(sprite_ID) - SpriteWidth(sprite_ID_3))/ 2, y3 + (SpriteHeight(sprite_ID) - SpriteHeight(sprite_ID_3)) / 2)
    
    StartDrawing(ScreenOutput())
      DrawingMode(#PB_2DDrawing_Transparent)
      DrawText(0, 0, "Sprite 3(" + x3 + ", " + y3 + ")", #Red)
    StopDrawing()
  EndIf
  
    StartDrawing(ScreenOutput())
     FrontColor(#White)
     DrawingMode(#PB_2DDrawing_Transparent)
     textY = 400: textX = 180
     prevTextX = DrawText(textX - TextWidth("1, 2, 3 : "), textY, "1, 2, 3 : ")
     DrawText(prevTextX + 20, textY, "Toggle display of sprite 1, 2, or 3 and it's corresponding number.")
     textY + 20: prevTextX = DrawText(textX - TextWidth("R : "), textY, "R : ")
     DrawText(prevTextX + 20, textY, "Toggle active rotation of sprites")
     textY + 20: prevTextX = DrawText(textX - TextWidth("Z : "), textY, "Z : ")
     DrawText(prevTextX + 20, textY, "Zero the absolute rotation of sprites and turn off active rotation")
     textY + 20: prevTextX = DrawText(textX - TextWidth("arrows : "), textY, "arrows : ")
     DrawText(prevTextX + 20, textY, "Modify sprite 3's coordinates")
     textY + 20: prevTextX = DrawText(textX - TextWidth("[Esc] : "), textY, "[Esc] : ")
     DrawText(prevTextX + 20, textY, "Exit program.")
     textX = 20
     textY + 40:DrawText(textX, textY, "Sprites 1 & 2 have a set position, while 3 is changeable.  The sprites are drawn in order (1, 2, 3) and the numbers")
     textY + 20:DrawText(textX, textY, "for the sprites are drawn immediately after their respective sprite and are centered on where their sprites should")
     textY + 20:DrawText(textX, textY, "be displayed. If a sprite's position is not displayed correctly, the sprite can be identified by which #'s it hides.")
     textY + 20:DrawText(textX, textY, "For example, sprite 3 hides sprite 1, #1, 2, And #2 While sprite 2 hides only sprite 1 And #1.")
     textY + 40:DrawText(textX, textY, "To demonstrate the error involving RotateSprite(), activate only sprites 1 and 3 and zero the rotation.")
     textY + 20:DrawText(textX, textY, "Move sprite 3 to about (196, 283).  Notice that sprites are correctly positioned under their #'s.")
     textY + 20:DrawText(textX, textY, "Press 'R' to start rotation.  Notice that sprite 1's position changes.")
     textY + 20:DrawText(textX, textY, "Press 'R' again to stop the rotation.  Notice that now sprite 3's position also changes.")
     textY + 20:DrawText(textX, textY, "You can verify which is sprite 3 by moving it.  Now zero the sprite positions and both sprites positions are correct.")
   StopDrawing()
  
Until event = #PB_Event_CloseWindow
I confirm the bug that using RotateSprite() and any angle results in displacing at least some of the later sprites out of their proper display locations. I confirmed this also with the directions in my test code for DirectX. The results were even more bizarre following the directions in my test code and using the OpenGL library SubSystem.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Rotated Sprite Bug PB561 tested x64

Post by walbus »

@Demivec
Very nice demo code !

Yep, on openGL, the rotating result fails ever
RotateSprite is primary unusable on openGL

The only available workaround is sprite pre rotating as image

I'm wondering, it looks, the community doesn't have much interest in this bug

Well, I don't care, I'm not a gamer :)
Last edited by walbus on Sat Oct 14, 2017 10:55 pm, edited 1 time in total.
User avatar
Demivec
Addict
Addict
Posts: 4091
Joined: Mon Jul 25, 2005 3:51 pm
Location: Utah, USA

Re: Rotated Sprite Bug PB561 tested x64

Post by Demivec »

I found the bug present at least as far back as version v5.20. That's as far as I tested so far.

I'm just surprised that it hasn't manifested itself before now. I'll do some more testing to see if there is a good bug avoidance strategy in using rotation with sprites.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Rotated Sprite Bug PB561 tested x64

Post by walbus »

Yep, i self have not found a way, i think it is a buffer size problem for the rotation result ?

It looks, the output is shifted vertically in a buffer for FlipBuffers
Last edited by walbus on Sat Oct 14, 2017 10:56 pm, edited 1 time in total.
User avatar
Fig
Enthusiast
Enthusiast
Posts: 351
Joined: Thu Apr 30, 2009 5:23 pm
Location: Côtes d'Azur, France

Re: Rotated Sprite Bug PB561 tested x64

Post by Fig »

An other sprite bug nobody care:
http://www.purebasic.fr/english/viewtop ... =4&t=65561

Pb is supposed to allow us to dev 2d games (at minimum). But it fails.
There are 2 methods to program bugless.
But only the third works fine.

Win10, Pb x64 5.71 LTS
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Rotated Sprite Bug PB561 tested x64

Post by walbus »

Yep, i know this other bug
Make a try with openGL, on openGL both bugs looking very similar

I couldn't believe it at first that RotateSprite didn't work properly on 561
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Rotated Sprite Bug PB561 tested x64

Post by Mijikai »

Fig wrote:...
Pb is supposed to allow us to dev 2d games (at minimum). But it fails.
I also can confirm this bug - i try to code a 2D game... :/
I rly hope this and the SetFramerate() bug get fixed soon.
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Rotated Sprite Bug PB561 tested x64

Post by walbus »

@Mijikai
Yep, its a little saddly
I think, for reducing the frame rate, you can use also a timer in the main loop (not a delay)
Last edited by walbus on Tue Oct 10, 2017 9:31 am, edited 2 times in total.
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Rotated Sprite Bug PB561 tested x64

Post by Kuron »

If the bug only exists in the 64-bit lib, that could be why almost nobody has noticed it. For games, 32-bit is still the norm and what publishers want.
Best wishes to the PB community. Thank you for the memories. ♥️
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Rotated Sprite Bug PB561 tested x64

Post by walbus »

@Kuron
Unfortunately, it looks at the same on x86 (32bit)
User avatar
Mijikai
Addict
Addict
Posts: 1360
Joined: Sun Sep 11, 2016 2:17 pm

Re: Rotated Sprite Bug PB561 tested x64

Post by Mijikai »

Kuron wrote:If the bug only exists in the 64-bit lib, that could be why almost nobody has noticed it. For games, 32-bit is still the norm and what publishers want.
It does exist on x86 & x64...
Image
User avatar
Kuron
Addict
Addict
Posts: 1626
Joined: Sat Oct 17, 2009 10:51 pm
Location: Pacific Northwest

Re: Rotated Sprite Bug PB561 tested x64

Post by Kuron »

You might want to modify the thread title to include X86 as well.
Best wishes to the PB community. Thank you for the memories. ♥️
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Rotated Sprite Bug PB561 tested x64

Post by walbus »

It can't be that no one has ever noticed this before !

Title changed
walbus
Addict
Addict
Posts: 929
Joined: Sat Mar 02, 2013 9:17 am

Re: Rotated Sprite Bug PB561 tested x64 /x86 - all OS

Post by walbus »

On Bucketfill_advanced (BF), now, a function is added for output high quality rotated PB sprites without PB bug on screen, all OS

The function can also resizing, rotating with offsets, color distance, handling JPG compressed images as sprites and more

Named "Create_PB_Sprite_simple_BF"

Demo file "BucketFill_scrolling_textured_text_and_alpha_image_on_windowed_screen_6.pb"
Last edited by walbus on Sat Oct 14, 2017 8:34 pm, edited 2 times in total.
Post Reply