1
$\begingroup$

I’m currently developing an addon for Blender. The addon (simply put) is just a cool material, but I’m creating some custom UI elements for changing the material nodes, in the sidebar (n-panel). I’ve already spent about 1 month on this (part time) and am close to releasing it. Though I’ve just found some big problems with it and am not sure what the reason is.

When changing some node settings with the UI elements, and then using ctrl+Z, blender crashes. Sometimes 1 undo works and it crashes on the second one, sometimes on the third one. But nearly always it crashes. It just closes. I tried to look for some crash reports to find out the reason. Even though, in the temp folder, there is a blender folder with the correct creation time the crash occurred, the folder is empty. I tried to narrow it down myself, by activating the system memory and video memory statistics, by right clicking in the bottom right, where the version number is. Even on the crash, it uses just about 30% of the memory. Another thing I tried was to have the task manager run on the side. Also here, everything stayed below 30% except the GPU. 1 second after the crash, it spiked for a few milliseconds to 100% I’m not sure if that is the reason of the crash, or just a reaction to the crash. Nevertheless, I tried updating my GTX 1070 Drivers, though I could not install the latest version. It just says an error occurred, and to try again. Another thing I tried was to do the same thing I did before (changing the same nodes and undoing), but in the shader editor, without loading the script for the UI elements. This did not crash Blender, and everything worked fine.

So the Problem seems to come from the script I’m developing. But since there is no Error message or crash report, I have no Idea what is causing it. Like I said, I’ve already spent quite some time on the script, and am quite proud of it. Question: How can I find the cause of the problem?

$\endgroup$
2
  • 1
    $\begingroup$ Hello ! It is impossible to say without seeing at least some parts of your script. This can be caused by a multitude of things. Always make sure your references are stored in bpy.props properties, Don't modify things in a draw method. Don't modify things in another property if you're using the update callback. etc $\endgroup$
    – Gorgious
    Commented May 17, 2023 at 8:55
  • $\begingroup$ It seems the question is not only about what the problem is, but also about how to find it. I think it might be useful if it gets answers about how to look for problems. $\endgroup$ Commented May 17, 2023 at 10:34

2 Answers 2

1
$\begingroup$

bpy_struct references cannot be safely used outside of the continuous python execution they were created in. The Undo/Redo rebuilds the references of the python exposed bpy.data and the dereferencing may access the memory which is not longer the original objects.

The Gotchas about it: https://docs.blender.org/api/current/info_gotcha.html#help-my-script-crashes-blender

For your case.

When you assign context.scene.planet_list.add() to bpy.app.driver_namespace["current_item"] in planet_list_01.LIST_OT_NewItem.execute and do the Undo/Redo the reference to the bpy_struct ListItem is invalid and using item = bpy.app.driver_namespace["current_item"] in Easy PLANETS_13.CUSTOMPLANET_PT_main.draw may lead to a crash.

You can replace the use of bpy.app.driver_namespace["current_item"] with bpy.context.scene.planet_list[bpy.context.scene.list_index] if bpy.context.scene.planet_list else None and remove the use of bpy.app.driver_namespace["current_item"] completely.

$\endgroup$
0
$\begingroup$

Be sure to read Gotchas section in the documentation for Blender's Python API.

You could reduce your script's functionality by removing code bit by bit while testing. When crashing stops - it means the thing you removed last is the cause.

Sharing the code or part of it here if possible might also help as there are many experienced Python coders around and they might find the issue, or at least come up with more specific suggestions how to approach this.

$\endgroup$
7
  • $\begingroup$ Well, the addon is quite big. It also requirest a 2 GB Folder of Images and files to work. Sharing all that is not that easy. But the Gotchas section is quite helpfull already. I will see if I can narrow down the problematic area with this. Thanks! $\endgroup$
    – DerMalt
    Commented May 17, 2023 at 9:56
  • $\begingroup$ I suspected there might be reasons not to share the whole code, but maybe if you narrow it down it could be possible to share a part of it with the problem if you still need help at that point. $\endgroup$ Commented May 17, 2023 at 10:29
  • $\begingroup$ Hey, I'm actually not much of a coder, but my brother is. He knows Python, but not specifically for Blender. Yesterday we think we narrowed down the problem to an Ui_List and some update functions. We can now pretty reliable reproduce the error, even without the 2GB folder. So I could share this code, once I've wrote down the exact steps to reproduce the error. Just note, that the code still is quite messy. Also, my brother is not available for the next days, so if there are some questions more indepth, I probably cant help there. I will post a google drive folder here, when done. thanks! $\endgroup$
    – DerMalt
    Commented May 18, 2023 at 10:48
  • $\begingroup$ It would be better if you edit the question and post the code there directly if possible. This makes it easier for people answering BSE questions since they don't have to follow links and can see everything in one place and it remains there to help others searching for similar solutions in the future. It's kind of a rule to post everything in the question instead of external links on Stack Exchange. If it's too much to post in the question, it's probably too much for BSE, maybe post on Blenderartists.org forums instead. You can share a link in comments for those who are willing to try to help. $\endgroup$ Commented May 18, 2023 at 12:27
  • $\begingroup$ And by too much for BSE, I mean it's starting to sound like it's "too localized" and "unlikely to be applicable outside of a very narrow context." which is not really suitable for Blender Stack Exchange. $\endgroup$ Commented May 18, 2023 at 12:32

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .