6.21 MousePick return wrong id

Everything related to 3D programming
User avatar
minimy
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

6.21 MousePick return wrong id

Post by minimy »

Hello, im trying to use PickMouse over 6.21 and return wrong Entity..
Any body can test it and confirm if is a bug?

Return this
CUBE: 2152618004016
Entity clicked: 2147483647

How you can see are diferent.
Here the code to test. Thanks.

Code: Select all

InitEngine3D(#PB_Engine3D_DebugLog):InitSprite():InitKeyboard():InitMouse()
OpenWindow(0, 0,0, 1280,720, "Pick test",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0),WindowHeight(0), 0, 0, 0)

CreateCamera(0,0,0,100,100):MoveCamera(0,0,5,-20,#PB_Absolute):CameraLookAt(0,0,5,0):CameraBackColor(0,$332211)
CreateLight(0,$ffffff,3,3,3)

s= CreateSprite(#PB_Any,30,30,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(s)):Box(0,0,OutputWidth(),OutputHeight(),$ff0000):StopDrawing()

e= CreateEntity(#PB_Any,MeshID(CreateCube(#PB_Any,1)),MaterialID(CreateMaterial(#PB_Any,#Null,$ff0000)))
Debug "CUBE: "+Str(e)


Repeat
  While WindowEvent():Wend
  ExamineMouse(): ExamineKeyboard()
  
  If MouseButton(#PB_MouseButton_Left)
    If Not lmb
      lmb=1
      e= MousePick(0,MouseX(),MouseY())
      Debug "Entity clicked: "+Str(e)
      If e>-1
      EndIf
    EndIf
  Else
    lmb=0
  EndIf
  
  renderTime= RenderWorld()
  DisplayTransparentSprite(s,MouseX(),MouseY())
  
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
minimy
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: 6.21 MousePick return wrong id

Post by minimy »

If use a number, not PB_any, all work fine, but with PB_any MouseClick() return unknown id (unknown for me) :lol:
Last edited by minimy on Mon Aug 11, 2025 11:51 am, edited 1 time in total.
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
minimy
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: 6.21 MousePick return wrong id

Post by minimy »

Found this when run a 3D main menu over 6.21, in 6.02 work.

Image
If translation=Error: reply="Sorry, Im Spanish": Endif
miso
Enthusiast
Enthusiast
Posts: 459
Joined: Sat Oct 21, 2023 4:06 pm
Location: Hungary

Re: 6.21 MousePick return wrong id

Post by miso »

I think you are absolutely right.

Sorry, I hijacked your code to a more convenient one for me.

Code: Select all

DeclareModule petskii
  Declare init()
  Declare text(x, y, text.s, color.i, intensity.i = 255)
EndDeclareModule
Module petskii
  #USED_CHARACTERS = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789!@#$%^&*()-_=+[{]};:',<.>/?"+Chr(34)
  Global Dim petskiifont(370)
  Global Dim fontimport.i(370)
  Procedure sub_loadfont()
    Protected x.i, i.i, j.i, sprline.a
    For i = 1 To Len(#USED_CHARACTERS):fontImport(Asc(Mid(#USED_CHARACTERS, i, 1))) = 1 : Next i 
    Restore petskii_font
    For x = 1 To 370
      If fontimport(x) = 1
        petskiifont(x) = CreateSprite(#PB_Any, 8, 12, #PB_Sprite_AlphaBlending)
        StartDrawing(SpriteOutput(petskiifont(x)))
        DrawingMode(#PB_2DDrawing_AllChannels)
        For j = 0 To 11  
          Read.a sprline 
          For i = 0 To 7
            If sprline&%1 :Plot(i, j, RGBA(255, 255, 255, 255)): Else : Plot(i, j, RGBA(0, 0, 0, 0)) : EndIf
            sprline>>1 
          Next i
        Next j
        StopDrawing()
        ZoomSprite(petskiifont(x), 16, 24)
      EndIf
    Next x
  EndProcedure
  Procedure init()
    sub_loadfont()
  EndProcedure
  Procedure text(x, y, text.s, color.i, intensity.i = 255) : Protected.i textlength, i, character
    textlength.i = Len(text.s)
    For i = 1 To textlength.i
      character.i = Asc(Mid(text.s, i, 1))
      If character.i>ArraySize(petskiifont()) : ProcedureReturn #Null : EndIf
      If IsSprite(petskiifont(character))
        DisplayTransparentSprite(petskiifont(character), (x+((i-1) * 16)), (y), intensity, color.i)
      EndIf
    Next i
  EndProcedure
  DataSection
    petskii_font:
    Data.q $3838383838380000, $EEEE000000003800, $00000000000000EE, $FFEEFFEEEEEE0000, $383800000000EEEE, $0000387EE07C0EFC, $1C3870EECECE0000, $7C7C00000000E6EE, $0000FCEEEE3C7CEE
    Data.q $00003870E0E00000, $7070000000000000, $000070381C1C1C38, $707070381C1C0000, $0000000000001C38, $000000EE7CFF7CEE, $38FE383800000000, $0000000000000038, $001C383800000000
    Data.q $00FE000000000000, $0000000000000000, $0000383800000000, $3870E0C000000000, $7C7C000000000E1C, $00007CEEEEFEFEEE, $38383C3838380000, $7C7C00000000FE38, $0000FE0E1C70E0EE
    Data.q $E078E0EE7C7C0000, $E0E0000000007CEE, $0000E0E0FEEEF8F0, $E0E07E0EFEFE0000, $7C7C000000007CEE, $00007CEEEE7E0EEE, $383870EEFEFE0000, $7C7C000000003838, $00007CEEEE7CEEEE
    Data.q $E0FCEEEE7C7C0000, $3838000000007CEE, $0000383800000038, $0000003838380000, $F0F00000001C3838, $0000F0381C0E1C38, $FE00FE0000000000, $1E1E000000000000, $00001E3870E07038
    Data.q $3870E0EE7C7C0000, $7C7C000000003800, $00007CCE0EFEFEEE, $EEFEEE7C38380000, $7E7E00000000EEEE, $00007EEEEE7EEEEE, $0E0E0EEE7C7C0000, $3E3E000000007CEE, $00003E7EEEEEEE7E
    Data.q $0E3E0E0EFEFE0000, $FEFE00000000FE0E, $00000E0E0E3E0E0E, $EEFE0EEE7C7C0000, $EEEE000000007CEE, $0000EEEEEEFEEEEE, $383838387C7C0000, $F8F8000000007C38, $00003C7E70707070
    Data.q $3E1E3E7EEEEE0000, $0E0E00000000EE7E, $0000FE0E0E0E0E0E, $CEFEFEFECECE0000, $EEEE00000000CECE, $0000EEEEFEFEFEFE, $EEEEEEEE7C7C0000, $7E7E000000007CEE, $00000E0E0E7EEEEE
    Data.q $EEEEEEEE7C7C0000, $7E7E00000000F07C, $0000EE7E3E7EEEEE, $E07C0EEE7C7C0000, $FEFE000000007CEE, $0000383838383838, $EEEEEEEEEEEE0000, $EEEE000000007CEE, $0000387CEEEEEEEE
    Data.q $FEFECECECECE0000, $EEEE00000000CEFE, $0000EEEE7C387CEE, $387CEEEEEEEE0000, $FEFE000000003838, $0000FE0E1C3870E0, $1C1C1C1C7C7C0000, $7C7C000000007C1C, $00007C7070707070
    Data.q $3838FE7C38380000, $0000000000003838, $0000FF0000000000, $FCE07C0000000000, $000000000000FCEE, $00007EEEEE7E0E0E, $0E0E7C0000000000, $0000000000007C0E, $0000FCEEEEFCE0E0
    Data.q $FEEE7C0000000000, $0000000000007C0E, $0000383838FC38F0, $EEEEFC0000000000, $0E0E0000007EE0FC, $0000EEEEEEEE7E0E, $38383C0038380000, $0000000000007C38, $003C707070700070
    Data.q $3E7E0E0E0E0E0000, $3C3C00000000EE7E, $00007C3838383838, $FEFEEE0000000000, $000000000000CEFE, $0000EEEEEEEE7E00, $EEEE7C0000000000, $0000000000007CEE, $000E0E7EEEEE7E00
    Data.q $EEEEFC0000000000, $0000000000E0E0FC, $00000E0E0EEE7E00, $7C0EFC0000000000, $0000000000007EE0, $0000F0383838FE38, $EEEEEE0000000000, $000000000000FCEE, $0000387CEEEEEE00
    Data.q $FEFECE0000000000, $000000000000FCFC, $0000EE7C387CEE00, $EEEEEE0000000000, $00000000003E70FC, $0000FE1C3870FE00, $381E3838F0F00000, $1E1E00000000F038, $00001E3838F03838
  EndDataSection
EndModule


ExamineDesktops()

InitEngine3D(#PB_Engine3D_DebugLog):InitSprite():InitKeyboard():InitMouse()
OpenWindow(0, 0,0, DesktopUnscaledX(DesktopWidth(0)),DesktopUnscaledY(DesktopHeight(0)), "Pick test",#PB_Window_ScreenCentered|#PB_Window_BorderLess)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0),WindowHeight(0), 0, 0, 0)



CreateCamera(0,0,0,100,100):MoveCamera(0,0,5,-20,#PB_Absolute):CameraLookAt(0,0,5,0):CameraBackColor(0,$332211)
RenderWorld()
ClearScreen(0)
FlipBuffers()


petskii::init()
CreateLight(0,$ffffff,3,3,3)



s= CreateSprite(#PB_Any,8,8,#PB_Sprite_AlphaBlending)
StartDrawing(SpriteOutput(s)):Box(0,0,OutputWidth(),OutputHeight(),$ff0000):StopDrawing()


cMesh=CreateCube(#PB_Any,1)
cmat=CreateMaterial(#PB_Any,#Null,$ff0000)

en.i = CreateEntity(#PB_Any,MeshID(cMesh),MaterialID(cmat))
;ebug "CUBE: "+Str(en)


ReleaseMouse(#False)
Repeat
  While WindowEvent():Wend
  ExamineMouse(): ExamineKeyboard()
  RotateEntity(en,0,1,0,#PB_Relative)
  If MouseButton(#PB_MouseButton_Left)
    If Not lmb
      lmb=1
      e= MousePick(0,MouseX(),MouseY())
      EndIf
  Else
    lmb=0
  EndIf
  
  renderTime= RenderWorld()
  
  DisplayTransparentSprite(s,MouseX(),MouseY())
    petskii::text(10,10,"Entity created     : "+Str(en),RGB(255,255,255)) 
    petskii::text(10,30,"Last Entity clicked: "+Str(e),RGB(255,255,255))

  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)


Last edited by miso on Mon Aug 11, 2025 4:56 pm, edited 1 time in total.
User avatar
minimy
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: 6.21 MousePick return wrong id

Post by minimy »

Thanks miso for confirmation!
Don't be a kidnapper friend! :lol:
As long as you don't ask me for ransom, all good :mrgreen:
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: 6.21 MousePick return wrong id

Post by IceSoft »

Better move it to the bug section?
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
User avatar
minimy
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: 6.21 MousePick return wrong id

Post by minimy »

IceSoft wrote: Tue Aug 12, 2025 12:15 pm Better move it to the bug section?
Hi IceSoft. Yes, is true. Moved.
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
skinkairewalker
Enthusiast
Enthusiast
Posts: 778
Joined: Fri Dec 04, 2015 9:26 pm

Re: 6.21 MousePick return wrong id

Post by skinkairewalker »

minimy wrote: Mon Aug 11, 2025 11:49 am Found this when run a 3D main menu over 6.21, in 6.02 work.

Image
can u share this code example ?
User avatar
minimy
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: 6.21 MousePick return wrong id

Post by minimy »

skinkairewalker wrote: Sat Aug 16, 2025 1:09 am
minimy wrote: Mon Aug 11, 2025 11:49 am Found this when run a 3D main menu over 6.21, in 6.02 work.

Image
can u share this code example ?
Hello skinkairewalker. The code for menu is big and complex, because have a lot of diferent 'gadgets' (buttons, sliders, toggle, inputs... I go to use this in my game. :wink:
The problem is this no work with PB6.21, if you run in 6.02 this work, is tested. :shock:
The base of the program is about MousePick and how say the title return wrong ID in 6.21.

But... i can share this snippet to have an idea of how work it. I think with this code and a little of work, you can make your own menu for your needs.
We use four rotated planes for buttons, draw the textures with your own design (now only have text). The idea is very simple.
I hope this help you. Tell me if you need more help.

Code: Select all

;{ sistema 3D
InitEngine3D(#PB_Engine3D_DebugLog):InitSprite():InitKeyboard():InitMouse()
OpenWindow(0, 0,0, 1280,720, "MENU 3D",#PB_Window_ScreenCentered)
OpenWindowedScreen(WindowID(0), 0, 0, WindowWidth(0),WindowHeight(0), 0, 0, 0)
CreateCamera(0,0,0,100,100):MoveCamera(camara,0,8,-15,#PB_Absolute):CameraLookAt(0,0,8,0):CameraBackColor(0,$332211)
CreateLight(0,$ffffff,23,23,23)
e= CreateEntity(#PB_Any,MeshID(CreateCube(#PB_Any,2)),MaterialID(CreateMaterial(#PB_Any,#Null,$0000ff)),0,8,0)
;}

f= LoadFont(#PB_Any,"Arial",20):m= CreatePlane(#PB_Any,4,1,1,1,1,1):tx.s= "":Dim b(4)
For p= 0 To 3
  t= CreateTexture(#PB_Any,200,50)
  StartDrawing(TextureOutput(t))
  DrawingMode(#PB_2DDrawing_AllChannels): Box(0,0,OutputWidth(),OutputHeight(),$00000000)
  DrawingMode(#PB_2DDrawing_AlphaBlend|#PB_2DDrawing_Transparent): Box(0,0,OutputWidth(),OutputHeight(),$88550000)
  tx= "Button "+Str(p): DrawingFont(FontID(f)):DrawText((OutputWidth()-TextWidth(tx))/2,(OutputHeight()-TextHeight(tx))/2,tx,$ffff4400)
  StopDrawing()
  b(p)= CreateEntity(#PB_Any,MeshID(m),MaterialID(CreateMaterial(#PB_Any,TextureID(t))), -5,10-(p*2),0):RotateEntity(b(p),-90,0,0)
Next p
mouseSpr= CreateSprite(#PB_Any,30,30):StartDrawing(SpriteOutput(mouseSpr)):Box(0,0,OutputWidth(),OutputHeight(),$00ffff):StopDrawing()

Repeat
  While WindowEvent():Wend
  ExamineMouse(): ExamineKeyboard()
  
  RotateEntity(e,0.5,1,2,#PB_Relative)
  renderTime= RenderWorld()
  
  DisplaySprite(mouseSpr,MouseX(),MouseY())
  
  If MouseButton(#PB_MouseButton_Left)
    If lmb=0
      mp= MousePick(0,MouseX(),MouseY())
      If mp>-1
        For p= 0 To 3:If mp=b(p):Debug "clik button "+Str(p):EndIf:Next p
      EndIf
    EndIf
    lmb=1
  Else
    lmb=0
  EndIf
  
  FlipBuffers()
Until KeyboardPushed(#PB_Key_Escape)
End
If translation=Error: reply="Sorry, Im Spanish": Endif
infratec
Always Here
Always Here
Posts: 7598
Joined: Sun Sep 07, 2008 12:45 pm
Location: Germany

Re: 6.21 MousePick return wrong id

Post by infratec »

Strange ...
in PB 6.21 x86 asm backend on Win10 x64 it works.
CUBE: 67700984
Entity clicked: -1
Entity clicked: 67700984
PB6.21 x64 asm backend fails. The returned value is 7FFFFFFF
CUBE: 1D388510E30
Entity clicked: FFFFFFFFFFFFFFFF
Entity clicked: 7FFFFFFF
User avatar
minimy
Enthusiast
Enthusiast
Posts: 597
Joined: Mon Jul 08, 2013 8:43 pm
Location: off world

Re: 6.21 MousePick return wrong id

Post by minimy »

Hello Infratec!
Work in 6.21 x86?? i need try it. Was tested in x64 and not work.
I said it, MousePick() in 6.21 only work if you use defined numbers for entiitys, like CreateEntity(0... if you use CreateEntity(#PB_Any... this return weird numbers.
Thanks for test and for advice about x86.
If translation=Error: reply="Sorry, Im Spanish": Endif
User avatar
IceSoft
Addict
Addict
Posts: 1694
Joined: Thu Jun 24, 2004 8:51 am
Location: Germany

Re: 6.21 MousePick return wrong id

Post by IceSoft »

@fred
should check for bug or not
Belive! C++ version of Puzzle of Mystralia
Bug Planet
<Wrapper>4PB, PB<game>, =QONK=, PetriDish, Movie2Image, PictureManager,...
Post Reply