Quick Links: Download Gideros Studio | Gideros Documentation | Gideros community chat | DONATE
Imgui crash in android player on touch — Gideros Forum

Imgui crash in android player on touch

This is the output as soon as I touch the screen

[1355] jni/../../Common/imgui_src/imgui.cpp: mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT

Should I do something I missed?

Thank you

Comments

  • I had no luck so far, I hope that someone else can try this project and confirm my experience.

    This is a very simple project that makes use only of the imgui demo window, and I get the same error message that I have in every other project I tried using imgui on android.

    They work in windows desktop player, but when I run them on android player they stop working as soon as I touch the screen; I even tried using a bluetooth mouse on the phone: as soon as I click the left button the player crashes
    [1355] jni/../../Common/imgui_src/imgui.cpp: mouse_button >= 0 && mouse_button < ImGuiMouseButton_COUNT
    To build the android player I exported the project as a player with imgui plugin and no assets as usual.

    thank you
    zip
    zip
    androidplayer_dummy.zip
    1M
  • keszeghkeszegh Member
    edited November 2022
    i had the sameish issue, see
    https://forum.giderosmobile.com/discussion/8399/imgui-new-thread/p20

    Comment 67327

    my workaround is that i propagate the mouse/touch events manually to the imgui within ontouches begin/move/end/cancel events, and there i do something like this to change value 0 to 1 before sending to imgui:
    if event.touch.mouseButton==0 then event.touch.mouseButton=1 end	 
    IO:setMouseDown(event.touch.mouseButton, true)
    (you need to disable automatic handling of mouse events to make this work, that is, you should initialize the gui like this:
    imgui = ImGui.new(nil, false, true, false) 
    IO=getIO()
    see https://github.com/MultiPain/Gideros_ImGui/#constructor)

    Likes: pie, MoKaLux

    +1 -1 (+2 / -0 )Share on Facebook
  • piepie Member
    edited December 2022
    I found out that I was using gideros TOUCHES_BEGIN/END events, while I had to use ImGui events, and now it is almost working.

    -EDIT: partially answered my own question, removed the second question to keep forum cleaner. I cannot remove the not working attached example, therefore I will make a new post.

    zip
    zip
    imgui_test_touch_TTF.zip
    358K
  • The attached file is an almost working example for imgui android touch: buttons are selected on the first click/touch and need a second click/touch to act.
    @rraptor @keszegh do you know if I can change this behaviour and let them act as soon as they are pressed?
    zip
    zip
    Imgui_android_touch.zip
    3K
  • keszeghkeszegh Member
    edited December 2022 Accepted Answer
    hi @pie, i don't have time to digest your code but i copy here more of my solution:
    stage:addEventListener(Event.TOUCHES_BEGIN, onTouch,self)
    stage:addEventListener(Event.TOUCHES_MOVE, onTouch,self)  
    stage:addEventListener(Event.TOUCHES_END, onTouch,self)
    stage:addEventListener(Event.TOUCHES_CANCEL, onTouch,self)
    stage:addEventListener(Event.MOUSE_HOVER, onTouch,self)
    stage:addEventListener(Event.MOUSE_WHEEL, onTouch,self)
     
     
    function onTouch(event)               
      local IO=gui.IO    
     
      if event.type=="mouseWheel" then      
        IO:setMouseWheel(event.wheel/300)
        IO:setMousePos(event.x,event.y)            
        return    
      end
     
      if event.type=="mouseHover" then      
        IO:setMousePos(event.x,event.y)        
        return    
      end
     
      local xGui=event.touch.x
      local yGui=event.touch.y
      IO:setMousePos(xGui,yGui)    
     
      guiHasMouse=IO:wantCaptureMouse()    
     
      if event.type=="touchesBegin" then           
    	if event.touch.mouseButton==0 then event.touch.mouseButton=1 end	 --workaround
        IO:setMouseDown(event.touch.mouseButton, true)                       
      end
     
      if event.type=="touchesMove" then           
      end
     
     if event.type=="touchesEnd" then        
    	  if event.touch.mouseButton==0 then event.touch.mouseButton=1 end     --workaround
        IO:setMouseDown(event.touch.mouseButton, false)           
        IO:setMouseDown(2, false)  --for safety, sometimes right-click got `stuck' 
      end        
     
      guiHasMouse=IO:wantCaptureMouse()  
      if guiHasMouse then return end
     end

    Likes: pie, MoKaLux

    +1 -1 (+2 / -0 )Share on Facebook
  • Thank you @keszegh this indeed works in a clean project, so my issue has probably to do with how I built my imgui based app until now :# It's faster to rewrite it than trying to discover what the issue was exactly.

    For the records my ui and IO instances were returned through a function from a local variable instanced in another lua file, but this approach didn't show any issue until now.
  • i'm glad it works.
    and also hope that this strange thing with event.touch.mouseButton returning 0 will be corrected.
    overall, imgui is really cool (along with gideros).
  • keszegh said:

    i'm glad it works.
    and also hope that this strange thing with event.touch.mouseButton returning 0 will be corrected.
    overall, imgui is really cool (along with gideros).

    What do you want it to return instead of 0?
    I may have a look if I understand the issue, do you have gideros forum threads where you explain this?

    Likes: pie

    my growING GIDEROS github repositories: https://github.com/mokalux?tab=repositories
    +1 -1 (+1 / -0 )Share on Facebook
  • well, i think for a touch event 1 would be the correct value.
Sign In or Register to comment.