[Solved] Custom SL Statement Bug: AttributeError: 'NoneType' object has no attribute 'copy_on_change'

Discuss how to use the Ren'Py engine to create visual novels and story-based games. New releases are announced in this section.
Forum rules
This is the right place for Ren'Py help. Please ask one question per thread, use a descriptive subject like 'NotFound error in option.rpy' , and include all the relevant information - especially any relevant code and traceback messages. Use the code tag to format scripts.
Post Reply
Message
Author
User avatar
IcyValet
Newbie
Posts: 11
Joined: Fri Feb 08, 2019 11:13 pm
itch: icyvalet
Contact:

[Solved] Custom SL Statement Bug: AttributeError: 'NoneType' object has no attribute 'copy_on_change'

#1 Post by IcyValet »

This is a strange bug that randomly occurs with my custom screen language statement registered using renpy.register_sl_statement

The custom sl element is a button. The button works fine most of the time, but sometime this exception would occur: AttributeError: 'NoneType' object has no attribute 'copy_on_change' when the button is pressed. The trigger seems to be when the custom sl element is hidden.

Interestingly, adding blank lines/comments to the file with the screen where the bug occurs "temporarily" fixes the bug, so it might have something to do with the cache.

To reproduce the bug, try this project file:

https://drive.google.com/file/d/1lJjBkD ... sp=sharing

1. At the main menu, press "Battle Test", and click 4 times to reach the battle menu. ATTACK, and RUN trigger the exception, but ANALYZE doesn't.
2. Now close the game and modify game/battle.rpy (by adding blank lines or comments), save the file, then reload the game.
3. ATTACK and RUN should now work properly.
4. Now close the game, and reload the game.
5. ATTACK and RUN should cause the exception again. Very bizzare!

This reproduction is consistent on my end, hopefully it is for you too.

The custom button screen is "btn" in templates.rpy
The renpy.register_sl_statement is in 000.rpy

Here's the full traceback:

Code: Select all

I'm sorry, but an uncaught exception occurred.

While running game code:
  File "game/battle.rpy", line 53, in script call
    call battle()
  File "game/battle.rpy", line 108, in script call
    call battle_loop
  File "game/battle.rpy", line 121, in script
    call screen battle_action
  File "renpy/common/000statements.rpy", line 570, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "game/battle.rpy", line 176, in copy_on_change
    screen battle_action():
  File "game/battle.rpy", line 178, in copy_on_change
    frame:
  File "game/battle.rpy", line 185, in copy_on_change
    fixed:
  File "game/battle.rpy", line 187, in copy_on_change
    frame:
  File "game/battle.rpy", line 190, in copy_on_change
    hbox:
AttributeError: 'NoneType' object has no attribute 'copy_on_change'

-- Full Traceback ------------------------------------------------------------

Full traceback:
  File "game/battle.rpy", line 53, in script call
    call battle()
  File "game/battle.rpy", line 108, in script call
    call battle_loop
  File "game/battle.rpy", line 121, in script
    call screen battle_action
  File "renpy/ast.py", line 1969, in execute
    self.call("execute")
  File "renpy/ast.py", line 1957, in call
    return renpy.statements.call(method, parsed, *args, **kwargs)
  File "renpy/statements.py", line 278, in call
    return method(parsed, *args, **kwargs)
  File "renpy/common/000statements.rpy", line 570, in execute_call_screen
    store._return = renpy.call_screen(name, *args, **kwargs)
  File "renpy/exports.py", line 2983, in call_screen
    rv = renpy.ui.interact(mouse="screen", type="screen", roll_forward=roll_forward)
  File "renpy/ui.py", line 298, in interact
    rv = renpy.game.interface.interact(roll_forward=roll_forward, **kwargs)
  File "renpy/display/core.py", line 3113, in interact
    scene_lists.replace_transient()
  File "renpy/display/core.py", line 914, in replace_transient
    self.remove(layer, tag, prefix=prefix)
  File "renpy/display/core.py", line 1223, in remove
    self.hide_or_replace(layer, remove_index, prefix)
  File "renpy/display/core.py", line 1139, in hide_or_replace
    d = oldsle.displayable._hide(now - st, now - at, prefix)
  File "renpy/display/screen.py", line 505, in _hide
    self.screen.ast.copy_on_change(self.cache.get(0, {}))
  File "game/battle.rpy", line 176, in copy_on_change
    screen battle_action():
  File "game/battle.rpy", line 178, in copy_on_change
    frame:
  File "game/battle.rpy", line 185, in copy_on_change
    fixed:
  File "game/battle.rpy", line 187, in copy_on_change
    frame:
  File "game/battle.rpy", line 190, in copy_on_change
    hbox:
  File "renpy/sl2/slast.py", line 2176, in copy_on_change
    self.ast.copy_on_change(c)
AttributeError: 'NoneType' object has no attribute 'copy_on_change'

Windows-10-10.0.19041
Ren'Py 7.4.4.1439
BUGTEST 1
Mon May 17 14:34:49 2021
Last edited by IcyValet on Wed May 19, 2021 10:31 am, edited 1 time in total.

User avatar
PyTom
Ren'Py Creator
Posts: 16096
Joined: Mon Feb 02, 2004 10:58 am
Completed: Moonlight Walks
Projects: Ren'Py
IRC Nick: renpytom
Github: renpytom
itch: renpytom
Location: Kings Park, NY
Contact:

Re: Custom SL Statement Bug: AttributeError: 'NoneType' object has no attribute 'copy_on_change'

#2 Post by PyTom »

This was a really subtle bug, but it will be fixed in the second prerelease of Ren'Py 7.4.5.

Thank you for putting together the replication for me, it was a big help.
Supporting creators since 2004
(When was the last time you backed up your game?)
"Do good work." - Virgil Ivan "Gus" Grissom
Software > Drama • https://www.patreon.com/renpytom


Post Reply

Who is online

Users browsing this forum: Ocelot