Jump to content

Game Crash with world:clear() & 2 vehicles ??


Marcousik
 Share

Recommended Posts

I encounter this problem:

 

I attach a script on ONE box creating ONE vehicle, ONE car, in a world, and I want to change the map ingame with the changemaptrigger script, that calls the world:clear() in main.lua

 

Well, there's NO problem doing this, the world gets cleared.

 

BUT when I put 2 cars, exactly the same, this crashes the game as the player goes in the trigger.

No importance if the cars are same models or not, and no importance if the scripts attached are the same or not: It crashes.

 

Anyone knows why ?

 

Here is the script attached, creating the cars:

 

import "Scripts/Functions/ReleaseTableObjects.lua"

 

 

 

Script.SpeedMax=20--int "Vitesse(2-100)"

Script.Reac=1--float "Virage(0-2)"

Script.MyMass=1000--int "Masse"

 

Script.Mass=100--int "Roue, poids"

Script.Rayon=0.5--float "Roue, Rayon"

Script.Epaiss=0.5--float "Pneus, Épaisseur"

 

Script.LongueurAV=1--float "Axes,longueur Av"

Script.LongueurAR=1--float "Axes,longueur Arr"

 

Script.LargeurG=0.8--float "Axes,largeur G"

Script.LargeurD=0.8--float "Axes,largeur D"

 

Script.Hauteur=-0.5--float "Axes, hauteur"

 

Script.SeeWheels = false --bool "Voir Roues"

Script.Inverse = false --bool "Inversé"

 

 

function Script:Start()

 

 

--Create the vehicle

self.entity:SetMass(self.MyMass)

 

self.vehicle = Vehicle:Create(self.entity)

 

--Add tires

local tireradius=self.Rayon

local tiremass=self.Mass

local tirewidth=self.Epaiss

local tireheight=self.Hauteur

local material = Material:Load("Materials/Effects/Invisible.mat")

self.tiremodel={}

 

 

self.tiremodel[0]=Model:Cylinder()

 

self.tiremodel[0]:SetScale(tireradius*2,tirewidth,tireradius*2)

self.vehicle:AddTire(self.LargeurG, tireheight,self.LongueurAV,tiremass,tireradius,tirewidth,true)--,200,2000,1.2,20,100000,1.5,0.1)

 

self.tiremodel[1]=Model:Cylinder()

 

self.tiremodel[1]:SetScale(tireradius*2,tirewidth,tireradius*2)

self.vehicle:AddTire(-self.LargeurD,tireheight,self.LongueurAV,tiremass,tireradius,tirewidth,true)--,200,2000,1.2,20,100000,1.5,0.1)

 

 

self.tiremodel[2]=Model:Cylinder()

 

self.tiremodel[2]:SetScale(tireradius*2,tirewidth,tireradius*2)

self.vehicle:AddTire(self.LargeurG,tireheight,-self.LongueurAR,tiremass,tireradius,tirewidth,false)--,200,2000,1.2,20,100000,1.5,0.1)

 

 

self.tiremodel[3]=Model:Cylinder()

 

self.tiremodel[3]:SetScale(tireradius*2,tirewidth,tireradius*2)

self.vehicle:AddTire(-self.LargeurD,tireheight,-self.LongueurAR,tiremass,tireradius,tirewidth,false)--,200,2000,1.2,20,100000,1.5,0.1)

 

 

if self.SeeWheels== false then

self.tiremodel[0]:SetMaterial(material)

self.tiremodel[1]:SetMaterial(material)

self.tiremodel[2]:SetMaterial(material)

self.tiremodel[3]:SetMaterial(material)

end

material:Release()

self.vehicle:AddAxle(0,1)

self.vehicle:AddAxle(2,3)

 

 

--Finalize the vehicle

if self.vehicle:Build()==false then Debug:Error("Failed to build vehicle.") end

 

--Stop the engine

self.vehicle:SetEngineRunning(false)

--Set the emergency brake

self.vehicle:SetHandBrakes(5000)

self.CarStop=1

 

self.BenzinCycle=0

self.BrakeTime=0

 

 

self.MyCar=0

 

end

 

 

 

------------------------------------------------

 

 

function Script:Detach()

 

 

self.tiremodel[0]:Release()

self.tiremodel[1]:Release()

self.tiremodel[2]:Release()

self.tiremodel[3]:Release()

 

self.tiremodel[0]=nil

self.tiremodel[1]=nil

self.tiremodel[2]=nil

self.tiremodel[3]=nil

 

self.vehicle:Release()

self.vehicle=nil

 

 

