Jump to content
KTyJLXy

LevelChange Problems

Recommended Posts

Hi guys. Yep, that's me again. I've got windows critical error (and it says nothing? like bla-bla programm should be closed) on attempt to change level.

Lua debug says nothing on this account.

 

Here's the app code

 


--This function will be called once when the program starts
function App:Start()

--Initialize Steamworks (optional)
Steamworks:Initialize()

--Set the application title
self.title="DungeonScrolls"

--Create a window
self.window=Window:Create(self.title,0,0,1366,768,Window.Titlebar+Window.Center+8)
self.window:HideMouse()

--Create the graphics context
self.context=Context:Create(self.window,0)
if self.context==nil then return false end

self.menumusic=Sound:Load("Sound/Music/Main theme.wav")
if self.menumusic~=nil then
	self.musicsource = Source:Create()
	self.musicsource:SetSound(self.menumusic)
	self.menumusic:Release()
	self.menumusic=nil
	self.musicsource:SetVolume(1)
    self.musicsource:SetLoopMode(true)
	self.musicsource:Play()
end

--Create settings table and add defaults
self.settings={}
self.settings.vsync=True

--Create a world
self.world=World:Create()

--Load a map
--local mapfile = System:GetProperty("map","Maps/start.map")
self.mapfile = "Maps/start.map"
if Map:Load(self.mapfile)==false then return false end
self.mapfile = ""

return true
end

function App:SwitchLevel(name)
self.mapfile = name
end

function App:LevelCheck()
if self.mapfile ~= "" then
self.world:Release()
self.world = World:Create()
Map:Load(self.mapfile)
self.mapfile = ""
end
end


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

self:LevelCheck()

--If window has been closed, end the program
if self.window:Closed() or self.window:KeyDown(Key.Escape) then return false end

--Update the app timing
Time:Update()

--Update the world
self.world:Update()

--Render the world
self.world:Render()

--Render statistics
self.context:SetBlendMode(Blend.Alpha)
if DEBUG then
	self.context:SetColor(1,0,0,1)
	self.context:DrawText("Debug Mode",2,2)
	self.context:SetColor(1,1,1,1)
	self.context:DrawStats(2,22)
	self.context:SetBlendMode(Blend.Solid)
else
	--Toggle statistics on and off
	if (self.window:KeyHit(Key.F11)) then self.showstats = not self.showstats end
	if self.showstats then
		self.context:SetColor(1,1,1,1)
		self.context:DrawText("FPS: "..Math:Round(Time:UPS()),2,2)
	end
end

--Refresh the screen
self.context:Sync(false)

--Returning true tells the main program to keep looping
return true
end

 

And here's the trigger code

 


Script.entered = false
Script.exited = false
Script.hadCollision = false

Script.Map = "" --path

function Script:UpdatePhysics()
   if self.entered then
       if self.hadCollision == false then
           if self.exited == false then
               self.exited = true
               self.component:CallOutputs("OnExit")
               self.entered = false
           end
       end
   end

   self.hadCollision = false
end

function Script:Collision(entity, position, normal, speed)
   self.hadCollision = true

   self.component:CallOutputs("OnCollide")

   if self.entered == false then
       self.component:CallOutputs("OnEnter")
	App:SwitchLevel(self.Map)
       self.entered = true
       self.exited = false
   end
end

Share this post


Link to post

What is the path to the level name in this example?

Maps/second_map.map

If i understand your question correctly.

Share this post


Link to post

self.world:Release()

 

This changed. It should be self.world:Clear() now

Share this post


Link to post

Put a System:Print("Map file = "..self.mapfile) inside your if statement in App:LevelCheck() and run the program and see what it says in the output.

Share this post


Link to post

Put a System:Print("Map file = "..self.mapfile) inside your if statement in App:LevelCheck() and run the program and see what it says in the output.

it says:

 

 

Map file = maps/second_map.map

Share this post


Link to post

Did you step through the code that changes? Do you know exactly what line it's failing on?

Share this post


Link to post

Did you step through the code that changes? Do you know exactly what line it's failing on?

Yep, that would be line 52 in app.lua, which now is

self.world:Clear()

Share this post


Link to post

Just a note if you Clear() the world you don't need to create another one. You are reusing the current world so you can comment that line out. Other than that I don't know what to tell you. This all works for me. I just tested the below and it works perfectly.

 

function App:ChangeLevel(newLevel)
self.newLevel = newLevel
end

function App:ShouldChangeLevel()
if self.newLevel ~= "" then
self.world:Clear()
Map:Load(self.newLevel)
self.newLevel = ""
end
end

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

self:ShouldChangeLevel()

-- all the other stuff I just didn't want to paste here
end

Share this post


Link to post

Should i submit bugreport to the engine devs or smth?

Btw, if i comment 52 line it loads next lvl. Lags as hell, but it gets it done.

Share this post


Link to post

I would if I were you. I would make a small test project just for this and include that in the bug report as well. List out your specs and make sure you have the most current version (I'm opted into the beta as well).

 

Yeah, what you experience with the lag is because all the entities in your other scene are still there. They weren't removed because your world wasn't cleared. It's a huge memory leak to do that.

Share this post


Link to post

I've opted into beta and have created project just for testing.

I've got following error now, instead of windows critical:

Object reference count error.

And output like

 

 

Map file = maps/second.map

Deleting material "e:/leadwerks projects/projectfortests/materials/developer/greengrid.mat"

Deleting shader "E:/Leadwerks projects/Changetest/shaders/model/diffuse.shader"

Deleting texture "e:/leadwerks projects/projectfortests/materials/developer/greengrid.tex"

Deleting texture "E:/Leadwerks projects/Changetest/Materials/Common/bfn.tex"

Deleting shader "E:/Leadwerks projects/Changetest/Shaders/Lighting/ambientlight.shader"

Setting breakpad minidump AppID = 251810

Steam_SetMinidumpSteamID: Caching Steam ID: 76561197981090266 [API loaded no]

Process Complete.

Share this post


Link to post

That's a better error as it looks like it's unloading the map. :)

 

There is a bug report forum. It's very unstructured. You just make a forum post in the bug forum and explain your bug and attach your zipped project

Share this post


Link to post

By the way, Rick, i wonder if you could sent me empty project with just level change somewhere in it. That way i could check if it is just my leadwerks creating projects wrongly.unsure.png

Share this post


Link to post

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

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.

×
×
  • Create New...