Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
L
libSDL
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
PocketInsanity
libSDL
Commits
3d9620ed
Commit
3d9620ed
authored
Dec 01, 2010
by
Sam Lantinga
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Fixed massive stack memory usage in the gesture functions
parent
56c7ba92
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
22 additions
and
21 deletions
+22
-21
SDL_gesture.c
src/events/SDL_gesture.c
+22
-21
No files found.
src/events/SDL_gesture.c
View file @
3d9620ed
...
@@ -294,7 +294,7 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) {
...
@@ -294,7 +294,7 @@ float bestDollarDifference(SDL_FloatPoint* points,SDL_FloatPoint* templ) {
}
}
//DollarPath contains raw points, plus (possibly) the calculated length
//DollarPath contains raw points, plus (possibly) the calculated length
int
dollarNormalize
(
SDL_DollarPath
path
,
SDL_FloatPoint
*
points
)
{
int
dollarNormalize
(
const
SDL_DollarPath
*
path
,
SDL_FloatPoint
*
points
)
{
int
i
;
int
i
;
float
interval
;
float
interval
;
float
dist
;
float
dist
;
...
@@ -303,34 +303,35 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
...
@@ -303,34 +303,35 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
float
xmin
,
xmax
,
ymin
,
ymax
;
float
xmin
,
xmax
,
ymin
,
ymax
;
float
ang
;
float
ang
;
float
w
,
h
;
float
w
,
h
;
float
length
=
path
->
length
;
//Calculate length if it hasn't already been done
//Calculate length if it hasn't already been done
if
(
path
.
length
<=
0
)
{
if
(
length
<=
0
)
{
for
(
i
=
1
;
i
<
path
.
numPoints
;
i
++
)
{
for
(
i
=
1
;
i
<
path
->
numPoints
;
i
++
)
{
float
dx
=
path
.
p
[
i
].
x
-
float
dx
=
path
->
p
[
i
].
x
-
path
.
p
[
i
-
1
].
x
;
path
->
p
[
i
-
1
].
x
;
float
dy
=
path
.
p
[
i
].
y
-
float
dy
=
path
->
p
[
i
].
y
-
path
.
p
[
i
-
1
].
y
;
path
->
p
[
i
-
1
].
y
;
path
.
length
+=
(
float
)(
SDL_sqrt
(
dx
*
dx
+
dy
*
dy
));
length
+=
(
float
)(
SDL_sqrt
(
dx
*
dx
+
dy
*
dy
));
}
}
}
}
//Resample
//Resample
interval
=
path
.
length
/
(
DOLLARNPOINTS
-
1
);
interval
=
length
/
(
DOLLARNPOINTS
-
1
);
dist
=
interval
;
dist
=
interval
;
centroid
.
x
=
0
;
centroid
.
y
=
0
;
centroid
.
x
=
0
;
centroid
.
y
=
0
;
//printf("(%f,%f)\n",path
.p[path.numPoints-1].x,path.p[path.
numPoints-1].y);
//printf("(%f,%f)\n",path
->p[path->numPoints-1].x,path->p[path->
numPoints-1].y);
for
(
i
=
1
;
i
<
path
.
numPoints
;
i
++
)
{
for
(
i
=
1
;
i
<
path
->
numPoints
;
i
++
)
{
float
d
=
(
float
)(
SDL_sqrt
((
path
.
p
[
i
-
1
].
x
-
path
.
p
[
i
].
x
)
*
(
path
.
p
[
i
-
1
].
x
-
path
.
p
[
i
].
x
)
+
float
d
=
(
float
)(
SDL_sqrt
((
path
->
p
[
i
-
1
].
x
-
path
->
p
[
i
].
x
)
*
(
path
->
p
[
i
-
1
].
x
-
path
->
p
[
i
].
x
)
+
(
path
.
p
[
i
-
1
].
y
-
path
.
p
[
i
].
y
)
*
(
path
.
p
[
i
-
1
].
y
-
path
.
p
[
i
].
y
)));
(
path
->
p
[
i
-
1
].
y
-
path
->
p
[
i
].
y
)
*
(
path
->
p
[
i
-
1
].
y
-
path
->
p
[
i
].
y
)));
//printf("d = %f dist = %f/%f\n",d,dist,interval);
//printf("d = %f dist = %f/%f\n",d,dist,interval);
while
(
dist
+
d
>
interval
)
{
while
(
dist
+
d
>
interval
)
{
points
[
numPoints
].
x
=
path
.
p
[
i
-
1
].
x
+
points
[
numPoints
].
x
=
path
->
p
[
i
-
1
].
x
+
((
interval
-
dist
)
/
d
)
*
(
path
.
p
[
i
].
x
-
path
.
p
[
i
-
1
].
x
);
((
interval
-
dist
)
/
d
)
*
(
path
->
p
[
i
].
x
-
path
->
p
[
i
-
1
].
x
);
points
[
numPoints
].
y
=
path
.
p
[
i
-
1
].
y
+
points
[
numPoints
].
y
=
path
->
p
[
i
-
1
].
y
+
((
interval
-
dist
)
/
d
)
*
(
path
.
p
[
i
].
y
-
path
.
p
[
i
-
1
].
y
);
((
interval
-
dist
)
/
d
)
*
(
path
->
p
[
i
].
y
-
path
->
p
[
i
-
1
].
y
);
centroid
.
x
+=
points
[
numPoints
].
x
;
centroid
.
x
+=
points
[
numPoints
].
x
;
centroid
.
y
+=
points
[
numPoints
].
y
;
centroid
.
y
+=
points
[
numPoints
].
y
;
numPoints
++
;
numPoints
++
;
...
@@ -344,7 +345,7 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
...
@@ -344,7 +345,7 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
return
0
;
return
0
;
}
}
//copy the last point
//copy the last point
points
[
DOLLARNPOINTS
-
1
]
=
path
.
p
[
path
.
numPoints
-
1
];
points
[
DOLLARNPOINTS
-
1
]
=
path
->
p
[
path
->
numPoints
-
1
];
numPoints
=
DOLLARNPOINTS
;
numPoints
=
DOLLARNPOINTS
;
centroid
.
x
/=
numPoints
;
centroid
.
x
/=
numPoints
;
...
@@ -386,7 +387,7 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
...
@@ -386,7 +387,7 @@ int dollarNormalize(SDL_DollarPath path,SDL_FloatPoint *points) {
return
numPoints
;
return
numPoints
;
}
}
float
dollarRecognize
(
SDL_DollarPath
path
,
int
*
bestTempl
,
SDL_GestureTouch
*
touch
)
{
float
dollarRecognize
(
const
SDL_DollarPath
*
path
,
int
*
bestTempl
,
SDL_GestureTouch
*
touch
)
{
SDL_FloatPoint
points
[
DOLLARNPOINTS
];
SDL_FloatPoint
points
[
DOLLARNPOINTS
];
int
numPoints
=
dollarNormalize
(
path
,
points
);
int
numPoints
=
dollarNormalize
(
path
,
points
);
...
@@ -528,7 +529,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
...
@@ -528,7 +529,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
#ifdef ENABLE_DOLLAR
#ifdef ENABLE_DOLLAR
if
(
inTouch
->
recording
)
{
if
(
inTouch
->
recording
)
{
inTouch
->
recording
=
SDL_FALSE
;
inTouch
->
recording
=
SDL_FALSE
;
dollarNormalize
(
inTouch
->
dollarPath
,
path
);
dollarNormalize
(
&
inTouch
->
dollarPath
,
path
);
//PrintPath(path);
//PrintPath(path);
if
(
recordAll
)
{
if
(
recordAll
)
{
index
=
SDL_AddDollarGesture
(
NULL
,
path
);
index
=
SDL_AddDollarGesture
(
NULL
,
path
);
...
@@ -549,7 +550,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
...
@@ -549,7 +550,7 @@ void SDL_GestureProcessEvent(SDL_Event* event)
else
{
else
{
int
bestTempl
;
int
bestTempl
;
float
error
;
float
error
;
error
=
dollarRecognize
(
inTouch
->
dollarPath
,
error
=
dollarRecognize
(
&
inTouch
->
dollarPath
,
&
bestTempl
,
inTouch
);
&
bestTempl
,
inTouch
);
if
(
bestTempl
>=
0
){
if
(
bestTempl
>=
0
){
//Send Event
//Send Event
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment