Skip to content

Commit

Permalink
Merge pull request #25 from erayzesen/bugfix/fix-memory-conflict-issues
Browse files Browse the repository at this point in the history
Fix Memory Conflict Issues
  • Loading branch information
erayzesen authored Jan 21, 2025
2 parents 013a8a7 + e0edeaa commit 9cb40c8
Show file tree
Hide file tree
Showing 30 changed files with 212 additions and 75 deletions.
Binary file modified .sconsign.dblite
Binary file not shown.
20 changes: 20 additions & 0 deletions project/examples/3_joints/main.tscn
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(-1500, -150, 1500, -150, 1500, 150, -1500, 150)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 0)])
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 2), PackedInt32Array(1, 3)])
data_polygon = PackedInt32Array(0, 1, 2, 3)
Expand Down Expand Up @@ -61,6 +63,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(-30, -30, 30, -30, 30, 30, -30, 30)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 0)])
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 2), PackedInt32Array(1, 3)])
data_polygon = PackedInt32Array(0, 1, 2, 3)
Expand All @@ -76,6 +80,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(32, 0, 22.6274, 22.6274, -1.39876e-06, 32, -22.6274, 22.6274, -32, -2.79753e-06, -22.6274, -22.6274, 3.81596e-07, -32, 22.6274, -22.6274)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1, 1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0, 0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 4), PackedInt32Array(4, 5), PackedInt32Array(5, 6), PackedInt32Array(6, 7), PackedInt32Array(7, 0)])
data_polygon = PackedInt32Array(0, 1, 2, 3, 4, 5, 6, 7)
data_uv_maps = Array[PackedInt32Array]([PackedInt32Array(0, 1, 2, 3, 4, 5, 6, 7)])
Expand Down Expand Up @@ -154,6 +160,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(-30, -30, 30, -30, 30, 30, -30, 30)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 0)])
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 2), PackedInt32Array(1, 3)])
data_polygon = PackedInt32Array(0, 1, 2, 3)
Expand All @@ -170,6 +178,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(-30, -30, 30, -30, 30, 30, -30, 30)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 0)])
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 2), PackedInt32Array(1, 3)])
data_polygon = PackedInt32Array(0, 1, 2, 3)
Expand All @@ -190,6 +200,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(-8, -30, 8, -30, 8, 30, -8, 30)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 0)])
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 2), PackedInt32Array(1, 3)])
data_polygon = PackedInt32Array(0, 1, 2, 3)
Expand All @@ -206,6 +218,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(-8, -30, 8, -30, 8, 30, -8, 30)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 0)])
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 2), PackedInt32Array(1, 3)])
data_polygon = PackedInt32Array(0, 1, 2, 3)
Expand All @@ -222,6 +236,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(-8, -30, 8, -30, 8, 30, -8, 30)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 0)])
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 2), PackedInt32Array(1, 3)])
data_polygon = PackedInt32Array(0, 1, 2, 3)
Expand All @@ -238,6 +254,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(-8, -30, 8, -30, 8, 30, -8, 30)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 0)])
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 2), PackedInt32Array(1, 3)])
data_polygon = PackedInt32Array(0, 1, 2, 3)
Expand All @@ -254,6 +272,8 @@ enable_stroke = true
data_particle_positions = PackedVector2Array(-8, -30, 8, -30, 8, 30, -8, 30)
data_particle_radius = PackedFloat32Array(0.5, 0.5, 0.5, 0.5)
data_particle_is_internal = PackedByteArray(0, 0, 0, 0)
data_particle_is_enabled = PackedByteArray(1, 1, 1, 1)
data_particle_is_lazy = PackedByteArray(0, 0, 0, 0)
data_springs = Array[PackedInt32Array]([PackedInt32Array(0, 1), PackedInt32Array(1, 2), PackedInt32Array(2, 3), PackedInt32Array(3, 0)])
data_internal_springs = Array[PackedInt32Array]([PackedInt32Array(0, 2), PackedInt32Array(1, 3)])
data_polygon = PackedInt32Array(0, 1, 2, 3)
Expand Down
13 changes: 7 additions & 6 deletions project/examples/7_classic_platformer/main.tscn
Original file line number Diff line number Diff line change
@@ -1,11 +1,12 @@
[gd_scene load_steps=16 format=4 uid="uid://dw06ipgwyx2cc"]
[gd_scene load_steps=17 format=4 uid="uid://dw06ipgwyx2cc"]

