Jump to content

Map switch script works for others, but not for me?


cowlol
 Share

Recommended Posts

I don't understand the download of your script just do what i do :

function Script:NextLevel()--in
if self.mapFile ~= "" then
	App.world = World:Create()
	Map:Load(self.mapFile)
end
end

 

Create world than Load map; like i posted here it just works.

Never use Clear or Release, even better thye just are not in Reference commands :

World

 

The world class provides separate spaces within which entities can be created, without interfering with entities outside their own world.

Members

  • std::list<Entity*> entities

Functions

Stop toying and make games

Link to comment
Share on other sites

Yeah, I think that might have been old. Clear() does cause a crash. Release(), for me anyway, does not, and it doesn't cause the memory to go up as fast as not. However it does more slowly still go up. I'm guessing Josh has a memory leak somewhere.

Link to comment
Share on other sites

INFO :

I got crash using Release() with actual map files and one old project i got, so Release() also crashes.

 

You should stay with posted solution link , that works fine, and also don't have any memory leak or increase without needing any Release() or Clear() functions.

function Script:NextLevel()--in
       if self.mapFile ~= "" then
               App.world = World:Create()
               Map:Load(self.mapFile)
       end
end

 

Just my two cents about that resolved bug and level changing that works now.

Stop toying and make games

Link to comment
Share on other sites

Where/when are you calling Release()? If you call it inside the collision it will crash which makes sense because you are currently inside the world. You can't release the world when you are inside of it code wise. So make sure you are releasing the world outside of being inside it's Update() call, which all entity script function calls are.

Link to comment
Share on other sites

Even in Loop : IT JUST CRASHES.

Could it be calling Release() or Clear()

the code :

 

function App:changeMap(name)
self.mapName = name
self.change = true

end

--This is our main program loop and will be called continuously until the program ends
function App:Loop()

if self.change == true then
World:Clear()
self.world = World:Create()
Map:Load(self.mapName)
self.change = false
end
...
...

Even Clear() gives me a nil error, like the function is not existign in Lua.

As these two are not referenced in the documentation and don't work : just ignore them.

Stop toying and make games

Link to comment
Share on other sites

I will not ignore them seeing as Release() is documented: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/object/objectrelease-r21 and that it works.

 

Why do you have World:Clear(self.world)?? Did you just make that up that syntax yourself? Did you try App.world:Release() in App:Loop() instead? Just need to make sure you didn't do something like World:Release(self.world) because that would be wrong.

 

 

@cow, just so you know, when I replaced your exe in the project you sent me with one of my exe's everything worked. I'm not sure what version you have but that's what's causing issues for you. Would be nice to see what sub versions people have.

Link to comment
Share on other sites

I will not ignore them seeing as Release() is documented

 

ok , didn't seen that,

But it just crashes, and can't be used by complex objects, a map object points to several child objects memory (all your map stuff), this can be one problem causing the crash ?

 

 

Why do you have World:Clear(self.world)?? Did you just make that up that syntax yourself? Did you try App.world:Release() in App:Loop() instead? Just need to make sure you didn't do something like World:Release(self.world) because that would be wrong.

 

I corrected the Clear() in the code, it was a previous test.

Using World:Clear(), just gives exception also.

Yep i tried App.world.Release() and it just crashes, tested it just now and i just confirm the crash.

Here is the last test with not working code :

function App:Loop()

if self.change == true then
self.world:Release()
self.world = World:Create()
Map:Load(self.mapName)
self.change = false
end

 

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

 

 

@cowlol :

Don't forget the working solution to close this thread :

 

 

LoadLevel.lua :


Script.map = "" --path

function Script:UpdatePhysics()

end

function Script:Collision(entity, position, normal, speed)
--"Maps/lol.map"
App:changeMap(self.map)

end

In App.lua remove all your change map code on Loop() function.

Than just add this little function in App.lua :

 

 


function App:changeMap(name)

self.world = World:Create()

Map:Load(name)

end

 

It works just fine without any memory problem.

 

IF you really need to put that in App.lua loop just do it simple :

 

function App:changeMap(name)
self.mapName = name
self.change = true
end

--This is our main program loop and will be called continuously until the program ends
function App:Loop()

if self.change == true then

 self.world = World:Create()
 Map:Load(self.mapName)
 self.change = false
end
...

 

This thread can be closed

smile.png

Stop toying and make games

Link to comment
Share on other sites

But it just crashes, and can't be used by complex objects, a map object points to several child objects memory (all your map stuff), this can be one problem causing the crash ?

 

There is no such thing as a map object. Map:Load() doesn't return a map object. All entities that get loaded from Map:Load() are put inside the current world object.Which is why you have to release it to release all those entities that got loaded.

 

Using World:Clear(), just gives exception also.

 

That's because it doesn't exist. Again, not sure where you came up with even trying that. Just guessing?

 

Maybe check that you are opted into the beta? That's what I have and it works.

 

I really wish Josh would address this though...

 

@YouGroove could you provide a project here that crashes for you. I'd love to give it a try.

Link to comment
Share on other sites

@Rick:

I'm not part of beta.

 

To test, just download the file on DropBox he posted :

