关于:0xcdcdcd



1 、

m_strctChnParam = NULL;

2 、

 if (m_strctChnParam)
 {
  free(m_strctChnParam);
  m_strctChnParam = NULL;
 }

 m_strctChnParam = (strChannelParam *)malloc(sizeof(strChannelParam) * m_iChannelNum * BASIC_STREAM_TYPES);
 if (m_strctChnParam)
 {
  memset(m_strctChnParam, 0, sizeof(strChannelParam) * m_iChannelNum * BASIC_STREAM_TYPES);
  for (int i = 0; i < m_iChannelNum; ++i)
  {
   m_strctChnParam[i].m_iChnConnectSta = -1;
  }
 }


今天遇到一个问题,将第一块代码注释掉,第二段就会报错:

原来:

指针如果没有初始化,系统会默认初始化为:0xcdcdcd,导致判断空失败,free野指针导致崩溃。


0xcdcdcd  (2011-03-25 23:52:19)别谈:


标签:

杂谈



VC在debug模式下,对CRT(C Runtime)分配的堆(Heap)内存,都会初始化填充成0xcdcdcdcd。目的就是为了方便程序员debug,一旦看到0xcdcdcdcd,就表示访问了没有初始化的内存。

在JavaScript中,你可以利用Three.js库来创建3D游戏场景,这是一个非常流行用于WebGL的开源库。以下是一个简单的示例,展示如何构建一个基础的繁华街道场景: ```javascript // 引入Three.js库 import * as THREE from 'three'; // 创建场景、相机和渲染器 const scene = new THREE.Scene(); const camera = new THREE.PerspectiveCamera(75, window.innerWidth / window.innerHeight, 0.1, 1000); const renderer = new THREE.WebGLRenderer(); // 将渲染器设置到页面上 renderer.setSize(window.innerWidth, window.innerHeight); document.body.appendChild(renderer.domElement); // 繁华街道元素:地面、建筑、行人等 // 地面 const groundMaterial = new THREE.MeshPhongMaterial({ color: 0x808080 }); const groundGeometry = new THREE.PlaneGeometry(100, 100, 10, 10); const ground = new THREE.Mesh(groundGeometry, groundMaterial); scene.add(ground); // 建筑 const buildingGeometry = new THREE.BoxGeometry(20, 40, 10); const buildingMaterial = new THREE.MeshBasicMaterial({ color: 0xCDCDCD }); for (let i = 0; i < 5; i++) { const building = new THREE.Mesh(buildingGeometry, buildingMaterial); building.position.x = Math.random() * 20 - 10; building.rotation.y = Math.random() * Math.PI * 2; scene.add(building); } // 行人 const personGeometry = new THREE.SphereGeometry(1, 32, 32); const personMaterial = new THREE.MeshBasicMaterial({ color: 0xFFA500 }); for (let i = 0; i < 10; i++) { const person = new THREE.Mesh(personGeometry, personMaterial); person.position.x = Math.random() * 40 - 20; person.position.z = Math.random() * 20 - 10; scene.add(person); } // 设置动画和渲染 function animate() { requestAnimationFrame(animate); ground.rotation.x += 0.01; ground.rotation.y += 0.01; for (let i = 0; i < scene.children.length; i++) { scene.children[i].rotation.x += 0.01; } renderer.render(scene, camera); } animate(); // 相关问题: 1. Three.js库还有哪些常用的功能或组件? 2. 如何添加光照效果到这个场景中? 3. 怎样让行人动态地移动而不是静止不动?
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值