[ext_resource type="Script" path="res://examples/7_classic_platformer/player.gd" id="1_b5iax"]
[ext_resource type="Texture2D" uid="uid://d3j7v6kge2who" path="res://examples/7_classic_platformer/sprites/tileset.png" id="1_ibcbn"]
[ext_resource type="Script" path="res://examples/7_classic_platformer/moveable_platform.gd" id="2_hvcqu"]
[ext_resource type="Script" path="res://examples/7_classic_platformer/door_button.gd" id="2_ndt36"]
[ext_resource type="Script" path="res://addons/quarkphysics/helper_nodes/qtilemap_collider.gd" id="2_yuswt"]
[ext_resource type="Script" path="res://examples/7_classic_platformer/coin.gd" id="3_5al4l"]
[ext_resource type="Script" path="res://examples/7_classic_platformer/q_world_node.gd" id="4_5rs6g"]
[ext_resource type="Script" path="res://examples/7_classic_platformer/finish_area.gd" id="4_mmqkf"]
[ext_resource type="Script" path="res://examples/7_classic_platformer/flag.gd" id="8_b3t3c"]

Expand Down Expand Up @@ -78,10 +79,6 @@ sources/1 = SubResource("TileSetAtlasSource_qdrbb")
[node name="Node2D" type="Node2D"]
metadata/_edit_horizontal_guides_ = [352.0]

[node name="QWorldNode" type="QWorldNode" parent="."]
debug_renderer = false
enable_debug_mouse_interactions = true

[node name="background" type="ColorRect" parent="."]
offset_left = -80.0
offset_right = 1008.0
Expand All @@ -99,6 +96,11 @@ key w: jump
"
label_settings = SubResource("LabelSettings_2ckbs")

[node name="QWorldNode" type="QWorldNode" parent="."]
debug_renderer = false
enable_debug_mouse_interactions = true
script = ExtResource("4_5rs6g")

[node name="DoorButton" type="QRigidBodyNode" parent="." node_paths=PackedStringArray("door")]
fixed_rotation = true
mass = 0.1
Expand Down Expand Up @@ -283,7 +285,6 @@ collision_visibility_mode = 1

[node name="QTileMapCollider" type="Node2D" parent="TileMapLayer"]
script = ExtResource("2_yuswt")
merge_mode = 1

[node name="Door" type="QRigidBodyNode" parent="."]
fixed_rotation = true
Expand Down
23 changes: 0 additions & 23 deletions project/examples/7_classic_platformer/plant.gd

This file was deleted.

15 changes: 15 additions & 0 deletions project/examples/7_classic_platformer/q_world_node.gd
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
extends QWorldNode


# Called when the node enters the scene tree for the first time.
func _ready() -> void:
call_deferred("move_zero")
pass # Replace with function body.

func move_zero():
get_parent().move_child(self,0)


# Called every frame. 'delta' is the elapsed time since the previous frame.
func _process(delta: float) -> void:
pass
4 changes: 2 additions & 2 deletions project/examples/examples_main.tscn
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
[gd_scene load_steps=2 format=3 uid="uid://b5wjks0a7qvwl"]

[ext_resource type="Script" path="res://examples/examples_main.gd" id="1_mqb4e"]
[ext_resource type="Script" path="res://examples/examples_main.gd" id="1_g2bxu"]

[node name="Node2D" type="Node2D"]
script = ExtResource("1_mqb4e")
script = ExtResource("1_g2bxu")
39 changes: 39 additions & 0 deletions project/export_presets.cfg
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
[preset.0]

name="Linux"
platform="Linux"
runnable=true
advanced_options=false
dedicated_server=false
custom_features=""
export_filter="all_resources"
include_filter=""
exclude_filter=""
export_path="../../../../../../home/eray/Documents/qp_example_test.x86_64"
encryption_include_filters=""
encryption_exclude_filters=""
encrypt_pck=false
encrypt_directory=false
script_export_mode=2

[preset.0.options]

