Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

AppGameKit Classic Chat / [Possible Bug?] Failed to Load more Objects and Images

Author
Message
hexGEAR
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 3rd Aug 2016 03:24
Hello guys, I've been encountering a strange issue while developing a 3D game using AppGameKit and was wondering if anyone else has come across such an issue or if the AppGameKit team could shed some light on what could possible be going wrong. I've checked the forums but it doesn't look like anyone else has experienced a similar issue.

My game generates a lot of assets on the fly, for example bullets, ricochet debris, etc and I've been very careful to free every single resource I create as soon as it's no longer in use. There's never a situation where there are too many assets on screen at the same time, and even when there are I track them all and make sure they're all safely deleted.

Now when I start playing the game, all goes well but after a long while, especially in the heat of a fierce battle where there are bullets flying everywhere and debris all over, AppGameKit refuses to load anymore objects or images. The game doesn't crash, it still works like normal but every call to create a new object or image fails so you get instances of invisible bullets flying around or white HUD sprites with no texture. When I use the GetLastError() command it just returns something along the lines of "failed to load object" or "failed to load image". What I'm interested in is why?

Now I was thinking it could be some kind of memory leak but when I exit the current game session to return to menu, a function is called that frees all resources used for the game session (deletes existing images, objects,sprites, texts etc) before returning to the menu. And even when this is done, and I try to load assets for the menu I get the same issue.

What are the limits of the Images and Objects you can load? If I delete an object and load objects later on will it pick an object ID of objects previously loaded and deleted? Or does it keep incrementing till it reaches some kind of upper limit?

Help!

Here are my System Specs:

AGK Version: v2.0.20 Tier 1
Dev Platform OS: Windows 10
Processor: Intel Celeron Quad Code 1.6GHz
Graphics Card: Intel HD 1GB
RAM: 2GB
Mobiius
Valued Member
21
Years of Service
User Offline
Joined: 27th Feb 2003
Location: The Cold North
Posted: 3rd Aug 2016 11:07
For images, you only need to load an image the once. You can set as many sprites/objects you want to use that image, but you don't need to reload the image.
I also think that if you use the auto image/object/etc numbers, it doesn't clear the list out even after you delete the resource. (I may be wrong on this however.) It may be better to write your own resource assigning system than to relay on AGKs,

For example, pick a random ID, chick if it exists, if it doesn't, use it. If it does, pick another random ID.
hexGEAR
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 3rd Aug 2016 13:56
@Mobiius:
Thanks for your response. Yeah I load all the images once at the start of the game and free them all just before you exit.
Quote: "I also think that if you use the auto image/object/etc numbers, it doesn't clear the list out even after you delete the resource."

I'm suspecting this as well. I'll try your suggestion and see if that makes any difference, thanks!
hexGEAR
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 3rd Aug 2016 14:53
Ok so I wrote some test code, a loop that loads a 3D object from a file then deletes it immediately. In the loop I also kept track of the 3D object's assigned ID number and the result of GetLastError(). As we suspected, the assigned object ID number starts from 100,000 and just keeps incrementing. However at around 100,660 it throws an error:
Quote: "Failed to Load Object "object path" - Unable to open File "object path""

I repeated this test several times and I always get the same error when loading .3DS objects and .X objects at around the 100,660 mark but this isn't a problem when loading image files.

So I changed strategy a bit and loaded the 3D object, converted it into a Mesh Memblock and repeated the same loop but this time converting from Mesh Memblock to 3D object and then deleting it in the same loop. This time around I didn't get any error so I guess I'll handle it this way instead. This is how the finished game will handle resources anyways since I won't be releasing the media in original form with the game.
JLMoondog
Moderator
15
Years of Service
User Offline
Joined: 18th Jan 2009
Location: Paradox
Posted: 3rd Aug 2016 15:20 Edited at: 3rd Aug 2016 15:23
This is something I use all the time for my mobile apps as when working with hundreds of images/sprites it tends to reach ridiculous numbers SO try this:



Good luck!

Edit: Oooooooops! I took too long to post my reply!

Any chance to see your 3d object load function using memblocks? I'm really interested in this technique and would be cool to add to my own current project. Thanks for your time!
hexGEAR
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 3rd Aug 2016 22:45
@JLMoondog:
Thanks for your suggestion. It's what @Mobiius advised as well; that I create my own resource assignment system. So out of curiosity I wrote another test code, this time around I assigned the same fixed ID number to the object, and kept loading and deleting the same object in the same loop and kept track of iterations with a counter. Theoretically this should go on for like forever but instead it stops at exactly 496 iterations before throwing the exact same error:
Quote: "Failed to Load Object "object path" - Unable to open File "object path""

It's beginning to look more like a bug, maybe a memory leak.

Quote: "Any chance to see your 3d object load function using memblocks? I'm really interested in this technique and would be cool to add to my own current project."

This was a simple test, I just used the CreateMemblockFromObjectMesh command to create the memblock, and then recreated the object using the CreateObjectFromMeshMemblock command.
Paul Johnston
TGC Developer
22
Years of Service
User Offline
Joined: 16th Nov 2002
Location: United Kingdom
Posted: 9th Aug 2016 17:34
Thanks, fixed for the next version. It was caused by the Open Asset Import Library that we use not closing the file after it had loaded the object, so it eventually exceeded the number of open files allowed.
CumQuaT
AGK Master
14
Years of Service
User Offline
Joined: 28th Apr 2010
Location: Tasmania, Australia
Posted: 13th Aug 2016 08:54
Brilliant, Paul! Do you know when you're planning to put that version out?
hexGEAR
22
Years of Service
User Offline
Joined: 3rd Nov 2002
Location: Naytonia
Posted: 15th Aug 2016 15:46
@Paul Johnston:
Great, makes a lot of sense, thanks for the explanation!

Login to post a reply

Server time is: 2024-11-25 04:53:10
Your offset time is: 2024-11-25 04:53:10