Show Posts

This section allows you to view all posts made by this member. Note that you can only see posts made in areas you currently have access to.


Messages - kbjansen

Pages: 1 [2] 3
16
ok thanks Egon!

For everyone who wants to get more information about Memory Management in Android here is a very useful presentation that should answer all other questions relating to Memory Management and Memory Leak tracking in Android!

To the huge texture problem:
I' m scaling the 2048² bitmap down to 1024² and resize the GUI elements programmatically like I said before.
I believe I have to live with the maybe creepy results, we will see.
Another option is to completely change the GUI to a retro style with pixel graphics...

But, thanks again Egon, for your time invest!

17
mmh, ok.
The reason why i use such a huge texture:
I've got 60 elements for InGame GUI and Menu GUI that fill altogether around 20 screens.
Some of these elements are used several times. Each button has a active and a nonactive state (so 2 sub bitmaps per button).
I already combine the Standard Android GUI with this own custom GUI elements to reduce the bitmap using.
Each GUI element that is located within the texture is gauged for a 480x800 display - So the biggest element is about 435x752 and the smallest element is about 64x64.

I may reduce and replace some inefficient (repetetive) GUI elements from that texture/ bitmap. But i think the reduction would be not enough to get fit all elements in the next smallest bitmap texture (1024x1024) without a rescale.

Another way may be to scale down the bitmap from 2048x2048  to 1024x1024 an double scale each GUI element programatically.
But then , i guess, the GUI would look kinda crappy (even the reduction of my skybox bitmaps from 512² to 256² doesn't look nice)

BTW:
Is there a difference between loading one time a 2048² bitmap to memory or four times a 1024² ?
So is this statement true or not:
[(1024²+1024²+1024²+1024²) -> memory] = [(1024²) -> memory] + [(1024²) -> memory] + [(1024²) -> memory] + [(1024²) -> memory]

If the right term needs fewer memory than the left, then i could split the 2048² into four 1024² bitmaps and load them seperatly.
If not a splitting doesn't solve the OOM.

Another question:
Is there a way to manipulate the native Memory?
Because until Android Honeycomb the bitmaps are stored there and not in managed Heap.
Maybe i can free some memory associated with the huge bitmap whlie switching between Activties?


18
Howdy!

short question about the storage of GUI elements that are obliged to blit via FrameBuffer:

What is better:
1. putting all GUI elements in one big bitmap that will be loaded as one single Texture to the TextureManager
or
2. for every small GUI element one single Texture-object that will be loaded to TextureManager?


My Problem:
I've chosen the first path because I've got about 60 GUI elements. All these elements are placed within a single
bitmap and are drawn to the screen via frameBuffer.blit(...) over their associated 'bitmap source coordinates' that are stored in a so called GUIMeasurements-Object.
The size of the bitmap is (please don't go berserk XD) 2048x2048 with a color depth of 16.

Is it necessary that this bitmap, which is only used for blitting, is loaded to the TextureManager?
At the moment the memory limit is reached while restarting the Activity, so I got a OOM - naturally.

The use of the method FrameBuffer.blit(int[], int, int, int, int, int, int, int, int, boolean) could be an alternative but is not recommended.

Any advice or hint?

19
Report:

Referring to Problem 1: Messed up keyframe animation after polygon reduction:

Try:
a) Take default object without keyframes and do polygon reduction
b) duplicate this "master" mesh 'n' times (n = amount of keyframes) and rotate/ translate subcomponents of the mesh to get the desired keyframes (e.g. rotating the front wheels to the left and right)
c) create one mesh out of all subcomponents, doing that once per mesh duplicate
d) Export each frame as separate 3ds-file, Serializing, zipping and load to the jpct-AE World

result:
- the object shapes of the mesh and it's different keyframes are loaded correctly, but the subcomponents that alter between the keyframes are textured in a wrong cracky way while animating (so the chassis and back wheels are textured correctly, but the front wheels doesn't )
- although the textures are connected to the shape of each single subobject correctly, because if i load each one in a separate Object3D then everything seems to be fine
-> animation.setInterpolationMethod(Animation.KEYFRAMESONLY) doesn't helped