ReleaseTableObjects(self.tiremodel)

 

self.entity:Release()

end

 

 

Link to comment
Share on other sites

I have entities release themselves all the time. I think it's how it should be in this environment. For example when the player shoots an enemy the play shouldn't release the enemy as the enemy still has to run its death animation which takes time after the player has shot it. No sense in the player holding onto a ref to that enemy to release it later.

 

Link to comment
Share on other sites

Agree with seeing a running example that can be tested but what I question is the code in the Script:Detach() function as well. You are releasing each tiremodel and setting them to nil, but then afterwards you are performing 'ReleaseTableObjects(self.tiremodel)' on something that has already been released. I would say do one or the other but not both.

 

Also, along the same lines but directed more at Josh: Looking through all of the inherent entity script examples, I see Script:Release() instead of Script:Detach(). Are these interchangeable or are these two separate functions that should be used only for specific reasons?

 

--Edit - Josh says they are interchangeable.

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

Okay I uploaded this start map and 2 scripts to add to the project-Template "Advanced FPS" (create a new project "Test" in project manager) in Folders "Test\Maps\" and "Test\Scripts\Objects\cars\"

After this, load the start.map (well here the one uploaded)

 

It will show you the bug.

The blue box is the ChangeMap-Trigger to terrain.map.

The 2 wood boxes are the ingame built cars.

 

Only remove ONE script from ONE of the car, start the game, and the trigger runs ok.

2 different cars, 2 different scripts.

TryTheStartMap.zip

post-15151-0-44968100-1448841167_thumb.jpg

 

 

Link to comment
Share on other sites

Crazy but the bug just disappears ! It seems writing a little modified script for this example just help to find the solutions:

I built for this example the cars in function Script:UpdatePhysics() instead of start() and this seems to have solved the problems blink.pngbiggrin.png

 

Have to test this longer..but very well !

 

Edit

 

Only issue is a warning:

<< Possible reference count error for asset "d:/documents/leadwerks/projects/test/materials/effects/invisible.mat" >>

 

Well thx for helping.

 

 

Link to comment
Share on other sites

Thx a lot macklebee but I just do not understand my own problem anymore.. I was experiencing crazy game crash with this and for a few minutes, I can't find the problem anymore. Something strange with this. huh.png

 

Please try this map:

 

You should see the cars moving with this, and I get no problem to change the map through the trigger.

start.zip

 

 

Link to comment
Share on other sites

hmmm... dunno. I cannot get it to not crash with your scripts. Even reworking the scripts to have the vehicle built within the Start function (because it must be done before the next call to World:Update()) just causes another glitchy behavior whereas the player falls through the scene on scene startup. If I do not build the vehicle then no issues (no falling through the map, no crashes, changes maps ok). If I build the vehicle, player falls through the map immediately. huh.png

Win7 64bit / Intel i7-2600 CPU @ 3.9 GHz / 16 GB DDR3 / NVIDIA GeForce GTX 590

LE / 3DWS / BMX / Hexagon

macklebee's channel

Link to comment
Share on other sites

If I build the vehicle [in start], player falls through the map immediately.

I confirm this. Thatswhy I put the car-buid lines in UpdatePhysics(): No player Fall anymore.

 

But strangely I do not get the world to crash... sadly can't tell what changed ...

 

Edit1 I'm in not beta version.

 

Edit2 Too crazy for me: Exactly the same map with exactly same elements in another project and I get the world:clear() crash !

 

Is there something like a load order that could cause such unstablil results ??

 

 

Link to comment
Share on other sites

I fixed the warning, so get the new upload.

 

After 1000 tests, I get always same the problem: when creating/building over one vehicle in a map at the same time, the map will crash when calling world:clear().

 

Some tests demontrated the crash do not always occur, but sadly and strangely nothing stable could be found:

Sometimes ok, same test on a new map ---> Bug occurs wacko.png

 

2 boxes with both this little script added cause the bug:

 

function Script:Start()

self.Creating=0

end

 

 

function Script:UpdatePhysics()

 

if self.Creating==0 then

--Create the vehicle

self.entity:SetMass(1000)

self.vehicle = Vehicle:Create(self.entity)

self.Creating=1

end

end

 

function Script:Detach()

if self.vehicle~=nil then

self.vehicle:Release()

self.vehicle=nil

end

end

 

 

Fortunatly this is no big problem for my project; I will build and release cars each time the player will get in or out, on this way, if the map has to be changed, all cars would have been released earlier.

TryTheStartMap.zip

 

 

Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

 Share

×
×
  • Create New...