Skip to content

Commit

Permalink
Fix error when spawning on object with no materials. Fix windows cras…
Browse files Browse the repository at this point in the history
…hes due to input thread not joining
  • Loading branch information
jaburns committed Aug 4, 2021
1 parent 1a39361 commit 46075a2
Showing 1 changed file with 28 additions and 15 deletions.
43 changes: 28 additions & 15 deletions mario.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
from . collision_types import COLLISION_TYPES

if platform.system() == 'Windows':
from . input_reader_win import sample_input_reader, start_input_reader
from . input_reader_win import sample_input_reader, start_input_reader, stop_input_reader
else:
from . input_reader import sample_input_reader, start_input_reader
from . input_reader import sample_input_reader, start_input_reader, stop_input_reader

SM64_TEXTURE_WIDTH = 64 * 11
SM64_TEXTURE_HEIGHT = 64
Expand Down Expand Up @@ -80,11 +80,19 @@ def insert_mario(rom_path: str, scale: float, pos):

SM64_SCALE_FACTOR = scale

try:
bpy.ops.object.mode_set(mode='OBJECT')
except:
pass
bpy.ops.object.select_all(action='DESELECT')
if 'LibSM64 Mario' in bpy.data.objects:
return
bpy.data.objects['LibSM64 Mario'].select_set(True) # Blender 2.8x
bpy.ops.object.delete()

stop_input_reader()

if sm64 != None:
sm64.sm64_global_terminate()
stop_tick_mario()

this_path = os.path.dirname(os.path.realpath(__file__))
dll_name = 'sm64.dll' if platform.system() == 'Windows' else 'libsm64.so'
Expand Down Expand Up @@ -133,16 +141,21 @@ def insert_mario(rom_path: str, scale: float, pos):

return None

def stop_tick_mario():
global sm64, sm64_mario_id, original_fps
bpy.app.handlers.frame_change_pre.clear()
bpy.context.scene.render.fps = original_fps
bpy.ops.screen.animation_cancel()
sm64_mario_id = -1
sm64.sm64_global_terminate()
sm64 = None
stop_input_reader()

def tick_mario(x0, x1):
global sm64, sm64_mario_id, mario_state, mario_geo, tick_count

if not ('LibSM64 Mario' in bpy.data.objects):
bpy.app.handlers.frame_change_pre.clear()
bpy.context.scene.render.fps = original_fps
bpy.ops.screen.animation_cancel()
sm64_mario_id = -1
sm64.sm64_global_terminate()
sm64 = None
stop_tick_mario()
return 0

sample_input_reader(mario_inputs)
Expand Down Expand Up @@ -224,11 +237,11 @@ def add_mesh(obj: bpy.types.Object, out):
else:
break

mat = mesh.materials[tri.material_index]
if hasattr(mat, 'collision_type_simple'):
out_elem['surftype'] = COLLISION_TYPES[mat.collision_type_simple]
else:
out_elem['surftype'] = COLLISION_TYPES['SURFACE_DEFAULT']
out_elem['surftype'] = COLLISION_TYPES['SURFACE_DEFAULT']
if tri.material_index > 0 and tri.material_index < len(mesh.materials):
mat = mesh.materials[tri.material_index]
if hasattr(mat, 'collision_type_simple'):
out_elem['surftype'] = COLLISION_TYPES[mat.collision_type_simple]

out.append(out_elem)

Expand Down

0 comments on commit 46075a2

Please sign in to comment.