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.

Dark GDK / Dark Lights and possible memory corruption

Author
Message
Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 3rd Apr 2012 16:49 Edited at: 3rd Apr 2012 17:12
I'm having problems with Dark Light. Or at least, Dark Lights is now highlighting a dormant problem in my code. The two symptoms are that when I add an object to Dark Lights to be light mapped, it becomes corrupted and the vertex data goes all over the place. A secondary symptom that start occurring later is a timer function, in a completely unrelated area of code causes an access violation.

All I'm doing is a simple light map:


This example causes corruption to the object arenaShell->dbObjTop. If I load in a new version of that model, rather than using the one that's already loaded, the light mapping works ok and I don't get a crash.

I can guarantee 100% dbObjTop exists and is genuine, because the model is on screen and gets corrupted when light mapped. So Dark Lights is struggling for some reason with the previously loaded model, but not a newly loaded one.

Having played around with lots of things, my suspicion is that the model data is somehow being interfered with after loading, perhaps by a dodgy array write or something like that (my editor is really complex now). I wonder if it's possible that the model data is being corrupted, so when Dark Lights tries to process it, it jumps into some weird memory positions, messes up the vertex data of my model and also other memory (hence the unrelated timing code blowing up).

Does anyone know how to go about debugging a problem like this? If something else is writing to the memory where the object is stored, how could I track that down?

I'm going to start stepping through the code and making a list of things that get allocated after the arena model is loaded, but perhaps there's a better way?

Edit: Just a note: It's not crashing on timer code, it's crashing on the dbSync() command, so the sync must be struggling with the corrupt object data.

Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 4th Apr 2012 10:38
Ok problem finally sussed! After half a day of trawling through arrays and pointer code, checking for possible overflows and other things, I couldn't find a problem. Turns out it's something to do with what happens to an object during a dbSync()

This code works fine:


However, if you add a dbSync() command anywhere in that code AFTER the object load but BEFORE the LMAddLightMapObject() the model data will be corrupted and the program will most likely crash. The reason I was having the problem is my models are loaded in my level editor, loads of syncs happen as the user works on the model and then only when they hit "Render Lights" do the models get added to the light mapper and rendered.

So I think the solution will be:
- Run LMStart() when my program first loads
- Run LMAddCollisionObject and LMAddLightMapObject directly after loading your model (or making it with mesh commands)
- Then you can sync away as much as you like before you make the light maps

Unfortunately this solution won't work for me, as model prefabs may be removed before the light mapping is rendered, and there is no command to remove an individual model from the light mapper. So my only solution is, when the user clicks to render lighting:
- Save all models to disk with all positional information etc.
- Load and rebuild the entire scene
- Render the lighting
- Continue as if that wasn't a pain in the arse

I need to work on scene saving code anyway, so I guess I'll kill two birds.

Also setting the lightmap file names only accepts a single char, rather than a char* as suggested by the manual. So it doesn't look like you can actually name your lightmaps, or give them a directory, which I'm sure is going to cause me massive headaches soon. I think I'm going to have to manually edit the generated DBO files binary to get them to use unique lightmap texture names, then rename the generic 1.png etc. files made. Unless there's something I'm missing? It seems too ridiculous to have a core command simply not work and nobody to have been bothered by that. So I must be doing something wrong?

Brendy boy
18
Years of Service
User Offline
Joined: 17th Jul 2005
Location: Croatia
Posted: 4th Apr 2012 22:29
4 thing you can try:
1. clone objects, delete originals, perform lightmapping on the clones
2. convert object fvf, perform lightmapping
3. convert object fvf, clone object, delete originals, perform lightmapping on clones
4. lock vertexdata for objects with mode 2, perform lightmapping

Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 5th Apr 2012 00:38
Quote: " clone objects, delete originals, perform lightmapping on the clones"


Good suggestion. I didn't think of that. May give it a try tomorrow. I finished my save/load level functionality today anyway, so I basically save then reload the level before light mapping and that works. Cloning the objects may be cleaner though.

I'll report back if it works. Cheers.

Matty H
15
Years of Service
User Offline
Joined: 7th Oct 2008
Location: England
Posted: 10th Apr 2012 02:49
I had issues with Dark Lights too a while ago, thanks for posting possible solutions/work arounds, I may give Dark Lights another chance for my next project.

Fallout
21
Years of Service
User Offline
Joined: 1st Sep 2002
Location: Basingstoke, England
Posted: 10th Apr 2012 19:02
I'm using it quite thoroughly and finding workarounds/solutions for several problems. Learning a lot about what makes it crash (seems quite easy to do, but so far it's always been something I've done), so if you have any questions about using it, I'll keep my eyes peeled and try and answer them.

Juggernaut
12
Years of Service
User Offline
Joined: 12th Mar 2012
Location:
Posted: 25th Jul 2012 23:48
Hello,

