Fix merge box crash on connect

main
Cameron Murphy Reikes 2 years ago
parent 8d32399034
commit 30f492718a

Binary file not shown.

@ -409,7 +409,7 @@ LauncherTarget missile_launcher_target(GameState *gs, Entity *launcher)
void destroy_constraints(cpBody *body, cpConstraint *constraint, void *data) void destroy_constraints(cpBody *body, cpConstraint *constraint, void *data)
{ {
((Entity*)cpConstraintGetUserData(constraint))->landed_constraint = NULL; ((Entity *)cpConstraintGetUserData(constraint))->landed_constraint = NULL;
cpSpaceRemoveConstraint(cpBodyGetSpace(body), constraint); cpSpaceRemoveConstraint(cpBodyGetSpace(body), constraint);
cpConstraintFree(constraint); cpConstraintFree(constraint);
} }
@ -463,7 +463,7 @@ void entity_memory_free(GameState *gs, Entity *e)
if (e->body != NULL) if (e->body != NULL)
{ {
// need to do this here because body which constraint is attached to can be destroyed // need to do this here because body which constraint is attached to can be destroyed
// NOT TRUE: can't do this here because the handle to the constraint cannot be set to NULL. Constraints are freed by the entities that own them // NOT TRUE: can't do this here because the handle to the constraint cannot be set to NULL. Constraints are freed by the entities that own them
cpBodyEachConstraint(e->body, destroy_constraints, NULL); cpBodyEachConstraint(e->body, destroy_constraints, NULL);
cpBodyEachShape(e->body, destroy_child_shape, (void *)gs); cpBodyEachShape(e->body, destroy_child_shape, (void *)gs);
cpSpaceRemoveBody(gs->space, e->body); cpSpaceRemoveBody(gs->space, e->body);
@ -534,7 +534,7 @@ void create_body(GameState *gs, Entity *e)
} }
// must always call this after creating a constraint // must always call this after creating a constraint
void on_create_constraint(Entity *e, cpConstraint* c) void on_create_constraint(Entity *e, cpConstraint *c)
{ {
cpConstraintSetUserData(c, (cpDataPointer)e); cpConstraintSetUserData(c, (cpDataPointer)e);
} }
@ -2729,7 +2729,7 @@ void process(struct GameState *gs, double dt)
#if 1 #if 1
cpVect world_hand_pos = get_world_hand_pos(gs, &player->input, p); cpVect world_hand_pos = get_world_hand_pos(gs, &player->input, p);
if(player->input.interact_action) if (player->input.interact_action)
{ {
player->input.interact_action = false; player->input.interact_action = false;
cpPointQueryInfo query_info = {0}; cpPointQueryInfo query_info = {0};
@ -2945,6 +2945,7 @@ void process(struct GameState *gs, double dt)
PROFILE_SCOPE("process entities") PROFILE_SCOPE("process entities")
{ {
ENTITIES_ITER(gs, e) ENTITIES_ITER(gs, e)
if (!e->flag_for_destruction)
{ {
if (e->body != NULL && cpvlengthsq((entity_pos(e))) > (INSTANT_DEATH_DISTANCE_FROM_CENTER * INSTANT_DEATH_DISTANCE_FROM_CENTER)) if (e->body != NULL && cpvlengthsq((entity_pos(e))) > (INSTANT_DEATH_DISTANCE_FROM_CENTER * INSTANT_DEATH_DISTANCE_FROM_CENTER))
{ {

Loading…
Cancel
Save