Is there a way to switch off interpolation between master object and its keyframes (or its duplicates)?

Reffering to Problem 2: Out of Memory when restarting/ close Activity after Animation allocation

Try:
a) make nearly every class member static and disable some object-destruction and 'nulling'
effect: OOM disappears for a while, but objects are not reseted correctly (some objects are still there others are gone -> very strange)
b) make some more changes referring to code structure and several statements
result: OOM is back :-\

----> now I gonna try to track the source of error with the help of the Eclipse Memory Analyzer Tool,
so stay tuned!

ps: every hint of 'how to get rid of OOM errors' would be nice and  helpful!

EDIT:
quickly found a possible reason for the appearing of the OOM error - the texture that contains all GUI elements might be too big
I think I open a new thread, because this could be basic topic with a short answer (linked here)

20
With "recycle" i actually meant to copy the references into the new (or restarted) Activity. My Android examples do this in a crude and simple way and my RPG game does it too. The result is, that the game simply continues where i left once all references are being copied into the new Activity.
... how do you copy the objects? Via Intent? I've already thought about handing over all jpct objects at the beginning of the developement.
At that time I failed to transport the mGLView because I didn't know how to transport custom or uncommon objects via Intent. So I leave this branch to save time.
Your result of copying the references seems to be equal with my "onResume"- result after minimizing and reopen the app.
When restarting the game and the activity, I want to reset all jpct objects position, score, time and so on. So no need to destroy them, thats right.
But I have to reset and unconnect the jBullet-Simulation. So it might work if I copy the refs like you said and 'just' destroy the jBullet things. Thats an idea...

reducing polys:
Ok I understand the problem, thanks! Your idea with the reduced master mesh seems to be plausible and make sense.
So back to original mesh :S ... I hope the polygon cruncher plugin for 3ds doesn't clump all submeshes of the object while reducing.
If so, there is no way to rotate the wheels after reduction... i test this and will report
 

21
Yes I'm disposing the World and the FrameBuffer in the destroy-Method like you mentioned.
Your idea of making objects static instead of killing them is interesting - i give it a try and will report the results.

And do you mean with recycle to reset the objects preferences (for example set an object3d back to startposition...) or doing the destroying and nulling that i do in destroyallobjects, or what else do you mean?

Thanks for your answer related to 'quads vs triangles'!


Another thing related to polygon reduction:

I'd reduced some 3ds models inclusive its separate keyframe meshes (keyframe meshes = same vehicle object but front wheels rotated).
When I separately load and 'draw' them with the jpct-AE Engine all objects are displayed correctly.

But when I load the 3ds keyframe meshes as keyframe into a Animation (do it like seen above) and animate these frames at runtime
then i will get a strange output:
- looks like the texture of the corresponding keyframe animation was putting over the mesh of the default original object itself
- so the keyframe texture is loaded but the keyframe mesh is not
- looks kind of cracked

without polygon reduction the keyframe meshes are displayed correctly
what could be lost while reducing polygons?
or is there any preference i should call on 'Animation'.

I 'm going to post some pictures, so you can see what i'm talking about
... too spiritless to do it right now o_o
cya

22
Hooohaaa!

the most nerving problem while programming for mobile devices is the OutOfMemory Exception.
In most cases the OOM is caused by long living objects. The further the development progresses the more objects you
need and the more often you are running into a OOM.

1.
Does anyone have experience with a kind of Memory Leaks tracking tool?
I want to find out which objects are blocking the Memory.
I would try this: http://macgyverdev.blogspot.de/2011/11/android-track-down-memory-leaks.html


The latest OOM - that drives me insane - is thrown after restarting the gameActivity wherein , among others, a simple keyframe animation
is created. Uncommenting that code lets the OOM disappear, so i think i have something forgotten to clean up.
This is how I do:

Code: [Select]
private Animation drive = null;
private Object3D temp = null, playerCar = null;
[...]
/* jPct specific ViewPort setup. It's called in MyRenderer.onSurfaceChanged(...)*/
private void setupViewPort(){
[...]
//loading 3D cars
case 1:{
//playerCar = beetle
if(playerCar == null){
playerCar = loadZippedSerializedModel(getResources().openRawResource(R.raw.beetleidle));
playerCar.rotateY((float)Math.PI/2);
playerCar.rotateMesh();
playerCar.clearRotation();
playerCar.getMesh().compress();
//*
drive = new Animation(3);
drive.createSubSequence("IDLE");
drive.addKeyFrame(playerCar.getMesh());

drive.createSubSequence("LEFT");
temp = loadZippedSerializedModel(getResources().openRawResource(R.raw.beetleleft));
temp.rotateY((float)Math.PI/2);
temp.rotateMesh();
temp.clearRotation();
temp.calcBoundingBox();
temp.calcNormals();
temp.getMesh().compress();
drive.addKeyFrame(temp.getMesh());
if(temp!=null)temp.clearObject(); temp = null;

drive.createSubSequence("RIGHT");
temp = loadZippedSerializedModel(getResources().openRawResource(R.raw.beetleright));
temp.rotateY((float)Math.PI/2);
temp.rotateMesh();
temp.clearRotation();
temp.calcBoundingBox();
temp.calcNormals();
temp.getMesh().compress();
drive.addKeyFrame(temp.getMesh());
if(temp!=null)temp.clearObject(); temp = null;

playerCar.setAnimationSequence(drive);

playerCar.strip();
playerCar.build();
// playerCar is added to world later, after connecting with jBullet Rigidbody
// /*drive.remove(0); drive = null;*/
                                                }

}
                           
/** Loads a single, zipped and serialized Object from InputStream. It' s called in setupViewPort()*/
private Object3D loadZippedSerializedModel(InputStream inputRessource) {
ZipInputStream zis = new ZipInputStream(inputRessource);
try {zis.getNextEntry();} catch (IOException e) {/*throw new RuntimeException(e);*/}

Config.oldStyle3DSLoader=true;
Config.useRotationPivotFrom3DS = true;

Object3D model = null;
model = Loader.loadSerializedObject(zis);

//clear resources
try {
zis.close();
zis = null;
} catch (IOException e) {/*e.printStackTrace();*/}
Loader.clearCache();
MemoryHelper.compact();
System.gc();
return model;
}


/* Resets all Objects to null in reverse order of creation. It's called in Activity.onDestroy()*/
private void destroyAllObjects(){
[...]
Loader.clearCache();
playerCar.clearAnimation(); playerCar.clearObject(); playerCar = null;
if(drive != null)drive.remove(0); drive = null;
if(temp != null)temp.clearObject(); temp = null;
[...]
System.gc();
MemoryHelper.compact();
}



What I managed beside the cleaning of all objects on Destroying the Activity:
  • minimizing the keyframe animation to 3 frames (so beside the object3D there are two more Meshes loaded)
  • every keyframe is part of a single animation sequence (so one frame per sequence)

To reduce the memory usage I want to compute the 3ds-objects down - I hope this helps.

2.
Does anyone know a good polygon reduction tool?
I already tried POLYGON CRUNCHER (http://www.mootools.com/plugins/us/polygoncruncher/) but after optimizing (from 9073 vertices  to 6112 and from 14652 faces to 8738)
the jpctSerializing process get stuck so the serialized 3ds file is not created.
I guess there was something destroyed while polygon reducing that was important for jpctSerializer.
Anyone knows a better tool?

(EDIT: fixed this by doing another import of the reduced 3ds-file to 3ds-Max and export it as 3ds-file again)


ByTheWay!?: What's recommended: quadrangular or triangular Polygons?
I've read somewhere that all quads are recompute into triangles for the android's hardware, so putting objects as quadrangular Polygon Mesh would reduce performance (can't find where I read this anymore) - so is that true?

23
nope, too bad. I hopped over the log, but have no clue why the Activity is not recreated correctly...
I attach the two logs (one with this issue: log.txt and another with the working workaround: logwithsleep.txt).
Maybe you see something strange...

EDIT:
upps, maybe i should create two new logs, because there were too many objects in this world at that time XD
so unreadable atm ...

EDIT2:
added two new logs...

[attachment deleted by admin]

24
Within the onDestroy-Method of the Activity, that should be able to get restarted, I call the method destroyAllObjects().
This method resets and 'nulls' all Objects, that were initialized and used by the Activity.

Or what do you mean with decouple?

25
Thanks for your informative explanation, Egon! Everything seems to be clear now!

Updated jpct and jpct-ae like you'd said. No, difference.
But with setting the object's center and pivot programmatically AFTER build() is called, there is no problem anymore.
I've already tried to call setCenter() and setRotationPivot() before, but didn't see that I called build() another time after object creation
in physics routine - what a silly and nooby mistake :S

So thanks again

26
some more trys:
I'd imported the vehicle.3ds to blender. With the exception of the rerotation of the 2nd vehicle it's all just ok. The pivot points seems to be on the right place in blender.

... so, I recognize that the so called "Selection Center" of the 3ds max Polygon editor in vertex mode resembles the in jpct shown transformed center (see pic1 previous post).
Some more recherche show that this "Vertex Selection Center" is the calculated geometric center of 3DS max.
http://docs.autodesk.com/3DSMAX/15/ENU/3ds-Max-Help/index.html?url=files/GUID-4B35174B-AAC4-470D-8A4E-89608EB6914D.htm,topicNumber=d30e57453


Is it possible that the transformed center of objects in jpct equals this geometric center?

Now, i no more believe that there is an error in exporting the 3ds. file referring to the pivot point.
(this other thing, i mean, the rerotating of the 2nd mesh, could be some failure of mine)

27
thanks for your quick response, i'll give it a try tomorrow

Edit:
ok, set Config.useRotationPivotFrom3DS to true, before serializing and before loading the 3ds object.
The console log after serializing says: Setting rotation pivot of object chassis_jPCT-2 to (0.0,0.0,0.0) - so just fine

But at runtime the center of the transformed is still on wrong position. But the pivot vector and the center of transform have the same
value - see pic1 (that yellow tall peak is set to the transformed Center):


pic1

So lets try another vehicle - same placement in 3ds Editor, same pivot alignment -> result: TransformedCenter of the 2nd car is now in the middle of the vehicle, BUT the vehicle is rotated about 90 degrees and not set to the center of the world - see pic 2


pic2

So a ghost whispered to me to just reimport the 3ds.files to 3ds Max and...... badumm tsss
result of that action:
the pivot of the 2nd vehicle is rerotated about 90 degrees (don't know why) and
to 1st car mesh was added a swollen big invisible mesh in y-direction (WTF)

So I think there are some issues with the 3ds-exporter

28
Huhu,

I am going to try to load a 3ds object (it's one single vehicle mesh) to jpct-ae to connect it with a jbullet rigidbody.
The rigidbody needs the transform's center to set a rigidbodyshape correctly.

Problem is, that the center of the vehicle transform (Object3d.getTransformedCenter()) at runtime doesn't equal with the center of the object in 3ds max. Even a moving of the object in 3ds max away from (0,0,0) doesn't cause a difference (the shown transformedCenter of the vehicle is still the same).

But, that doesn't concern to all objects I'd loaded with jpct the same way!
The transformed center of a spherical soccer ball matches exactly with the one from 3DS Max.

Anyone of you knows this issue?
Is it possible that the .3ds-exporter of 3DS max generates a center of the transform relatively to the size and not position of the object?
Or is the vector of this center generated while serializing the object's 3ds. file with jpct?

I method like Object3D.setTransformedCenter(new SimpleVector()) would be great. Then I may reset manually the center of the vehicle at object creation time.


If some more information, code-snippets or explanation screenshots are required I can deliver them in addition.
(sorry for linguistic bloopers, but this problem made me insane and dizzy .'S )


EDIT:
The 3d object passes through the following workflow:

3DS MAX -> Export as .3ds-file -> Serialization 3ds. to .ser-file -> Zip
... Android Build process ...
Runtime: -> unzipping -> load via Loader.loadSerializedObject and object3d creation

29
EDIT:
If I could remove a single activity from history stack at runtime then the problem would be solved.
Does anyone know a way to do that?

greetings
jan

30
Hi there,

i hope you can help me with the following activity-lifecircle problem:

Situation:
I have two Activities, one for the Menu and one for the Game.
The GameActivity is started by the MenuActivity via startActivityForResult(GameIntent) after pressing "start Game"
(see pic0 number 1. )
There are two different jPCT-Environments within these two Activities, that will be individually cleaned by their
associated Activity.onDestroy() method when calling Activity.this.finish().


The user has differnet options after pressing "pause Game":

a. Resume the game
-> simply unpausing the game

b. Quit the game

Code: [Select]
//pseudo code
GameActivity.this.setResult(RESULT_QUIT);
GameActivity.finish();
MenuActivity.onActivityResult(...){ ... case RESULT_QUIT: MenuActivity.finish() }

c. Back to Main Menu
Code: [Select]
//pseudo code
GameActivity.this.setResult(RESULT_MAIN_MENU);
GameActivity.finish();
MenuActivity.onActivityResult(...){ ... case RESULT_MAIN_MENU: MenuActivity.currentScreen = Screen.MAIN_MENU; }

d. Restart the game
Code: [Select]
//pseudo code
GameActivity.this.setResult(RESULT_RESTART);
GameActivity.finish();
MenuActivity.onActivityResult(...){ ... case RESULT_RESTART: startActivityForResult(GameIntent) }


Problem:
When restarting the GameActivity immediately after destroying (see option d.), the jpct-World doesn't load (see pic2),
although the Framebuffer is ready (you can see the key buttons on pic 2).
I think the old GameActivity with the cleaned jPCT-Environment is still on the Activity stack and not
destroyed quickly enough by the garbage collector. (see pic0 number 2. ) [reason for this argument: see clumsy workaround 1, lower]

Restarting the GameActivity by pressing "start Game" after returning to the Main Menu (see option c.) is working (see pic1).

pic0

short workflow


pic1

Display after pressing "start Game"


pic2

Display after pressing "restart Game"

Clumsy workaround 1:
When returning to MenuActivity with RESULT_RESTART, pasting a thread.sleep for 5 sec before calling startActivityForResult(GameIntent)
-> result:  World will be loaded like shown in pic1
Issue:
5 sec blackscreen appears between activity switching

Clumsy workaround 2:
When returning to MenuActivity with RESULT_RESTART, putting a System.exit(0); in GameActivity.onDestroy() as last line
-> result:  World will be loaded like shown in pic1
Issues (EDIT):
-rough Activity changing with short ugly blackscreen, lumberjack style :S
-a following "back to Menu"-action from GameActivity ends up in a restart of the MenuActivity too,
because System.exit(0) clears the states of all Activities! - i guess



Question:
Does anyone know a good way to get rid of old activity instances immediately?
I think about a command like "gc, clean the stack NOW!" (System.gc() doesn't help, still takes 5 sec until the GC get its ash up)

Or is there a way to get the number of the Activities on stack?

I am wondering why no new instance of GameActivity is build after calling startActivityForResult(GameIntent) immediately?
Maybe I have to set a flag like "the old GameActivty is expired"? Any ideas?


EDIT:
Reset the GameIntent before calling startActivityForResult(GameIntent) doesn't help neither









[attachment deleted by admin]

Pages: 1 [2] 3