Does all these features in Dark Lights work (http://www.thegamecreators.com/?m=view_product&id=2023)? Can anybody confirm ?

Quote: "

Dark Lights
Dark Lights adds a suite of light mapping commands and features to DarkBASIC Professional and Dark GDK, and also includes a versatile lightmapping tool with full source code.

Dark Lights is available for DarkBASIC Professional and Dark GDK.

Here are some of the features that Dark Lights supports:

Three types of light: Directional, Point and Spot Lights
Variable attenuation point lights, both quadratic and linear attenuation are avaible.
Curved surfaces are smoothed correctly.
Realistic shadows and variable shadow blurring.
Transparent objects that modify the colour of the light ray as it passes through it.
Uses very fast ray casting to achieve quick build times
Start the light mapping as a thread so you can display its status whilst it works.
Ambient occlusion for realistic global lighting.
Lights

The light mapper supports three types of lights, point lights which emit light equally in all directions and reduce in bightness over distance, directinonal lights which shine in a particular diretcion over all distances equally, and spot lights that shine in a particular direction like a flash light.

Attenuation

You can set the attenuation for point lights to control how light fades over distance from the light source. You can set the parameters for quadratic, linear, or no attenuation and the radius over which the light has effect.


Transparency

You can add transparent objects that allow light through but modify the colour of the light on its way through. This can be used for stained glass windows that create a pattern on the floor behind when a bright light shines through them. There are three modes of transparency available, black colour key transparency that blocks or allows light through, alpha mapped texture for transparency that varies over the object and colours the light, and semi-transparent with consistant transparency over the object and colours the light.

Curved Surfaces

The light mapper reads the vertex normals of the objects that are being light mapped and colours curved surfaces accordingly. You can also set the quality for curved surfaces to be higher than that for flat surfaces to make sure there are enough pixels to smooth the surface correctly.

Self Shadowing

Objects can cast shadows over each other or be set to only receive light and not cast shadows. You can set the shadow bluring to remove any sharp edges that are created in the transition between light and dark. Soft shadows can be achieved by either bluring or by using multiple point lights instead of a single point light to smooth the transition of shadows.

Speed

The light mapper uses a fast ray casting engine to quickly work out if a point will be in shadow and allows many lights to be used whilst still maintaining quick build times in the order of minutes for complex scenes and seconds for simple scenes.

Threading

The light mapper allows you to start the light map process as a thread so that you can continue to display its status on screen whilst it is in progress. You can end this thread at any time before its completion allow you to cancel it without ending your program.

Ambient Occlusion

A form of global illumination, ambient occlusion creates realistic shading on surfaces by testing how much of a global light each point can see. Those points in corners or holes will see less of the global light and be darkened accordingly.

You may be wondering what use these sorts of commands would be in DarkBASIC Professional and Dark GDK. After all, even the fastest lightmapping routines would still take too long to be run in-game on complex levels. However there are many applications for this extension. A large number of people when creating games, build their own 'game editors' as well. Using this you could now add sophisticated light mapping functions directly into your tools. You could write your own stand-alone light mapping application with this. Write your own interface perhaps and use this extension to handle the actual mapping.

You could of course use it in-game if your game suits it. For example in a simple scene, dynamically generated, you could lightmap the entire level before the player even gets to start it. The threading options available mean you could even be doing this while the player is going through the intro sequence / game menu. Finally the editor we include with the DLL can be used to lightmap your own levels and objects. Using an intuiative 3D interface you can fly around your level, place lights, change the colour, fall-off distance and other attributes, before rendering the scene. You can then fly around the rendered scene and if you like it, save it out as a native DBO object. No more messy conversion with file formats - you can now import and map directly to DBO files which DBPro will load and display exactly as they appear in the editor. We even give you the source code to the editor, so you can add your own enhancements and learn from it. A free demo version of the editor is now available to download (see below).



"


I am asking this , because I downloaded the demo but it did not work for me!
Olby
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 26th Jul 2012 00:11 Edited at: 26th Jul 2012 00:14
Yes, they do. I used Dark Lights extensively for my level editor project (back in 2006). It's quite powerful. There are some additional commands not mentioned in the help file. Readme file covers them all. To be honest I haven't experienced any issue described in this thread while using DL- and I did for quite a while.

MapScape (CSG map builder) made by EVOLVED uses Dark Lights for internal light mapping.

I heard the demo doesn't work because it strips out every third triangle (essentially making your models like cheese). It was created solely for testing purposes.


Intel Core2Duo 2.2GHZ, 2GB, GeForce 8600M GT 1280MB, Windows Vista Ultimate SP2, PureBasic 4.61 + DarkGDK 2.0
Juggernaut
12
Years of Service
User Offline
Joined: 12th Mar 2012
Location:
Posted: 26th Jul 2012 00:19
@Olby: Thank you for the confirmation. I was finding myself a bit shaky about the lingering bugs that can trouble us in the middle of our projects. Seems like - it is worth buying.
Olby
20
Years of Service
User Offline
Joined: 21st Aug 2003
Location:
Posted: 26th Jul 2012 00:29
As with everything from TGC make sure you use it right or you will get into issues sooner or later i.e. stick to the rules. That's my advice. I have had so many issues with DBPro related products just because I tried to achieve something unusual and that's where one usually gets into trouble.


Intel Core2Duo 2.2GHZ, 2GB, GeForce 8600M GT 1280MB, Windows Vista Ultimate SP2, PureBasic 4.61 + DarkGDK 2.0
Juggernaut
12
Years of Service
User Offline
Joined: 12th Mar 2012
Location:
Posted: 26th Jul 2012 00:49
I see.

Login to post a reply

Server time is: 2024-03-29 09:49:19
Your offset time is: 2024-03-29 09:49:19