Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
17 commits
Select commit Hold shift + click to select a range
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions ui/addmeshes.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -7,6 +7,10 @@ import {
} from "./blockmesh.js";

export function createMeshOnCanvas(block) {
if (!isEligibleForMeshCreation(block)) {
return;
}

const mesh = getMeshFromBlock(block);
if (mesh) {
console.warn("Mesh already exists for block", block.id);
Expand DownExpand Up@@ -434,6 +438,22 @@ export function createMeshOnCanvas(block) {
}
}

function isEligibleForMeshCreation(block) {
if (!block?.isEnabled?.()) return false;
if (block.previousConnection && !block.previousConnection.isConnected?.()) {
return false;
}

let root = block;
let parent = block.getParent?.();
while (parent) {
root = parent;
parent = parent.getParent?.();
}

return root?.isEnabled?.() ?? false;
}

function createShapeInternal(block) {
const shapeType = block.type;
let position, color, newMesh, alpha;
Expand Down
65 changes: 38 additions & 27 deletions ui/blockmesh.js
Original file line numberDiff line numberDiff line change
Expand Up@@ -452,6 +452,13 @@ export function setClearSkyToBlack() {

// Add this function before updateMeshFromBlock
export function updateOrCreateMeshFromBlock(block, changeEvent) {
const sceneControllerTypes = [
"set_sky_color",
"set_background_color",
"create_ground",
"create_map",
];

if (flock.meshDebug)
console.log(
"Update or create mesh from block",
Expand All@@ -463,19 +470,8 @@ export function updateOrCreateMeshFromBlock(block, changeEvent) {
return;
}

if (
[
"set_sky_color",
"set_background_color",
"create_ground",
"create_map",
].includes(block.type)
) {
// Always proceed to update
updateMeshFromBlock(null, block, changeEvent);
return;
}
const meshes = getMeshesFromBlock(block);
const isConnectedToEnabledChain = isBlockConnectedToEnabledChain(block);
if (flock.meshDebug) console.log(meshes);
const wasDisabled =
changeEvent?.oldValue === true || changeEvent?.oldValue === "true";
Expand All@@ -488,13 +484,24 @@ export function updateOrCreateMeshFromBlock(block, changeEvent) {
nowEnabled;
const isImmediateEnabledCreate =
changeEvent?.type === Blockly.Events.BLOCK_CREATE &&
block.isEnabled() &&
isConnectedToEnabledChain &&
meshes.length === 0;

if (!isConnectedToEnabledChain) {
if (meshes.length) {
deleteMeshFromBlock(block.id);
}
return;
}
Comment on lines +490 to +495

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

Scene-controller updates are being blocked by the connectivity guard.

Line 490 returns early for all block types, including scene controllers, so their special update path may never run when disconnected. Exempt sceneControllerTypes from this gate.

Proposed fix
- if (!isConnectedToEnabledChain) {+ const isSceneController = sceneControllerTypes.includes(block.type);+ if (!isSceneController && !isConnectedToEnabledChain) {
if (meshes.length) {
deleteMeshFromBlock(block.id);
}
return;
}
🤖 Prompt for AI Agents
Verify each finding against the current code and only fix it if needed.
In `@ui/blockmesh.js` around lines 490 - 495, The early-return connectivity guard
prevents scene controllers from running their update path; modify the condition
so it only returns when disconnected and the block is NOT a scene controller.
Concretely, change the if check around isConnectedToEnabledChain (the block
containing meshes, deleteMeshFromBlock(block.id), and return) to skip the return
for blocks whose type is in sceneControllerTypes (e.g., use a predicate like
!sceneControllerTypes.includes(block.type) or similar) so scene controller
blocks still proceed with their special update path while other blocks keep the
existing behavior.

if ((window.loadingCode && !changeEvent?.recordUndo) || block.disposed)
return;
const alreadyCreatingMesh = meshMap[block.id] !== undefined;
if (!alreadyCreatingMesh && (isEnabledEvent || isImmediateEnabledCreate)) {
createMeshOnCanvas(block);
if (sceneControllerTypes.includes(block.type)) {
updateMeshFromBlock(meshes, block, changeEvent);
} else {
createMeshOnCanvas(block);
}
return;
}
if (flock.meshDebug) {
Expand All@@ -510,17 +517,28 @@ export function updateOrCreateMeshFromBlock(block, changeEvent) {
changeEvent?.type === Blockly.Events.BLOCK_CREATE ||
changeEvent?.type === Blockly.Events.BLOCK_MOVE) &&
(meshes.length ||
[
"set_sky_color",
"set_background_color",
"create_ground",
"create_map",
].includes(block.type))
sceneControllerTypes.includes(block.type))
) {
updateMeshFromBlock(meshes, block, changeEvent);
}
}

function isBlockConnectedToEnabledChain(block) {
if (!block?.isEnabled?.()) return false;
if (block.previousConnection && !block.previousConnection.isConnected?.()) {
return false;
}

let root = block;
let parent = block.getParent?.();
while (parent) {
root = parent;
parent = parent.getParent?.();
}

return root?.isEnabled?.() ?? false;
}
Comment thread
coderabbitai[bot] marked this conversation as resolved.

function isBlockIdDescendantOf(rootBlock, id) {
if (!rootBlock || !id) return false;
if (rootBlock.id === id) return true;
Expand DownExpand Up@@ -1279,13 +1297,6 @@ export function updateMeshFromBlock(meshesOrMesh, block, changeEvent) {
block.type === "create_ground" ||
block.type === "create_map"
) {
if (changeEvent.type === Blockly.Events.BLOCK_MOVE) {
if (flock.meshDebug)
console.log(
"Ignoring BLOCK_MOVE for scene block with no input change",
);
return;
}
changed = "COLOR";
} else {
if (flock.meshDebug)
Expand Down
Loading