https://www.dropbox.com/s/vk4bjtt8b8pkzwe/AlienInsurgency.zip

Dezip , load the project on LE3 and apply above changes in previous post :

Modify App.lua and replace LoadLevel.lua with the code i posted.

You'll be able to test working solution and not working if you add some Release() call.

 

Note :

This is the wooden box in start room that has the script LoadLevel.lua attached to it.

 

Anyway it works fine without Release() so just let down that function with World object.

Stop toying and make games

Link to comment
Share on other sites

Anyway it works fine without Release() so just let down that function with World object.

 

Because it seems to create a memory leak. Because the creator of Leadwerks says to not screw around with the world object while inside world:Update(), which is what you are doing.

 

I did download his project and when I replace his exe with one created from my project, it works. Which tells me something about the version you and he has is somehow different than my version. I'm in beta though so maybe that's the reason, but I seem to remember this working before this beta.

 

This isn't good that people can have different versions like this.

Link to comment
Share on other sites

I still have got no solution: game still gives error with any of the scripts ''Failed to read file ''C:\users\*****\documents\leadwerks\projects\buildandshoot''''

 

Please note that it is not this error anymore:

Debug Assertion Failed!

 

Program:

...ents\Leadwerks\Projects\buildandshoot\buildandshoot.debug.exe

File: c:\program files (x86)\microsoft visual studio

12.0\vc\include\vector

Line: 1442

 

Expression: vector erase iterator outside range

For information on how your program can cause an assertion failure, see the Visual C++ documentation on asserts.

 

(Press Retry to debug the application)

 

That error only happens if I attempt to release the world while switching maps.

Link to comment
Share on other sites

@YouGroove He's saying even if he doesn't use Release() he gets a different error.

 

My guess is Josh did that off the top of his head and confused Clear() for Release(). Seems like a simple mistake. I think the important thing to take away from what Josh has there is that you have to do something to free the entities in the world before you load a new one or you'll have a memory leak. Seems logical does it not?

Link to comment
Share on other sites

@Rick :

Yes, seems logical, but a World can contain several maps i think.

I take example of FF7 game style, you have main scene exploration and another map for combat, in this case yu would just switch maps, and not call Release() or am i wrong ?

 

If Release() would become mandatory, before World:Create(), why not keeping it in C++ hard coded in World:Create() call.

Better :

You would just call : Map:Load(zzz)

And behind the scenes the engine would just call : World:Release(), than World:Create()

I really don't see why the World functions are exposed ?

Stop toying and make games

Link to comment
Share on other sites

Because you can make multiple worlds and switch between them. I know in LE 2.x it was needed for transparency. Whenever you set a new world as current, all entities loaded/created after that will be in that world: http://www.leadwerks.com/werkspace/page/documentation/_/command-reference/world/worldsetcurrent-r508

 

Release() isn't mandatory, but if you don't call it, it's important to know that all your entities still exist in memory, which the majority of the time is not what you want. Again, when it was needed for transparency, which I think you could still use/do in 3.x, you would want a different world at the same time for your transparent objects, but even then if you were actually switching maps while the game is running, you'd want to free the entities that were in said world.

Link to comment
Share on other sites

@cowlol :

Just don't use Release()

 

@Rick :

I have Steam version auto update, i just use code that works also.

And well this is super clear what is said on level switching script :

map.jpg

 

No Release() call !

 

I mean when I dont use Release I don't get the Debug Assertion Failed! Error. I still get the Failed to load file error, so the problem is not solved yet.

Link to comment
Share on other sites

When I look at the output instead of the error I can see that unloading everything goes allright on a test project (the project is called testytest), but then it says this line at output:

Loading map ''C:\users\*****\documents\leadwerks\projects\testytest''

Could someone tell me what your output is when loading the new map? (so after unloading the first map, if you use the Release script)

I think that the reason why I get the error Failed to load file ''C:\users\*****\documents\leadwerks\projects\testytest'' is that it sees the project folder as the .map file it is supposed to load or anything similar to that.

Link to comment
Share on other sites

I mean when I dont use Release I don't get the Debug Assertion Failed! Error. I still get the Failed to load file error, so the problem is not solved yet.

 

 

It worked without Release() with your level and the code i put. What do you want more laugh.png ?

 

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

 

You must have another problem somewhere ?

Can you post a smal test example ?

 

(Better create another bug report and close this one)

Stop toying and make games

Link to comment
Share on other sites

btw, don't know if this has been mentioned yet. Your sample code from your first post uses 'self.mapFile' to store the level. However, when the map gets loaded, 'self.map' is being used. Since that variable has no path, the game crashes.

 

function App:SwitchLevel(name)
     self.mapFile = name
end
function App:ShouldSwitchLevel()
    Map:Load(self.map)
end

Link to comment
Share on other sites

I found the cause...I was misusing C++ vectors, rather stupidly. This will be fixed in this weekend's patch. (Select the beta branch in Steam to get the update, when it is ready.)

http://steamcommunity.com/app/251810/discussions/0/540732596474790325/

 

Thank you for finding that.

My job is to make tools you love, with the features you want, and performance you can't live without.

Link to comment
Share on other sites

Guest
This topic is now closed to further replies.
 Share

×
×
  • Create New...