Overkillz Posted May 20, 2020 Share Posted May 20, 2020 Hey there dear community, today Im having an issue with renderTargets as the title says. Well, In fact it happens me when I minimize (not all the times) I thought that using properly the function onClientRestore it would be solved and I wouldn't have any problem, but no. Well the problem is that the renderTarget is not drawn or dissapear when minimizeing and restoring. The code is too long and there are useless functions that are innecessary, so, here goes a simple version how am I using renderTargets. Im sure that it is the right way to use and restore it. NOTE: Variables are properly set. The script works perfectly, but sometimes dissapear while minimizeing and restoring local topTimelist = {} for i=1,8 do table.insert(topTimelist, {pos = i, playerName = "–– Empty", time = "", date = "", country = "", playerSerial = "" }) end function drawTopTime() sizeY = labelSize*(#topTimelist+1) toptimesRT = dxCreateRenderTarget(sizeX,sizeY,true) dxSetRenderTarget(toptimesRT, true) dxSetBlendMode("modulate_add") --DRAW CONTENT dxSetBlendMode("blend") dxSetRenderTarget() end function renderTopTime() dxDrawImageSection(x,y,sizeX,maxSizeY,0,slide,sizeX,maxSizeY,toptimesRT,0,0,0,tocolor(255,255,255,255)) end function restoreTopTimesDraw(didClearRenderTargets) if didClearRenderTargets then drawTopTime() end end addEventHandler("onClientRestore",root,restoreTopTimesDraw) drawTopTime() addEventHandler("onClientRender",root,renderTopTime) Link to comment
Bonsai Posted May 20, 2020 Share Posted May 20, 2020 You only need to create the renderTarget once, e.g. on resource start. Not exactly sure whats wrong, but after you fixed that, you could simply call drawTopTime() in your render function before drawing the renderTarget on screen. Link to comment
Moderators IIYAMA Posted May 20, 2020 Moderators Share Posted May 20, 2020 (edited) 3 hours ago, Overkillz said: toptimesRT = dxCreateRenderTarget(sizeX,sizeY,true) As Bonsai said about creating it once. You currently have created a memory leak, which might play a role in this strange behaviour. A render target is an element, which is attached to the element tree, not just a value you can overwrite. In your case you might want to destroy it first, every time you display new top times (since your height is variable). if isElement(toptimesRT) then destroyElement(toptimesRT) end toptimesRT = dxCreateRenderTarget(sizeX,sizeY,true) Edited May 20, 2020 by IIYAMA Link to comment
Overkillz Posted May 20, 2020 Author Share Posted May 20, 2020 @Bonsai First of all, thanks for answering. Well, creating renderTarget again might could cause the issue. About calling drawTopTime() iinside render function the CPU Usage fires depending of the amount inside the table. The reason why Im creating again the renderTarget is due to the size changes depending of the amount inside the table. I need to clear out that I've already tried to destroy the renderTarget element and setting the variable as nil. Any suggestions ? @IIYAMA I've just commented about what you told I had already tried to destroy the element in other scripts where Im using renderTargets with this method. Example of my scoreboard if isElement(scoreboardRT) then destroyElement(scoreboardRT) scoreboardRT = nil end scoreboardRT = dxCreateRenderTarget(sizeX,fullSizeY,true) --REST OF THE CODE Respecting the elementTree, thats took all my attention. Might using several renderTargets is causing the problem ? Im currently using like 3 or 4 renderTargets. race, scoreboard, toptimes and might another one. I need to clear out that only the scoreboard is having the destroyElement method and might the issue is caused by the rest of scripts that are NOT using the destroyElement method ? Thanks for answering, best regards. Link to comment
Moderators IIYAMA Posted May 20, 2020 Moderators Share Posted May 20, 2020 32 minutes ago, Overkillz said: Might using several renderTargets is causing the problem ? Not sure to be honest. 4 should be fine. 38 minutes ago, Overkillz said: I need to clear out that only the scoreboard is having the destroyElement method and might the issue is caused by the rest of scripts that are NOT using the destroyElement method ? If you run out of VRAM, it could be possible for the rendertarget to fail. Not sure what kind of hardware you use. iprint(dxGetStatus ().VideoMemoryFreeForMTA) https://wiki.multitheftauto.com/wiki/DxGetStatus Also checking for an texture memory leak isn't a bad idea. iprint(#getElementsByType("texture")) -- should be showing the total textures from all resources 1 Link to comment
Overkillz Posted May 21, 2020 Author Share Posted May 21, 2020 Well, looks like creating renderTargets while you are minimized it fully bugs the renderTarget element. I just added some functions to avoid the creation of renderTargets while the players is minimized ...etc Also, while restoring, Im destroying the renderTarget element to create it again just to ensure that everything its ok. Just to clear one thin. I thought that using the argument (didClearRenderTargets) provided by onClientRestore would be usefull, but I really have just tested it and it didn't work for me, so, restoring wasnt working at all since this argument doesn't work properly. Take care about creating renderTarget while minimizeing (For example in a notification script that are using rts) Thanks for your help, best regards. 1 Link to comment
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now