Yue Posted 23 hours ago Posted 23 hours ago -- Configuración mínima local displays = GetDisplays() local window = CreateWindow("Leadwerks", 0, 0, 1280, 720, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR) local framebuffer = CreateFramebuffer(window) local world = CreateWorld() local camera = CreateCamera(world) camera:SetClearColor(0.125) camera:SetPosition(0, 0, -2) Print("=== CARGA DIRECTA DESDE BUFFER ===") -- 1. Cargar archivo completo a buffer Print("1. LoadBuffer('Maps/Mars.map')...") local buffer = LoadBuffer("Maps/Mars.map") if buffer == nil then Print("Error: LoadBuffer falló") return end Print(" Buffer: " .. buffer:GetSize() .. " bytes") -- 2. Crear BufferStream desde el buffer Print("2. CreateBufferStream(buffer)...") local stream = CreateBufferStream(buffer) if stream == nil then Print("Error: No se pudo crear stream") return end -- 3. Crear binstream vacío (requerido por LoadScene) Print("3. Creando binstream...") local binstream = CreateBufferStream() -- 4. Intentar carga directa desde buffer Print("4. LoadScene(world, stream, binstream)...") stream:Seek(0) binstream:Seek(0) local scene = LoadScene(world, stream, binstream) if scene == nil then Print("❌ FALLO: No se pudo cargar desde buffer") else Print("✅ ÉXITO: Escena cargada directamente desde buffer") end -- Loop mínimo while window:KeyDown(KEY_ESCAPE) == false and window:Closed() == false do world:Update() world:Render(framebuffer) end The entire file enters the buffer. Print("=== CARGA COMPLETA DE ARCHIVO A BUFFER ===") -- 1. Cargar archivo COMPLETO con LoadBuffer Print("1. Cargando archivo con LoadBuffer...") local buffer = LoadBuffer("Maps/Mars.map") if buffer == nil then Print("❌ LoadBuffer falló - el archivo no se pudo cargar") return end local bufferSize = buffer:GetSize() Print("✅ Buffer creado: " .. bufferSize .. " bytes") -- 2. Mostrar información general Print("\n2. Información del buffer:") Print(" - Tamaño total: " .. bufferSize .. " bytes") Print(" - Primer byte: " .. buffer:PeekByte(0) .. " (ASCII: " .. string.char(buffer:PeekByte(0)) .. ")") Print(" - Último byte: " .. buffer:PeekByte(bufferSize-1)) -- 3. Mostrar los primeros 500 bytes (como texto y hex) Print("\n3. Primeros 500 bytes del archivo:") local textPreview = "" local hexPreview = "" for i = 0, math.min(499, bufferSize-1) do local byte = buffer:PeekByte(i) -- Versión texto (solo caracteres imprimibles) if byte >= 32 and byte <= 126 then textPreview = textPreview .. string.char(byte) else textPreview = textPreview .. "." end -- Versión hexadecimal hexPreview = hexPreview .. string.format("%02X ", byte) if (i+1) % 16 == 0 then hexPreview = hexPreview .. "\n" end end Print(" Como texto (imprimible):") Print(" " .. textPreview) Print("\n En hexadecimal:") Print(" " .. hexPreview) -- 4. Mostrar los últimos 500 bytes Print("\n4. Últimos 500 bytes del archivo:") if bufferSize > 500 then local startPos = bufferSize - 500 local textEnd = "" local hexEnd = "" for i = startPos, bufferSize-1 do local byte = buffer:PeekByte(i) if byte >= 32 and byte <= 126 then textEnd = textEnd .. string.char(byte) else textEnd = textEnd .. "." end hexEnd = hexEnd .. string.format("%02X ", byte - startPos) if (i - startPos + 1) % 16 == 0 then hexEnd = hexEnd .. "\n" end end Print(" Como texto (imprimible):") Print(" " .. textEnd) else Print(" (El archivo es demasiado pequeño para mostrar últimos 500 bytes)") end -- 5. Buscar la transición de JSON a datos binarios Print("\n5. Analizando estructura del archivo:") local nullByteCount = 0 local jsonEnd = nil -- Buscar bytes nulos (0x00) que indican datos binarios for i = 0, math.min(1000, bufferSize-1) do if buffer:PeekByte(i) == 0 then nullByteCount = nullByteCount + 1 if jsonEnd == nil then jsonEnd = i Print(" - Primer byte nulo (0x00) en posición: " .. i) end end end Print(" - Bytes nulos en primeros 1000 bytes: " .. nullByteCount) Print(" - JSON probablemente termina cerca del byte: " .. (jsonEnd or "no encontrado")) -- 6. Verificar si es JSON válido Print("\n6. Verificando si es JSON válido:") local firstChar = string.char(buffer:PeekByte(0)) local secondChar = string.char(buffer:PeekByte(1)) Print(" - Primeros caracteres: " .. firstChar .. secondChar) if firstChar == "{" then Print(" ✅ Comienza con '{' (JSON válido)") -- Buscar la última llave de cierre local lastBrace = -1 for i = 0, bufferSize-1 do if buffer:PeekByte(i) == string.byte("}") then lastBrace = i end end if lastBrace > 0 then Print(" - Última '}' en posición: " .. lastBrace) Print(" - Tamaño del JSON: ~" .. (lastBrace + 1) .. " bytes") Print(" - Datos binarios después: ~" .. (bufferSize - lastBrace - 1) .. " bytes") end else Print(" ❌ No comienza con '{' (no es JSON puro)") end Print("\n=== ANÁLISIS COMPLETADO ===") Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Yue Posted 22 hours ago Author Posted 22 hours ago Simplified code, the application crashes in LoadScene. local displays = GetDisplays() local window = CreateWindow("Leadwerks", 0, 0, 1280, 720, displays[1], WINDOW_CENTER | WINDOW_TITLEBAR) local framebuffer = CreateFramebuffer(window) local world = CreateWorld() local camera = CreateCamera(world) camera:SetClearColor(0.125) camera:SetPosition(0, 0, -2) local buffer = LoadBuffer("Maps/Mars.map") local stream = CreateBufferStream(buffer) local jsonEnd = 0 for i = 0, buffer:GetSize() - 1 do if buffer:PeekByte(i) == string.byte('}') then jsonEnd = i end end local jsonStream = CreateStreamBuffer(stream, 0, jsonEnd + 1) local binstream = CreateStreamBuffer(stream, jsonEnd + 1, buffer:GetSize() - jsonEnd - 1) local scene = LoadScene(world, jsonStream, binstream) while window:KeyDown(KEY_ESCAPE) == false and window:Closed() == false do world:Update() world:Render(framebuffer) end Quote Murphy's Law: We don't fix bugs, we document them as features. – Murphy Games
Solution Josh Posted 2 hours ago Solution Posted 2 hours ago The documentation here is slightly wrong, and this overload is not exposed in the Lua API. I have fixed both problems and they will be available in the next update. 1 Quote Let's build cool stuff and have fun.
Recommended Posts
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.