custom_template/debug=""
custom_template/release=""
debug/export_console_wrapper=1
binary_format/embed_pck=false
texture_format/s3tc_bptc=true
texture_format/etc2_astc=false
binary_format/architecture="x86_64"
ssh_remote_deploy/enabled=false
ssh_remote_deploy/host="user@host_ip"
ssh_remote_deploy/port="22"
ssh_remote_deploy/extra_args_ssh=""
ssh_remote_deploy/extra_args_scp=""
ssh_remote_deploy/run_script="#!/usr/bin/env bash
export DISPLAY=:0
unzip -o -q \"{temp_dir}/{archive_name}\" -d \"{temp_dir}\"
\"{temp_dir}/{exe_name}\" {cmd_args}"
ssh_remote_deploy/cleanup_script="#!/usr/bin/env bash
kill $(pgrep -x -f \"{temp_dir}/{exe_name} {cmd_args}\")
rm -rf \"{temp_dir}\""
6 changes: 4 additions & 2 deletions src/QuarkPhysics/qbody.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -43,8 +43,10 @@ QBody::~QBody()
{
for(int i=0;i<_meshes.size();i++){
if (_meshes[i]!=nullptr){
delete _meshes[i];
_meshes[i]=nullptr;
if (_meshes[i]->manualDeletion==false){
delete _meshes[i];
_meshes[i]=nullptr;
}
}
}
_meshes.clear();
Expand Down
5 changes: 5 additions & 0 deletions src/QuarkPhysics/qbody.h
Original file line number Diff line number Diff line change
Expand Up @@ -654,6 +654,11 @@ class QBody{
*/
QBody *SetVelocityLimit(float value);

/**
* By default, objects included in the physics engine are deleted by the destructors of the objects they belong to. When this flag is enabled, it indicates that this object should never be deleted by this engine. It is disabled by default, and it is recommended to keep it disabled. However, it can be used if needed for advanced purposes and integrations.
*/
bool manualDeletion=false;


friend class QMesh;
friend class QWorld;
Expand Down
5 changes: 5 additions & 0 deletions src/QuarkPhysics/qjoint.h
Original file line number Diff line number Diff line change
Expand Up @@ -227,6 +227,11 @@ class QJoint
/** Updates the constraints of the joint. */
virtual void Update();

/**
* By default, objects included in the physics engine are deleted by the destructors of the objects they belong to. When this flag is enabled, it indicates that this object should never be deleted by this engine. It is disabled by default, and it is recommended to keep it disabled. However, it can be used if needed for advanced purposes and integrations.
*/
bool manualDeletion=false;

friend class QWorld;


Expand Down
12 changes: 8 additions & 4 deletions src/QuarkPhysics/qmesh.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -44,16 +44,20 @@ QMesh::~QMesh()
{
for(int i=0;i<particles.size();i++){
if (particles[i]!=nullptr){
delete particles[i];
particles[i]=nullptr;
if(particles[i]->manualDeletion==false ){
delete particles[i];
particles[i]=nullptr;
}
}
}
particles.clear();

for(int i=0;i<springs.size();i++){
if(springs[i]!=nullptr){
delete springs[i];
springs[i]=nullptr;
if(springs[i]->manualDeletion==false){
delete springs[i];
springs[i]=nullptr;
}
}
}
springs.clear();
Expand Down
10 changes: 5 additions & 5 deletions src/QuarkPhysics/qmesh.h
Original file line number Diff line number Diff line change
Expand Up @@ -636,13 +636,13 @@ struct QMesh
static vector<QVector> GetMatchingParticlePositions(vector<QParticle*> particleCollection,QVector targetPosition, float targetRotation);







/**
* By default, objects included in the physics engine are deleted by the destructors of the objects they belong to. When this flag is enabled, it indicates that this object should never be deleted by this engine. It is disabled by default, and it is recommended to keep it disabled. However, it can be used if needed for advanced purposes and integrations.
*/
bool manualDeletion=false;



};

#endif // QMESH_H
5 changes: 5 additions & 0 deletions src/QuarkPhysics/qparticle.h
Original file line number Diff line number Diff line change
Expand Up @@ -243,6 +243,11 @@ class QParticle
*/
static void ApplyForceToParticleSegment(QParticle *pA,QParticle *pB,QVector force,QVector fromPosition);

/**
* By default, objects included in the physics engine are deleted by the destructors of the objects they belong to. When this flag is enabled, it indicates that this object should never be deleted by this engine. It is disabled by default, and it is recommended to keep it disabled. However, it can be used if needed for advanced purposes and integrations.
*/
bool manualDeletion=false;


friend class QMesh;
friend class QBody;
Expand Down
7 changes: 7 additions & 0 deletions src/QuarkPhysics/qraycast.h
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,11 @@ class QRaycast
*/
QRaycast *SetCollidableLayersBit(int value);

/**
* By default, objects included in the physics engine are deleted by the destructors of the objects they belong to. When this flag is enabled, it indicates that this object should never be deleted by this engine. It is disabled by default, and it is recommended to keep it disabled. However, it can be used if needed for advanced purposes and integrations.
*/
bool manualDeletion=false;


friend class QWorld;

Expand All @@ -140,6 +145,8 @@ class QRaycast

static bool SortContacts(const QRaycast::Contact contactA,const QRaycast::Contact contactB);



};

#endif // QRAYCAST_H
5 changes: 5 additions & 0 deletions src/QuarkPhysics/qspring.h
Original file line number Diff line number Diff line change
Expand Up @@ -146,6 +146,11 @@ class QSpring
return this;
}

/**
* By default, objects included in the physics engine are deleted by the destructors of the objects they belong to. When this flag is enabled, it indicates that this object should never be deleted by this engine. It is disabled by default, and it is recommended to keep it disabled. However, it can be used if needed for advanced purposes and integrations.
*/
bool manualDeletion=false;




Expand Down
Loading

0 comments on commit 9cb40c8

Please sign in to comment.