Revision 05ecc6fe
Added by Leszek Koltunski over 7 years ago
src/main/java/org/distorted/library/Distorted.java | ||
---|---|---|
123 | 123 |
mInitialized = true; |
124 | 124 |
} |
125 | 125 |
|
126 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
127 |
/** |
|
128 |
* Call this so that the Library can release its internal data structures. |
|
129 |
* Must be called from Activity.onPause(). |
|
130 |
*/ |
|
131 |
public static void onPause() |
|
132 |
{ |
|
133 |
DistortedSurface.onPause(); |
|
134 |
} |
|
135 |
|
|
126 | 136 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
127 | 137 |
/** |
128 | 138 |
* Call this so that the Library can release its internal data structures. |
src/main/java/org/distorted/library/DistortedFramebuffer.java | ||
---|---|---|
124 | 124 |
|
125 | 125 |
void recreate() |
126 | 126 |
{ |
127 |
if( mColorCreated!=DONT_CREATE ) mColorCreated = NOT_CREATED_YET; |
|
128 |
if( mDepthCreated!=DONT_CREATE ) mDepthCreated = NOT_CREATED_YET; |
|
127 |
if( mColorCreated!=DONT_CREATE ) |
|
128 |
{ |
|
129 |
mColorCreated = NOT_CREATED_YET; |
|
130 |
mColorH[0] = 0; |
|
131 |
} |
|
132 |
if( mDepthCreated!=DONT_CREATE ) |
|
133 |
{ |
|
134 |
mDepthCreated = NOT_CREATED_YET; |
|
135 |
mDepthH[0] = 0; |
|
136 |
} |
|
129 | 137 |
} |
130 | 138 |
|
131 | 139 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
src/main/java/org/distorted/library/DistortedSurface.java | ||
---|---|---|
20 | 20 |
package org.distorted.library; |
21 | 21 |
|
22 | 22 |
import java.util.HashMap; |
23 |
import java.util.Iterator; |
|
23 | 24 |
import java.util.LinkedList; |
25 |
import java.util.Map; |
|
24 | 26 |
|
25 | 27 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
26 | 28 |
/** |
... | ... | |
75 | 77 |
abstract void recreate(); |
76 | 78 |
|
77 | 79 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
78 |
// must be called form a thread holding OpenGL Context
|
|
80 |
// must be called from a thread holding OpenGL Context
|
|
79 | 81 |
|
80 | 82 |
static synchronized void toDo() |
81 | 83 |
{ |
... | ... | |
109 | 111 |
|
110 | 112 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
111 | 113 |
|
112 |
static synchronized void onDestroy()
|
|
114 |
static synchronized void onPause()
|
|
113 | 115 |
{ |
114 |
Job job; |
|
115 | 116 |
DistortedSurface surface; |
117 |
int num = mDoneList.size(); |
|
116 | 118 |
|
117 |
for(Long key: mToDoMap.keySet())
|
|
119 |
for(int i=0; i<num; i++)
|
|
118 | 120 |
{ |
119 |
job = mToDoMap.get(key); |
|
120 |
|
|
121 |
if( job.surface.mType==TYPE_SYST ) |
|
122 |
{ |
|
123 |
mDoneList.add(job.surface); |
|
124 |
} |
|
121 |
surface = mDoneList.removeFirst(); |
|
122 |
mToDoMap.put(surface.getID(), surface.new Job(surface,JOB_CREATE) ); |
|
123 |
surface.recreate(); |
|
125 | 124 |
} |
126 | 125 |
|
127 |
mToDoMap.clear(); |
|
126 |
mToDo = true; |
|
127 |
} |
|
128 |
|
|
129 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
|
128 | 130 |
|
129 |
int num = mDoneList.size(); |
|
131 |
static synchronized void onDestroy() |
|
132 |
{ |
|
133 |
Job job; |
|
134 |
Iterator<Map.Entry<Long,Job>> it = mToDoMap.entrySet().iterator(); |
|
130 | 135 |
|
131 |
for(int i=0; i<num; i++)
|
|
136 |
while (it.hasNext())
|
|
132 | 137 |
{ |
133 |
surface = mDoneList.removeFirst(); |
|
134 |
|
|
135 |
if( surface.mType==TYPE_SYST ) |
|
136 |
{ |
|
137 |
mToDoMap.put(surface.getID(), surface.new Job(surface,JOB_CREATE) ); |
|
138 |
surface.recreate(); |
|
139 |
} |
|
138 |
Map.Entry<Long,Job> entry = it.next(); |
|
139 |
job = entry.getValue(); |
|
140 |
if (job.surface.mType!=TYPE_SYST) it.remove(); |
|
140 | 141 |
} |
141 | 142 |
|
143 |
mDoneList.clear(); |
|
144 |
|
|
142 | 145 |
mToDo = true; |
143 | 146 |
mNextClientID = 0; |
144 | 147 |
} |
src/main/java/org/distorted/library/DistortedTexture.java | ||
---|---|---|
85 | 85 |
|
86 | 86 |
void delete() |
87 | 87 |
{ |
88 |
if( mColorH[0]>=0 )
|
|
88 |
if( mColorH[0]>0 ) |
|
89 | 89 |
{ |
90 | 90 |
GLES30.glDeleteTextures(1, mColorH, 0); |
91 | 91 |
mColorH[0] = 0; |
... | ... | |
98 | 98 |
|
99 | 99 |
void recreate() |
100 | 100 |
{ |
101 |
if( mColorCreated!=DONT_CREATE ) mColorCreated = NOT_CREATED_YET; |
|
101 |
if( mColorCreated!=DONT_CREATE ) |
|
102 |
{ |
|
103 |
mColorCreated = NOT_CREATED_YET; |
|
104 |
mColorH[0] = 0; |
|
105 |
} |
|
102 | 106 |
} |
103 | 107 |
|
104 | 108 |
/////////////////////////////////////////////////////////////////////////////////////////////////// |
Also available in: Unified diff
Major:
1) in the Library, fix the fact that some applications (those that were creating their DistortedSurface objects outside of onSurfaceCreated or onSurfaceChanged) would not render after the activity went to background (press POWER to see that).
2) in the Apps, call the new 'Distorted.onPause()' API to fix the above problem
The above fixes the problem, but it still leaks memory if an App creates its Surface in onSurfaceCreated/Changed (precisely: it leaves the old Surface in the DistortedSurface Map). Thus
3) Fix the first 15 Apps to avoid the memory leak. Next Apps coming.