UPBGE / upbge

UPBGE, the best integrated game engine in Blender
https://upbge.org
Other
1.39k stars 177 forks source link

VERSION 0.4.0 importing and converting objects from other Blend files causes a crash IF you are in camera view. #1847

Closed Feral3d closed 9 months ago

Feral3d commented 9 months ago

IF you load and convert assets from another Blender file, BUT you are currently "in Camera View", then it causes a crash.

IF you load and convert assets from another Blender file, BUT you are currently NOT "in Camera View", then it successfully loads the assets, while failing to convert "game_default_cam"

I have attached an example test showing the bug:

Just open "EXAMPLE.blend" in version 0.4.0 and press "P" and it will load and convert a suzanne perfectly. Then switch the viewport to the only camera in the scene and press "P", and it will cause a crash.

TSL_TEST.zip

youle31 commented 9 months ago

Thanks for the report. There are some cases like in your file where an object can't be converted, for example, if we are trying to convert again an object which has already been converted, or with game_default_cam which is a special case (we need it for initial conversion, but we prevent its conversion another time).

game_default_cam is a bpy.types.Object always created when we load a new scene.

This cam is added to scene->master_collection and can be in the same collection than other objects that you have in outliner before game start.

If we are not in camera view at game start, this cam will be used as blenderObject for the default KX_Camera created because we always need a KX_Camera with its corresponding blenderObject in 0.3+.

If we are in camera view at game start, game_default_cam won't be used by any KX_Camera but is still there in outliner even if you can't see it before game start.

game_default_cam is deleted only at KX_Scene exit.

I tried to mitigate the issue here: https://github.com/UPBGE/upbge/commit/037c66830b3c3c75203b9fdecde514e4cb42da63 to prevent the crash and adding a warning to tell what is happening if for some reasons an Object can't be converted.