@@ -93,7 +93,11 @@ function startBrowser ( elementType, callback, initialCat, initialModel, remembe
9393 if not cachedElements [elementType ] then
9494 cachedElements [elementType ] = cacheElements (xmlFiles [elementType ], elementCatalogs [elementType ])
9595 end
96- cachedElements [" favourite" ] = cacheElements (xmlFiles [" favourite" ], elementCatalogs [elementType ])
96+ if xmlFiles [" favourite" ] then
97+ cachedElements [" favourite" ] = cacheElements (xmlFiles [" favourite" ], elementCatalogs [elementType ])
98+ else
99+ cachedElements [" favourite" ] = {}
100+ end
97101 browser .enabled = true
98102 returnX ,returnY ,returnZ ,returnRX ,returnRY ,returnRZ = getCameraMatrix ()
99103 returnInterior = getCameraInterior ()
361365
362366addEventHandler (" onClientResourceStop" , resourceRoot ,
363367 function ()
364- xmlSaveFile (xmlFiles [" favourite" ])
365- xmlUnloadFile (xmlFiles [" favourite" ])
368+ if xmlFiles [" favourite" ] then
369+ local success = xmlSaveFile (xmlFiles [" favourite" ])
370+ if not success then
371+ outputDebugString (" [editor_gui] ERROR: Failed to save favourites.xml on resource stop" , 1 )
372+ end
373+ xmlUnloadFile (xmlFiles [" favourite" ])
374+ end
366375 end )
367376
368377local lastCallTick = 0
@@ -371,6 +380,9 @@ function toggleFavourite (gridlist)
371380 if getTickCount () - lastCallTick < 500 then return end -- Since it always gets called at least twice per click
372381 lastCallTick = getTickCount ()
373382 if not gridlist then return end
383+ if not xmlFiles [" favourite" ] then return end
384+ if not catNodes or not catNodes [2 ] then return end
385+ if not initiatedType or not elementCatalogs [initiatedType ] then return end
374386 local item = guiGridListGetSelectedItem (gridlist )
375387 local name = guiGridListGetItemText (gridlist , item , 1 )
376388 local model = guiGridListGetItemText (gridlist , item , 2 )
@@ -384,6 +396,10 @@ function toggleFavourite (gridlist)
384396 break
385397 end
386398 end
399+ local success = xmlSaveFile (xmlFiles [" favourite" ])
400+ if not success then
401+ outputDebugString (" [editor_gui] ERROR: Failed to save favourites.xml after removing item" , 1 )
402+ end
387403 cachedElements [" favourite" ] = cacheElements (xmlFiles [" favourite" ], elementCatalogs [initiatedType ])
388404 catNodes [2 ] = cachedElements [" favourite" ]
389405 if browserGUI .dropdown :getRow () == 2 then
@@ -397,6 +413,10 @@ function toggleFavourite (gridlist)
397413 xmlNodeSetAttribute (node , " model" , model )
398414 xmlNodeSetAttribute (node , " name" , name )
399415 xmlNodeSetAttribute (node , " keywords" , " " )
416+ local success = xmlSaveFile (xmlFiles [" favourite" ])
417+ if not success then
418+ outputDebugString (" [editor_gui] ERROR: Failed to save favourites.xml after adding item" , 1 )
419+ end
400420 cachedElements [" favourite" ] = cacheElements (xmlFiles [" favourite" ], elementCatalogs [initiatedType ])
401421 catNodes [2 ] = cachedElements [" favourite" ]
402422 outputMessage (elementCatalogs [initiatedType ]:gsub (" ^%l" , string.upper ) .. " '" .. name .. " ' added to favourites." , 50 , 255 , 50 )
0 commit comments