Adam's Lair Forum

game development and casual madness
It is currently 2018/11/20, 20:37

All times are UTC + 1 hour [ DST ]




Post new topic Reply to topic  [ 5 posts ] 
Author Message
PostPosted: 2018/09/06, 18:15 
Novice Member
Novice Member
User avatar

Joined: 2018/08/28, 17:12
Posts: 12
Role: Hobbyist
Edit// After I have realized it is because ALL the objects been deleted from the scene, but it wasn't me!

Hi.

Not sure where to report any bugs and I'm also not entirely sure if it a bug.
Basically I'm having the same problem like I have described in this topic:
viewtopic.php?f=4&p=7284#p7284

During the development so far when I use the OnInit method from ICmpInitializable, I get the message in Dualitor the scene has been edited externally. After that, the game no longer runs in the Launcher but only in the editor. No error messages, nothing, everything seems to be fine, preview works but I'm getting black screen in the launcher.
But bigger problem, after closing and re-opening the editor, I can no longer open the scene in the editor.

What I tried to do:
I have created a public property to be able to get the texture from the editor, I have also added two private fields to get the height and width of the texture

Code:
public ContentRef<Texture> ObjectTexture { get; set; }
float textureWidth;
float textureHeight;


After that inside the OnInit method I tried to get the width and height

Code:
public void OnInit(InitContext context)
{
     textureWidth = ObjectTexture.Res.PixelWidth;
     textureHeight = ObjectTexture.Res.PixelHeight;
}


When I compiled the component, Dualitor prompt the message the scene has been edited externally. When I tried to run the game, I did get Null Reference Exception for trying to get the width and height of the texture saying texture is null and I'm uncertain why is that. I did passed the texture to the property so not sure if I did anything wrong or else.

After I moved the lines to get width and height of the texture in to the OnUpdate method it is solved the Null Reference Exception error and the game runs in the preview but I get black screen in the launcher. And there is nothing fix it even if I remove the component entirely, it doesn't solve the black screen. I closed the editor, opened again and since I can not even open the scene.


Last edited by ddabrahim on 2018/09/06, 22:20, edited 3 times in total.

Top
 Profile  
 
PostPosted: 2018/09/06, 18:44 
Novice Member
Novice Member
User avatar

Joined: 2018/08/28, 17:12
Posts: 12
Role: Hobbyist
Okay, I have solved the problem. It was not that the scene didn't load and the game didn't run, but all the objects has been deleted from the scene including the MainCamera and this is why the Launcher didn't worked and I didn't see anything when opened the scene that made me think the scene didn't load and the game didn't run in the launcher.

Fortunately I was able to restore the scene from the backup but still, it is really weird and dangerous thing to happen. Not sure what caused it.

Is this happening often with Duality?
I hope not :S


Top
 Profile  
 
PostPosted: 2018/09/06, 19:06 
Novice Member
Novice Member
User avatar

Joined: 2018/08/28, 17:12
Posts: 12
Role: Hobbyist
Anyway, apart from the fact all objects being deleted from the scene, could anyone explain please why do I get Null Reference Exception if I try to get the width and height of the texture inside the OnInit method?

I would think this is the place where I supposed to initialize data that doesn't need to be updated and not going to change, but after my experience with OnInit I may stick to using only the OnUpdate method and just constantly update everything even if it not optimal :S

Thanks.


Top
 Profile  
 
PostPosted: 2018/09/06, 20:52 
Forum Addict
Forum Addict
User avatar

Joined: 2013/09/19, 14:31
Posts: 880
Location: Italy
Role: Hobbyist
ddabrahim wrote:
Anyway, apart from the fact all objects being deleted from the scene, could anyone explain please why do I get Null Reference Exception if I try to get the width and height of the texture inside the OnInit method?

I would think this is the place where I supposed to initialize data that doesn't need to be updated and not going to change, but after my experience with OnInit I may stick to using only the OnUpdate method and just constantly update everything even if it not optimal :S

Thanks.


That's because you are just not thinking four...
Ahem.

That's because you need to test your OnInit for the appropriate InitContext (Activated should be the one you are looking for). The method is actually called multiple times (loaded from resources, added to object, activated, etc...) so there might be some cases where, although it's been "initialized", the parent GameObject might not have been fully loaded yet.
Activated should be a safe bet that, at the very least, everything else in the GameObject has been loaded.

Regarding your "scene lost everything" issue, it might happen usually when there is something that goes very wrong™ during your Scene serialization phase, resulting in an empty or corrupted file.
Good to have a backup, but you will be probably happy to know that Duality keeps a backup record by itself in the aptly named Backup folder.

_________________
Come on Duality's Discord channel. We have cookies! :mrgreen:


Top
 Profile  
 
PostPosted: 2018/09/06, 22:20 
Novice Member
Novice Member
User avatar

Joined: 2018/08/28, 17:12
Posts: 12
Role: Hobbyist
Thanks a lot for your help :)

Quote:
That's because you are just not thinking four...

Well, it is a bit difficult to think in 4 dimensions if you don't even know the 4th dimension exists xD

I didn't even paid any attention to InitContext enumerators until you mentioned. Probably I should read the docs a bit more carefully. :redface:

Quote:
you will be probably happy to know that Duality keeps a backup record by itself

Yes I have noticed that one, fortunately it was in the first dimension right in-front my eyes. Thanks for mentioning

Anyway, so it was totally my fault then, I need to be careful what and how I'm initializing B)


Top
 Profile  
 
Display posts from previous:  Sort by  
Post new topic Reply to topic  [ 5 posts ] 

All times are UTC + 1 hour [ DST ]


Who is online

Users browsing this forum: No registered users and 20 guests


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Jump to:  
cron
Powered by phpBB® Forum Software © phpBB Group