Ren'Py Crashing while playing mini-game, click and hold

EmperoXXX Anime

KonoSuba The Harem Adventures
Game Developer
Jul 30, 2023
86
281
While most of the players didn't face this issue, still some players reported that the game suddenly closed when this mini-game, click and hold started.
The script for calling the game is -
Code:
scene black with slowdiz
        
        $ mg_lantern_win = 0
        $ total_lanterns = 0
        $ mg_lantern_win2 = 0
        $ guild_event2_total_room_price = 0
        "Master your precision: Hold down the mouse button to align the bar flawlessly within the small box."
        
        play music music_action
        jump mg_lantern_label
#####BELOW LABEL IS THE MINIGAME START AND HERE GAME CRASHES#####
label mg_lantern_label:
    show mg_lantern_unlit
    
    python:
        total_lanterns += 1
        randfloat = renpy.random.random() * 2.0 + 0.5
        ui.add(mg_lantern_screen(2.5,randfloat))
        winner = ui.interact(suppress_overlay=True, suppress_window=True)

    window show None
    python:
        if winner < 0.1:
            mg_lantern_win+=1 
    if mg_lantern_win>mg_lantern_win2:
        $ mg_lantern_win2 = mg_lantern_win  
        hide mg_lantern_unlit
        show mg_lantern_lit
    "You fixed [mg_lantern_win] lanterns out of 3 lanterns."
    hide mg_lantern_lit

    if total_lanterns < 3:
        jump mg_lantern_label
    "{b}{size=*1.2}Final - You fixed [mg_lantern_win] lanterns out of 3 lanterns."
    
    jump guild_event2_after_lantern


here is the game mechanism:

Code:
init:
    python:
        import math

        from vec2d import vec2d
        class mg_lantern_screen(renpy.Displayable):
            def __init__(self, time_limit, time_target):
                renpy.Displayable.__init__(self)
                
                self.time_limit = time_limit
                self.time_target = time_target
                
                
                # Some displayables we use.
                self.panel = Image("images/mini_game_lantern/mg_lantern_panel.png")
                self.meter = Image("images/mini_game_lantern/mg_lantern_meter.png")
                self.arrow = Image("images/mini_game_lantern/mg_lantern_arrow.png")
                self.ctb = Text("Click and Hold to repair the lantern.", size=36, drop_shadow=(2,2), drop_shadow_color="#C0C0C0")
                
                # The sizes of some of the images.
                self.METER_WIDTH = 50.0
                self.METER_HEIGHT = 400.0
                
                # Started.
                self.started = False
                
                # The time of the past render-frame.
                self.oldst = None
                self.time_passed = 0.0
                
            def score(self):
                return math.fabs(self.time_target-self.time_passed)
                
            # draws the screen.
            def render(self, width, height, st, at):
                # Figure out the time elapsed since the previous frame.
                if self.oldst is None and self.started:
                    self.oldst = st
                if self.started:    
                    self.time_passed = st - self.oldst
                # The Render object we'll be drawing into.
                r = renpy.Render(width, height)
                
                
                # pixel_height = self.METER_HEIGHT * (self.time_passed/self.time_limit)
                pixel_height = min(self.METER_HEIGHT * (self.time_passed/self.time_limit), self.METER_HEIGHT)
                target_height = self.METER_HEIGHT - (self.METER_HEIGHT * (float(self.time_target)/float(self.time_limit)))
                
                
                eileen = renpy.render( self.panel, width, height, st, at)
                ew, eh = eileen.get_size()
                r.blit(eileen, (width*0.75 - ew / 2, height/2 - eh/ 2))
                
                
                temp_meter = im.Crop(self.meter,0,self.METER_HEIGHT-pixel_height,self.METER_WIDTH,pixel_height)
                eileen = renpy.render( temp_meter, width, height, st, at)
                r.blit(eileen, (width*0.75 - self.METER_WIDTH / 2, height/2 + self.METER_HEIGHT/ 2-pixel_height))
                       
                meter = renpy.render( self.arrow, width, height, st, at)
                ew, eh = meter.get_size()
                r.blit(meter, (width*0.75 - self.METER_WIDTH / 2, (height/2) - (self.METER_HEIGHT/ 2) + target_height - (eh / 2)))
                
                # Show the "Click to Begin" label.
                if self.started == False:
                    ctb = renpy.render(self.ctb, 800, 600, st, at)
                    cw, ch = ctb.get_size()
                    r.blit(ctb, (width*0.5 - cw / 2, height*0.25 - ch/2)) 
                    

                # Ask that we be re-rendered ASAP, so we can show the next
                # frame.
                renpy.redraw(self, 0)
                
                # Return the Render object.
                return r
            
            # Handles events.
            def event(self, ev, x, y, st):
                import pygame
                
                # Mousebutton down == start the game by setting stuck to
                # false.
                if ev.type == pygame.MOUSEBUTTONDOWN and ev.button == 1:
                    self.started = True
                if ev.type == pygame.MOUSEBUTTONUP and ev.button == 1 and self.started:
                    return  self.score()
                if self.started:
                    if self.time_passed < self.time_limit:
                        raise renpy.IgnoreEvent()
                    else:
                        return self.score()
                else:
                    raise renpy.IgnoreEvent()
There's a vec2d file as well, if anyone wanna take a look, please just ask.

Does anyone have any clue why some players are experiencing this issue?